Skip to content

Instantly share code, notes, and snippets.

@flambard
Created March 19, 2014 21:33
Show Gist options
  • Save flambard/9651871 to your computer and use it in GitHub Desktop.
Save flambard/9651871 to your computer and use it in GitHub Desktop.
Naive implementation of multi-arity defun in CL.
(defmacro defun-multi (name &body clauses)
(let ((vars-sym (gensym "VARS")))
`(defun ,name (&rest ,vars-sym)
(ecase (length ,vars-sym)
,@(loop
for (vars . body) in clauses
collect `(,(length vars)
(destructuring-bind ,vars ,vars-sym ,@body))))) ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment