Skip to content

Instantly share code, notes, and snippets.

@SuzanneSoy
Forked from dumbs/gist:664599
Created November 5, 2010 19:00
Show Gist options
  • Save SuzanneSoy/664610 to your computer and use it in GitHub Desktop.
Save SuzanneSoy/664610 to your computer and use it in GitHub Desktop.
(defun make-stat-env (params &optional env (position 1) num-env)
(unless num-env (setq num-env (+ (or (second (first env)) -1) 1)))
(cond ((endp params)
env)
((eq '&optional (car params))
`((,(cadr params) ,num-env ,position)
(,(intern (format nil "~a-P" (cadr params))) ,num-env ,(+ 1 position))
. ,(make-stat-env (cddr params) env (+ 2 position) num-env)))
((eq '&rest (car params))
(make-stat-env (cdr params) env position num-env))
(t
`((,(car params) ,num-env ,position)
. ,(make-stat-env (cdr params) env (+ 1 position))))))
(make-stat-env '(a b &optional c))
=> ((A 0 1) (B 0 2) (&OPTIONAL 0 3) (C 0 4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment