[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 2626840 336/426: Add -fixfn
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 2626840 336/426: Add -fixfn |
Date: |
Tue, 04 Aug 2015 19:38:42 +0000 |
branch: externals/dash
commit 262684080296f0fbc4f35744f1e7543ed7f5afa0
Author: Matus Goljer <address@hidden>
Commit: Matus Goljer <address@hidden>
Add -fixfn
---
README.md | 14 ++++++++++++++
dash-functional.el | 13 +++++++++++++
dash.el | 1 +
dev/examples.el | 6 ++++++
4 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 2b44acf..9567edf 100644
--- a/README.md
+++ b/README.md
@@ -250,6 +250,7 @@ These combinators require Emacs 24 for its lexical scope.
So they are offered in
* [-orfn](#-orfn-rest-preds) `(&rest preds)`
* [-andfn](#-andfn-rest-preds) `(&rest preds)`
* [-iteratefn](#-iteratefn-fn-n) `(fn n)`
+* [-fixfn](#-fixfn-fn) `(fn)`
* [-prodfn](#-prodfn-rest-fns) `(&rest fns)`
## Anaphoric functions
@@ -1930,6 +1931,19 @@ This function satisfies the following law:
(funcall (-iteratefn 'cdr 3) '(1 2 3 4 5)) ;; => '(4 5)
```
+#### -fixfn `(fn)`
+
+Return a function that computes the (least) fixpoint of `fn`.
+
+`fn` is a unary function, results are compared with `equal`.
+
+In types: (a -> a) -> a -> a.
+
+```cl
+(funcall (-fixfn 'cos) 0.7) ;; => 0.7390851332151607
+(funcall (-fixfn (lambda (x) (expt (+ x 10) 0.25))) 2.0) ;; =>
1.8555845286409378
+```
+
#### -prodfn `(&rest fns)`
Take a list of n functions and return a function that takes a
diff --git a/dash-functional.el b/dash-functional.el
index eb2484a..115f137 100644
--- a/dash-functional.el
+++ b/dash-functional.el
@@ -135,6 +135,19 @@ This function satisfies the following law:
(funcall (-iteratefn fn n) init) = (-last-item (-iterate fn init (1+ n)))."
(lambda (x) (--dotimes n (setq x (funcall fn x))) x))
+(defun -fixfn (fn)
+ "Return a function that computes the (least) fixpoint of FN.
+
+FN is a unary function, results are compared with `equal'.
+
+In types: (a -> a) -> a -> a."
+ (lambda (x)
+ (let ((re (funcall fn x)))
+ (while (not (equal x re))
+ (setq x re)
+ (setq re (funcall fn re)))
+ re)))
+
(defun -prodfn (&rest fns)
"Take a list of n functions and return a function that takes a
list of length n, applying i-th function to i-th element of the
diff --git a/dash.el b/dash.el
index c90d3bf..9ba16ea 100644
--- a/dash.el
+++ b/dash.el
@@ -1780,6 +1780,7 @@ structure such as plist or alist."
"-orfn"
"-andfn"
"-iteratefn"
+ "-fixfn"
"-prodfn"
))
(special-variables '(
diff --git a/dev/examples.el b/dev/examples.el
index 04fb8c3..9d8c9ea 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -801,6 +801,12 @@ new list."
(equal (funcall (-iteratefn fn 5) init)
(-last-item (-iterate fn init (1+ 5)))))))
+ (defexamples -fixfn
+ ;; Find solution to cos(x) = x
+ (funcall (-fixfn 'cos) 0.7) => 0.7390851332151607
+ ;; Find solution to x^4 - x - 10 = 0
+ (funcall (-fixfn (lambda (x) (expt (+ x 10) 0.25))) 2.0) =>
1.8555845286409378)
+
(defexamples -prodfn
(funcall (-prodfn '1+ '1- 'int-to-string) '(1 2 3)) => '(2 1 "3")
(-map (-prodfn '1+ '1-) '((1 2) (3 4) (5 6) (7 8))) => '((2 1) (4 3) (6
5) (8 7))
- [elpa] externals/dash 8f9fc41 340/426: Add support for multiple input arguments to -lambda, (continued)
- [elpa] externals/dash 8f9fc41 340/426: Add support for multiple input arguments to -lambda, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7f2b3c7 343/426: [-lambda] test all match-forms before converting to regular lambda, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6f81492 346/426: [-lambda] Better error-handling, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6f0bb7d 348/426: [-let] Fix dynamic scoping issue, Phillip Lord, 2015/08/04
- [elpa] externals/dash f939201 347/426: [-let] Optimize shifting/binding of unused _ places, Phillip Lord, 2015/08/04
- [elpa] externals/dash c1d555b 355/426: [-let] Optimize single-binding of vectors and kv, Phillip Lord, 2015/08/04
- [elpa] externals/dash edb1e31 356/426: [-let] Add more tests, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9ec1a02 354/426: [-let] Abstract the _ test into a function, Phillip Lord, 2015/08/04
- [elpa] externals/dash 31f321a 358/426: Release 2.9.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 40849a7 357/426: [-let] Remove stale comment, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2626840 336/426: Add -fixfn,
Phillip Lord <=
- [elpa] externals/dash 2436bf8 361/426: Add debug declaration on -lambda, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4d67b25 345/426: [-let] Do not reinvent `pop', Phillip Lord, 2015/08/04
- [elpa] externals/dash f7664c6 352/426: [-let] Add &keys support for cons matcher, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4b63be1 362/426: Declare --mapcat macro before using it. #102, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0310e0e 359/426: Update docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0fc5d73 351/426: [-let] Make the cons matcher temp-bind as late as possible, Phillip Lord, 2015/08/04
- [elpa] externals/dash 75d29a2 363/426: Declare --iterate macro before using it. #102, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3bdf60b 365/426: Add some examples, Phillip Lord, 2015/08/04
- [elpa] externals/dash 65a3736 349/426: [-let] Fix improper list non-symbol last argument handler, Phillip Lord, 2015/08/04
- [elpa] externals/dash 549bfd3 366/426: Reorder macros to make sure they are declared before being used, Phillip Lord, 2015/08/04