| This macro lets implements a conditional form with braches that differ in some subexpressions, but have a common structure. It is supposed to make programs shorter by eliminating redundancy. (def improper (l)
(if acons.l (improper cdr.l)
l))
(def sexp-trans (test fun tree)
(if (test tree) (fun tree)
(improper tree) tree
(map [sexp-trans test fun _] tree)))
(mac cond-alt (conds . code)
(let test (andf acons [is 'alt car._])
`(if ,@(apply join (rev:accum acc
(forlen index conds
(acc `(,conds.index (do ,@(sexp-trans test [cdr._ index] code))))))))))
Example: (let there 'ham
(cond-alt ((is there 'spam) (is there 'ham) (is there 'bacon))
(pr "there is " (alt 'spam 'ham 'bacon)
", but there is no " (alt 'ham 'bacon 'spam)
" or "(alt 'bacon 'spam 'ham) " in 'there.")))
|