| This just pushed on nex-3's arc-wiki.git: (defpat *defpat-rpn
" Example/testcase for defpat in using
,(x (test x)) guarded patterns "
;start with an empty stack
(lst)
(*defpat-rpn lst '())
;all done; return what's on the stack
(() (x))
x
;extra stuff on the stack
(() (_ . __))
(ero "extra stuff on the stack")
;divide by zero
((,(f (is f /)) . _) (0 x . __))
(ero "divide by zero")
;pop, pop, push...
((,(f (isa f 'fn)) . xs) (b a . s))
(*defpat-rpn xs `(,(f a b) ,@s) )
;not enough to pop
((,(f (isa f 'fn)) . xs) x)
(ero "too few parameters")
;just push
((x . xs) s)
(*defpat-rpn xs `(,x ,@s)))
edit: oh and by the way, patterns like this will work: (defpat foo
((x . 'x)) (prn "you have an x of "x)
((y . ,(s (isa s 'sym))))
(prn "Not an x, but a " s " of " y))
To support the above, though, you can't use quote and unquote as variable names. |