[plt-scheme] expand
On May 23, 2007, at 10:46 AM, Jos K oot wrote:
> Hi,
> In section 12.6.1 "Expanding Expressions to Primitive Syntax" of the
> fine "PLT Mzscheme Language Manual" the possible shapes of fully
> expanded expressions are shown. The display does not account for the
> lifting of expressions within nested begin forms. Can I safely assume
> the following?
>
> fully-expanded-expr is top-level-expr
>
> top-level-expr is one of
> general-top-level-expr
> (#%expression expr)
> (module identifier name (#%plain-module-begin module-level-expr*
> ···)) <=== see below
> (begin top-level-expr ···)
>
> module-level-expr is one of
> general-top-level-expr
> (provide provide-spec ...)
>
> general-top-level-expr is one of
> expr
> (define-values (variable ···) expr)
> (define-syntaxes (identifier ···) expr)
> (define-values-for-syntax (variable ···) expr)
> (require require-spec ···)
> (require-for-syntax require-spec ···)
> (require-for-template require-spec ···)
>
> expr is one of
> variable
> (lambda formals expr* ···1) <=== see below
> (case-lambda (formals expr* ···1) ···) <=== see below
> (if expr expr)
> (if expr expr expr)
> (begin expr* ···1)
> (begin0 expr expr* ···) <=== see below
> (let-values (((variable ···) expr) ···) expr* ···1) <=== see below
> (letrec-values (((variable ···) expr) ···) expr* ···1) <=== see below
> (set! variable expr)
> (quote datum)
> (quote-syntax datum)
> (with-continuation-mark expr expr expr)
> (#%app expr ···1)
> (#%datum . datum)
> (#%top . variable)
> (#%variable-reference variable)
> (#%variable-reference (#%top . variable))
>
> top-level-expr* is any top-level-expr except (begin any ...)
> module-level-expr* is any module-level-expr except (begin any ...)
> expr* is any expr except (begin any ...)
No. 'begin' forms can still show up in fully-expanded code as
expressions:
(expand '(#%expression (begin (begin 'a 'b) (begin (begin 'c)))))
(expand '(module m mzscheme (#%expression (begin 'a 'b))))
(expand '(lambda () (#%expression (begin 'a 'b))))
The expander flattens out 'begin' forms when looking for definitions,
whether at the top-level or within a module or within an internal
definition context (a 'lambda' body, etc). Once it goes into expression
mode, it stops treating 'begin' specially.
Ryan
>
> The word 'except' is not nice, but without it, the description becomes
> unnecesary complicated/duplicated, I think.
>
> Kind regards, Jos Koot
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme