diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-06-21 20:02:40 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-06-21 20:02:40 -0700 |
commit | ff9db4f3a6ee2a2bb5c821b73d59ffe792cbbc27 (patch) | |
tree | 4bddaf493f2d9a03e064ebe0ade3c5555bbcc1fa | |
parent | d0ffb09d01edbc28002520104865117894ef5fa9 (diff) | |
download | txr-ff9db4f3a6ee2a2bb5c821b73d59ffe792cbbc27.tar.gz txr-ff9db4f3a6ee2a2bb5c821b73d59ffe792cbbc27.tar.bz2 txr-ff9db4f3a6ee2a2bb5c821b73d59ffe792cbbc27.zip |
* lisplib.c (ifa_set_entries): Add conda.
* share/txr/stdlib/ifa.tl (conda): New macro.
* tests/012/ifa.tl: Adding test for conda.
* txr.1: Documenting conda.
-rw-r--r-- | ChangeLog | 22 | ||||
-rw-r--r-- | lisplib.c | 2 | ||||
-rw-r--r-- | share/txr/stdlib/ifa.tl | 7 | ||||
-rw-r--r-- | tests/012/ifa.tl | 25 | ||||
-rw-r--r-- | txr.1 | 34 |
5 files changed, 79 insertions, 11 deletions
@@ -1,3 +1,25 @@ +2015-06-21 Kaz Kylheku <kaz@kylheku.com> + + Version 109. + + * RELNOTES: Updated. + + * configure, txr.1: Bumped version and date. + + * share/txr/stdlib/ver.tl: Likewise. + + * tl.vim, txr.vim: Regenerated. + +2015-06-21 Kaz Kylheku <kaz@kylheku.com> + + * lisplib.c (ifa_set_entries): Add conda. + + * share/txr/stdlib/ifa.tl (conda): New macro. + + * tests/012/ifa.tl: Adding test for conda. + + * txr.1: Documenting conda. + 2015-06-20 Kaz Kylheku <kaz@kylheku.com> * genman.txr: Rewrite the man2html-generated inner name links with hash @@ -98,7 +98,7 @@ static val ver_instantiate(val set_fun) static val ifa_set_entries(val dlt, val fun) { - val name[] = { lit("ifa"), nil }; + val name[] = { lit("ifa"), lit("conda"), nil }; set_dlt_entries(dlt, name, fun); return nil; } diff --git a/share/txr/stdlib/ifa.tl b/share/txr/stdlib/ifa.tl index 180e5231..bffe8246 100644 --- a/share/txr/stdlib/ifa.tl +++ b/share/txr/stdlib/ifa.tl @@ -50,3 +50,10 @@ (it-temp [temps pos-candidate])) ^(let* (,*(zip temps args) (it ,it-temp)) (if (,sym ,*temps) ,then ,else)))))))) + +(defmacro conda (. pairs) + (tree-case pairs + (((test . forms) . rest) ^(ifa ,test (progn ,*forms) + (conda ,*rest))) + (() ()) + (else (throwf 'eval-error "conda: bad syntax: ~s" pairs)))) diff --git a/tests/012/ifa.tl b/tests/012/ifa.tl index d659399e..ae283abc 100644 --- a/tests/012/ifa.tl +++ b/tests/012/ifa.tl @@ -14,34 +14,39 @@ (error "test case ~s failed to expand: expected is ~s" expr expected))))) ;; "it" is (+ 2 2) -(ifa (> (+ 2 2) 0) (* it 2)) - (test (ifa (> (+ 2 2) 0) (* it 2)) - 8) + 8) ;; "it" is (* x x) (test (let ((x 7)) - (ifa (>= (* x x) 49) - (isqrt it))) - 7) + (ifa (>= (* x x) 49) + (isqrt it))) + 7) ;; ambiguous: is "it" x or is "it" y? (test (ifa (> x y) (print it)) :error) ;; "it" is (+ 3 (* 2 x)) (test (let ((x 5)) - (ifa (< 0 (+ 3 (* 2 x)) 20) (* 100 it))) - 1300) + (ifa (< 0 (+ 3 (* 2 x)) 20) (* 100 it))) + 1300) ;; "it" is (length '(a b c d)) ;; Intuition: it" could also be '(a b c d) ;; TODO: deal specially with chains of unary functions. ;; How about it = (length ...), itt = '(a b c d) (test (ifa (not (oddp (length '(a b c d)))) it) - 4) + 4) ;; "it" is y because %x% is constantp (test (symacrolet ((%x% 42)) (let ((y 41)) (ifa (> %x% y) it))) - 42) + 42) + +(test (let ((x 5)) + (conda + ((not (integerp x)) (list it)) + ((oddp (+ 2 x)) (list it)))) + (7)) + @@ -10941,6 +10941,40 @@ form. -> (4) .cble +.coNP Macro @ conda +.synb +.mets (conda >> {( test << form *)}*) +.syne +.desc +The +.code conda +operator provides a multi-branching conditional evaluation of +forms, similarly to the +.code cond +operator. Enclosed in the cond form are groups of forms expressed as lists. +Each group must be a list of at least one form. + +The +.code conda +operator is anaphoric: it expands into a nested structure of zero or more +.code ifa +invocations, according to these patterns: + +.cble + (conda) -> nil + (conda (x y ...) ...) -> (ifa x (progn y ...) (conda z ...)) +.cblk + +Thus, +.code conda +inherits all the restrictions on the +.meta test +expressions from +.codn ifa , +as well as the anaphoric +.code it +variable feature. + .coNP Macro @ dotimes .synb .mets (dotimes >> ( var < count-form <> [ result-form ]) << body-form *) |