diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-01-13 21:00:10 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-01-13 21:00:10 -0800 |
commit | 487e5f4c8c11ba9c1691b1cdd9723311e7b58c7a (patch) | |
tree | 57064d32b97ad0992842a5949f4127f5043f167d | |
parent | f711590ceae82493b8a87eba0bfaaed30af06c34 (diff) | |
download | txr-487e5f4c8c11ba9c1691b1cdd9723311e7b58c7a.tar.gz txr-487e5f4c8c11ba9c1691b1cdd9723311e7b58c7a.tar.bz2 txr-487e5f4c8c11ba9c1691b1cdd9723311e7b58c7a.zip |
The identity function gets an alias: use.
* eval.c (eval_init): Register "use" as alias for identity.
* txr.1: Documented use function.
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | txr.1 | 23 |
2 files changed, 23 insertions, 1 deletions
@@ -4674,6 +4674,7 @@ void eval_init(void) reg_fun(list_s, list_f); reg_fun(intern(lit("list*"), user_package), func_n0v(list_star_intrinsic)); reg_fun(identity_s, identity_f); + reg_fun(intern(lit("use"), user_package), identity_f); reg_fun(intern(lit("typeof"), user_package), func_n1(typeof)); reg_fun(intern(lit("subtypep"), user_package), func_n2(subtypep)); reg_fun(intern(lit("typep"), user_package), func_n2(typep)); @@ -13905,20 +13905,41 @@ previous clauses match. .SS* Object Equivalence -.coNP Function @ identity +.coNP Functions @, identity and @ use .synb .mets (identity << value ) +.mets (use << value ) .syne .desc The .code identity function returns its argument. +The +.code use +function is a synonym. + .TP* Notes: The .code identity function is useful as a functional argument, when a transformation function is required, but no transformation is actually desired. +In this role, the +.code use +synonym leads to readable code. For instance: +.cblk + ;; construct a function which returns its integer argument + ;; if it is odd, otherwise it returns its successor. + ;; "If it's odd, use it, otherwise take its successor". + + [iff oddp use succ] + + ;; Applications of the function: + + [[iff oddp use succ] 3] -> 3 ;; use applied to 3 + + [[iff oddp use succ] 2] -> 3 ;; succ applied to 2 +.cble .coNP Functions @, null @, not and @ false .synb |