summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-07-20 11:06:17 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-07-20 11:06:17 -0700
commit0d29bebdc195800fc416d6bea57d84140d54e7a3 (patch)
tree22808d93cd773cb4158c78bcb47b23da87d55700 /txr.1
parent7da23010b2afbaae4dc4b8f01d1f8950e2c878be (diff)
downloadtxr-0d29bebdc195800fc416d6bea57d84140d54e7a3.tar.gz
txr-0d29bebdc195800fc416d6bea57d84140d54e7a3.tar.bz2
txr-0d29bebdc195800fc416d6bea57d84140d54e7a3.zip
* eval.c (eval_init): Register juxt as intrinsic.
* lib.c (do_juxt): New static function. (juxtv): New function. * lib.h (juxtv): Declared. * txr.1: Documented juxt.
Diffstat (limited to 'txr.1')
-rw-r--r--txr.135
1 files changed, 35 insertions, 0 deletions
diff --git a/txr.1 b/txr.1
index 5ffacc85..ca0d5529 100644
--- a/txr.1
+++ b/txr.1
@@ -12394,6 +12394,41 @@ op operator is this:
(call (chain (fun +) (lambda (x) (* 2 x))) 3 4)
+.SS Function juxt
+
+.TP
+Syntax:
+
+ (juxt <func>*)
+
+.TP
+Description:
+
+The juxt function accepts a variable number of arguments which are functions.
+It combines these into a single function which, when invoked, passes its arguments
+to each of the functions, and collects the results into a list. The results
+
+Note: the juxt function can be understood in terms of the following reference
+implementation:
+
+ (defun juxt (funcs)
+ (lambda (. args)
+ (mapcar (lambda (fun)
+ (apply fun args))
+ funcs)))
+
+.TP
+Example:
+
+ ;; separate list (1 2 3 4 5 6) into lists of evens and odds, which end up
+ ;; juxtaposed in the output list:
+
+ [(op [juxt keep-if remove-if] evenp) '(1 2 3 4 5 6)] -> ((2 4 6) (1 3 5))
+
+ ;; call several functions on 1, collecting their results:
+ [[juxt (op + 1) (op - 1) evenp sin cos] 1]'
+ -> (2 0 nil 0.841470984807897 0.54030230586814)
+
.SS Functions andf and orf
.TP