From cec8c0d6850e132ba7f33fbe403cb69e2793879e Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Wed, 10 Feb 2021 14:09:50 +0000 Subject: [PATCH] Rename approx-equal to more accurate approx= * dev/dash-defs.el (approx-equal): Rename... (approx=): ...to this, to more accurately reflect its function. All references changed. * dev/examples.el (-fixfn): Clean up examples. * README.md: * dash.texi: Regenerate docs. --- README.md | 4 ++-- dash.texi | 4 ++-- dev/dash-defs.el | 8 ++++---- dev/examples.el | 16 +++++++++------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 8d47295..ad0a508 100644 --- a/README.md +++ b/README.md @@ -2997,9 +2997,9 @@ cdr the final output from `halt-test`. In types: (a -> a) -> a -> a. ```el -(funcall (-fixfn 'cos 'approx-equal) 0.7) ;; ~> 0.7390851332151607 +(funcall (-fixfn #'cos #'approx=) 0.7) ;; ~> 0.7390851332151607 (funcall (-fixfn (lambda (x) (expt (+ x 10) 0.25))) 2.0) ;; => 1.8555845286409378 -(funcall (-fixfn 'sin 'approx-equal) 0.1) ;; => (halted . t) +(funcall (-fixfn #'sin #'approx=) 0.1) ;; => (halted . t) ``` #### -prodfn `(&rest fns)` diff --git a/dash.texi b/dash.texi index c0e457f..da5dab4 100644 --- a/dash.texi +++ b/dash.texi @@ -4527,7 +4527,7 @@ In types: (a -> a) -> a -> a. @example @group -(funcall (-fixfn 'cos 'approx-equal) 0.7) +(funcall (-fixfn #'cos #'approx=) 0.7) @result{} 0.7390851332151607 @end group @group @@ -4535,7 +4535,7 @@ In types: (a -> a) -> a -> a. @result{} 1.8555845286409378 @end group @group -(funcall (-fixfn 'sin 'approx-equal) 0.1) +(funcall (-fixfn #'sin #'approx=) 0.1) @result{} (halted . t) @end group @end example diff --git a/dev/dash-defs.el b/dev/dash-defs.el index af73bb9..f05fdd2 100644 --- a/dev/dash-defs.el +++ b/dev/dash-defs.el @@ -35,14 +35,14 @@ EXPECTED should be the result of evaluating ACTUAL, and OP is one of the following comparison operators: - `=>' ACTUAL should be `equal' to EXPECTED. -- `~>' ACTUAL should be `approx-equal' to EXPECTED. +- `~>' ACTUAL should be `approx=' to EXPECTED. - `!!>' ACTUAL should signal the EXPECTED error, either an error symbol or an error object.") (defvar dash--epsilon 1e-15 - "Epsilon used in `approx-equal'.") + "Epsilon used in `approx='.") -(defun approx-equal (u v) +(defun approx= (u v) "Like `=', but compares floats within `dash--epsilon'. This allows approximate comparison of floats to work around differences in implementation between systems. Used in place of @@ -56,7 +56,7 @@ differences in implementation between systems. Used in place of "Return an ERT assertion form based on EXAMPLE." (pcase example (`(,actual => ,expected) `(should (equal ,actual ,expected))) - (`(,actual ~> ,expected) `(should (approx-equal ,actual ,expected))) + (`(,actual ~> ,expected) `(should (approx= ,actual ,expected))) (`(,actual !!> ,(and (pred symbolp) expected)) ;; FIXME: Tests fail on Emacs 24-25 without `eval' for some reason. `(should-error (eval ',actual ,lexical-binding) :type ',expected)) diff --git a/dev/examples.el b/dev/examples.el index 307f761..d7d94ce 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -21,7 +21,7 @@ ;; so make those good. ;; ;; Use the `~>' symbol instead of `=>' to test the expected and actual -;; values with `approx-equal'. +;; values with `approx='. ;;; Code: @@ -1710,12 +1710,14 @@ for historical reasons, and will soon be absorbed by `dash'." (-last-item (-iterate fn init (1+ 5)))))) => t) (defexamples -fixfn - ;; Find solution to cos(x) = x (may not converge without fuzzy comparison) - (funcall (-fixfn 'cos 'approx-equal) 0.7) ~> 0.7390851332151607 - ;; Find solution to x^4 - x - 10 = 0 (converges using 'equal comparison) - (funcall (-fixfn (lambda (x) (expt (+ x 10) 0.25))) 2.0) => 1.8555845286409378 - ;; The sin function has a fixpoint at zero, but it converges too slowly and is halted - (funcall (-fixfn 'sin 'approx-equal) 0.1) => '(halted . t)) + ;; Solve cos(x) = x (may not converge without fuzzy comparison). + (funcall (-fixfn #'cos #'approx=) 0.7) ~> 0.7390851332151607 + ;; Solve x^4 - x - 10 = 0 (converges using `equal' comparison). + (funcall (-fixfn (lambda (x) (expt (+ x 10) 0.25))) 2.0) + => 1.8555845286409378 + ;; The sin function has a fixpoint at zero, but it converges too + ;; slowly and is halted. + (funcall (-fixfn #'sin #'approx=) 0.1) => '(halted . t)) (defexamples -prodfn (funcall (-prodfn '1+ '1- 'number-to-string) '(1 2 3)) => '(2 1 "3")