$ git clone https://github.com/akkartik/wart.git # needs SBCL
$ cd wart
$ git checkout 7b5109581b3c5d56c767e618f903c12cdd5173f7
$ wart
wart> (def fact(n)
(* n (fact (- n 1))))
fact
wart> (def fact(n) :case (iso 0 n)
1)
fact
wart> (fact 8)
40320
While this style of definition with guarded clauses may be reminiscent of functional languages[1], I plan to use guards only where I may want to add more in the future. Some use cases:a) Currying: (def foo(a) (fn(b) (foo a b)))
(def foo(a b) (+ a b))
foo.3.4 ; 7
b) Overloading macros. To allow let to define recursive local functions (https://arclanguage.org/item?id=13763): (mac let(f . body) :case (match f '(def . _))
`(labels (,(cdr f))
,@body))
c) I'm going to replace my old defgeneric/defmethod setup to just use def.[2]--- [1] In haskell, for example: fac 0 = 1
fac n = n * fac (n-1)
[2] In acknowledgement that the approach of https://awwx.ws/extend is superior :) |