diff --git a/docs/api/scheme/eval.md b/docs/api/scheme/eval.md index 65960a22..fd6d7653 100644 --- a/docs/api/scheme/eval.md +++ b/docs/api/scheme/eval.md @@ -34,6 +34,11 @@ A non-standard function to initialize a new global environment. # expand - (expand expr environment rename-environment) + (expand expr [[environment] [rename-environment]]) + +Perform macro expansion on `expr` and return the resulting expression. + +`environment` may be optionally passed as the current environment. + +`rename-environment` is an optional argument of an environment containing variables renamed directly by macros. This would generally be an empty environment when using this function for macro debugging. -Perform macro expansion on `expr` and `environment` is the current environment. `rename-environment` is an environment containing variables renamed directly by macros; this would generally be an empty environment when using this function for macro debugging. diff --git a/scheme/eval.sld b/scheme/eval.sld index ee12e9e2..f45ec40a 100644 --- a/scheme/eval.sld +++ b/scheme/eval.sld @@ -982,8 +982,14 @@ ;TODO: modify this whole section to use macros:get-env instead of *defined-macros*. macro:get-env becomes the mac-env. any new scopes need to extend that env, and an env parameter needs to be added to (expand). any macros defined with define-syntax use that env as their mac-env (how to store that)? ; expand : exp -> exp -(define (expand exp env rename-env) - (_expand exp env rename-env '() '())) +(define (expand exp . opts) + (let ((env (if (> (length opts) 0) + (car opts) + *global-environment*)) + (rename-env (if (> (length opts) 1) + (cadr opts) + (env:extend-environment '() '() '())))) + (_expand exp env rename-env '() '()))) ;; Internal implementation of expand ;; exp - Expression to expand