[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 2626840 336/439: Add -fixfn
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 2626840 336/439: Add -fixfn |
Date: |
Tue, 04 Aug 2015 20:29:54 +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 f8873a0 327/439: Update readme-template with changes from last release, (continued)
- [elpa] externals/dash f8873a0 327/439: Update readme-template with changes from last release, Phillip Lord, 2015/08/04
- [elpa] externals/dash f18a520 326/439: Release 2.7.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash f257fb9 328/439: Add -butlast, Phillip Lord, 2015/08/04
- [elpa] externals/dash d9879e9 329/439: Release 2.8.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 25c114c 330/439: Implementing a shallow copy counterpart to -clone., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6fc652d 331/439: Merge pull request #95 from Wilfred/shallow-copy-function, Phillip Lord, 2015/08/04
- [elpa] externals/dash d37947a 332/439: Add -tree-seq, Phillip Lord, 2015/08/04
- [elpa] externals/dash 166bccd 333/439: Add -tree-map-nodes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3adad97 334/439: Add -non-nil, Phillip Lord, 2015/08/04
- [elpa] externals/dash ab99be6 335/439: Add -fix, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2626840 336/439: Add -fixfn,
Phillip Lord <=
- [elpa] externals/dash c6b92ae 324/439: Reorder the examples into more meaningful blocks, Phillip Lord, 2015/08/04
- [elpa] externals/dash b1e585d 337/439: Update copyright notice, Phillip Lord, 2015/08/04
- [elpa] externals/dash f0831d3 339/439: Add -lambda, Phillip Lord, 2015/08/04
- [elpa] externals/dash 8f9fc41 340/439: Add support for multiple input arguments to -lambda, Phillip Lord, 2015/08/04
- [elpa] externals/dash 05fa92f 342/439: [-let] Transpose nreverse/flatten, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7f2b3c7 343/439: [-lambda] test all match-forms before converting to regular lambda, Phillip Lord, 2015/08/04
- [elpa] externals/dash 947ffda 341/439: Add support for &rest match for non-list sequences (like . for improper lists), Phillip Lord, 2015/08/04
- [elpa] externals/dash a4be872 338/439: Add `-let` and `-let*`, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9065e1b 344/439: [-let] Final cdr shift optimization, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6f81492 346/439: [-lambda] Better error-handling, Phillip Lord, 2015/08/04