skx / yal

Yet another lisp interpreter
GNU General Public License v2.0
16 stars 0 forks source link

Allow default arguments #130

Closed skx closed 1 year ago

skx commented 1 year ago

I came across this example, recently:

(define*
 ;; function name: hi
 ;; a is needed
 ;; b has default argument 32
 ;; c has default argument "hi"
 (hi a (b 32) (c "hi"))
 ;; just returning the arguments
 (list a b c))

(list
 (hi 1)
 (hi :c 332 :a 3)
 (hi 3 2 1))

I'm not sure about the named-arguments, used when calling a function, but allowing default values for parameters seems nice and the syntax is trivial to handle.

skx commented 1 year ago

Reference: