diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-11-06 06:35:34 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-11-06 06:35:34 -0800 |
commit | 6cd6af985619569e7e12df7b28c6aa1dc10726c1 (patch) | |
tree | f6b64a6bbb70fb630329922a54e470538934876f | |
parent | 34cb933b006c52eec59dba4478a0d04c8ae4e5ba (diff) | |
download | txr-6cd6af985619569e7e12df7b28c6aa1dc10726c1.tar.gz txr-6cd6af985619569e7e12df7b28c6aa1dc10726c1.tar.bz2 txr-6cd6af985619569e7e12df7b28c6aa1dc10726c1.zip |
Allow then-func to be omitted in iff. Cleanup.
* eval.c (eval_init): Register iff as requiring only one arg.
* lib.c (do_iff): Do not check thenfun for nil. Just call it.
(iff): Default thenfun to identity.
* txr.1: Documentation updated.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | lib.c | 3 | ||||
-rw-r--r-- | txr.1 | 53 |
4 files changed, 51 insertions, 18 deletions
@@ -1,3 +1,14 @@ +2014-11-06 Kaz Kylheku <kaz@kylheku.com> + + Allow then-func to be omitted in iff. Cleanup. + + * eval.c (eval_init): Register iff as requiring only one arg. + + * lib.c (do_iff): Do not check thenfun for nil. Just call it. + (iff): Default thenfun to identity. + + * txr.1: Documentation updated. + 2014-11-05 Kaz Kylheku <kaz@kylheku.com> * lib.c (iff): Bugfix: forgotten handling of default @@ -3749,7 +3749,7 @@ void eval_init(void) reg_fun(intern(lit("andf"), user_package), func_n0v(andv)); reg_fun(intern(lit("orf"), user_package), func_n0v(orv)); reg_fun(intern(lit("notf"), user_package), func_n1(notf)); - reg_fun(intern(lit("iff"), user_package), func_n3o(iff, 2)); + reg_fun(intern(lit("iff"), user_package), func_n3o(iff, 1)); reg_fun(intern(lit("iffi"), user_package), func_n3o(iffi, 2)); reg_fun(intern(lit("if"), user_package), func_n3o(if_fun, 2)); reg_fun(intern(lit("or"), user_package), func_n0v(or_fun)); @@ -4606,12 +4606,13 @@ static val do_iff(val env, val args) cons_bind (thenfun, elsefun, choices); return if3(apply(condfun, args, nil), - if2(thenfun, apply(thenfun, args, nil)), + apply(thenfun, args, nil), if2(elsefun, apply(elsefun, args, nil))); } val iff(val condfun, val thenfun, val elsefun) { + thenfun = default_arg(thenfun, identity_f); elsefun = default_bool_arg(elsefun); return func_f0v(cons(condfun, cons(thenfun, elsefun)), do_iff); } @@ -20628,7 +20628,7 @@ and then inverts the result as if by application of the .coNP Functions @ iff and @ iffi .synb -.mets (iff < cond-func < then-func <> [ else-func ]) +.mets (iff < cond-func >> [ then-func <> [ else-func ]]) .mets (iffi < cond-func < then-func <> [ else-func ]) .syne .desc @@ -20639,7 +20639,7 @@ function is the functional equivalent of the operator. It accepts functional arguments and returns a function. -The resulting function takes its arguments and applies them to +The resulting function takes its arguments, if any, and applies them to .metn cond-func . If .meta cond-func @@ -20651,6 +20651,15 @@ resulting value is returned. Otherwise the arguments are passed to and the resulting value is returned. If +.meta then-func +is omitted then +.code identity +is used as default. This omission is not permitted by +.codn iffi , +only +.codn iff . + +If .meta else-func needs to be called, but is omitted, then .code nil @@ -20663,26 +20672,38 @@ function differs from only in the defaulting behavior with respect to the .meta else-func -argument. The following equivalences hold: +argument. If +.meta else-func +is omitted in a call to +.code iffi +then the deafult function is +.codn identity . +This is useful in situations when one value is to be +replaced with another one when the condition is true, otherwise +preserved. + +The following equivalences hold between +.code iffi +and +.codn iff : .cblk - (iffi a b c) <--> (iff a b c) + (iffi a b c) <--> (iff a b c) - (iffi a b) <--> (iff a b identity) + (iffi a b) <--> (iff a b identity) - (iffi a b nil) <--> (iff a b identity) + (iffi a b false) <--> (iff a b) + + (iffi a identity false) <--> (iff a) .cble -The -.code iffi -function defaults to the identity function when -.meta else-func -is -omitted or -.codn nil , -and therefore is useful in situations when one value is to be -replaced with another one when the condition is true, otherwise -preserved. +The following equivalence illustrates +.code iff +with both optional arguments omitted: + +.cblk + (iff a) <---> (iff a identity false) +.cble .coNP Functions @ tf and @ nilf .synb |