guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: macroexpand-1


From: Mark H Weaver
Subject: Re: macroexpand-1
Date: Sun, 03 Jun 2018 10:04:12 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Hi,

Catonano <address@hidden> writes:

> 2018-05-30 3:07 GMT+02:00 Mark H Weaver <address@hidden>:
>
>  This is just a toy, and not very useful in practice.
>  Here's the equivalent formulation for Guile:
>
>    (use-modules (system syntax)
>                 (srfi srfi-11))
>
>    (define (syntax-local-value id)
>      (let-values (((type value) (syntax-local-binding id)))
>        value))
>
>    (define-syntax expand1
>      (lambda (stx)
>        (syntax-case stx ()
>          [(_expand1 form)
>           (syntax-case #'form ()
>             [(id . more)
>              (identifier? #'id)
>              (let ([transformer (syntax-local-value #'id)])
>                (with-syntax ([expansion (transformer #'form)])
>                  #''expansion))]
>             [_
>              #''form])])))
>
>  (I usually prefer to avoid using square brackets in this way, but for
>  sake of comparison, I used them in the definition of 'expand1' above.)
>
>  Anyway, it works the same way as in Racket for this simple example:
>
>    scheme@(guile-user)> (expand1 (or 1 2 3))
>    $2 = (let ((t 1)) (if t t (or 2 3)))
>
> This is surprising to me
>
> When I saw that example made in Racket for the first time I instantly
> identified "syntax-local-value" as problematic

You're right, it is problematic, and it's good that you noticed that.
It exposes internal details of Guile's implementation, which is quite
likely to change in the future.  Do not use this interface if you can
avoid it, and expect code that uses it to break in future versions of
Guile.  That said, it can be useful for writing things like macro
steppers.

> Will Guile have anything equivalent ? I asked myself
>
> Now you show me the "(system syntax)" namespace (or module)
>
> I didn't  suspect it existed
>
> Does the manual mention it anywhere ? I didn' t see it

Do you know how to search the manual or its index?  Press 'i' from
either the Emacs or standalone info browsers to search the index, where
you can find 'syntax-local-binding'.

You can also search the entire manual text by pressing 's'.  You can
find (system syntax) that way.

> Or maybe does it belong to any scheme standard ?

No, certainly not.

> Do any more (system ....) namespaces exist ? 
>
> How would I know ?

Look in the "module" subdirectory of the Guile source tree for modules
that come with Guile itself, or more generally in the directories of
%load-path after installation.  The directory structure mirrors the
module namespaces.  The module (foo bar baz) is found in
<DIR>/foo/bar/baz.scm, where <DIR> is a component of %load-path.  For
example, (system syntax) is in <DIR>/system/syntax.scm.  In the Guile
source tree, it's in module/system/syntax.scm.

      Mark



reply via email to

[Prev in Thread] Current Thread [Next in Thread]