unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] psyntax: custom ellipses using 'with-ellipsis' or R7RS syntax-rules
Date: Wed, 08 Jan 2014 15:10:41 -0500	[thread overview]
Message-ID: <8761puxmim.fsf@netris.org> (raw)
In-Reply-To: <871u0i8zvx.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Wed, 08 Jan 2014 12:41:06 +0100")

Hi Ludovic,

ludo@gnu.org (Ludovic Courtès) writes:

> Mark H Weaver <mhw@netris.org> skribis:
>
>> In the end, here's how this works: 'with-ellipsis' binds a special
>> identifier named #{ $sc-ellipsis }# using a new 'ellipsis' binding type.
>> The new ellipsis identifier is stored within the binding.  In order to
>> determine whether an identifier X is an ellipsis, the binding for
>> #{ $sc-ellipsis }# is looked up in the lexical environment of X.  If the
>> binding is found and has binding-type 'ellipsis', then X is compared to
>> the identifier stored in the binding using 'bound-id=?'.  Otherwise, X
>> is compared to '...' using 'free-id=?' as was done before.
>
> This looks nice!  Thanks for providing the detailed reasoning, that’s
> insightful.
>
> Does something like this work:
>
>   (define-syntax define-inline
>     (with-ellipsis ---
>       (syntax-rules ()
>         ((_ (name parms ---) exp ---)
>          (define-syntax name
>             (syntax-rules ()
>               ((_ args (--- ---))
>                ((lambda (parms ---) exp ---)
>                 args (--- ---)))))))))

No, because as noted in the docs, the custom ellipsis does not propagate
to the generated code.  Therefore, given the above definition,

  (define-inline (foo a b c) (list a b c))

expands to:

  (define-syntax foo
    (syntax-rules ()
      ((_ args ---)
       ((lambda (a b c) (list a b c))
        args ---))))

However, '---' is not the ellipsis identifier for this generated macro,
because the 'with-ellipsis' is not present in the generated code.
Therefore, '---' is treated as a normal pattern variable by the
generated macro.

It is important that the custom ellipsis does not propagate to the
generated code, so that we can use 'with-ellipsis' to implement R7RS
'syntax-rules', which allows a custom ellipsis as its first operand,
before the literals list.  In R7RS 'syntax-rules', the custom ellipsis
does not propagate to generated code.

A corrected version of your macro is the following:

  (define-syntax define-inline
    (with-ellipsis ---
      (syntax-rules ()
        ((_ (name parms ---) exp ---)
         (define-syntax name
           (syntax-rules ()
             ((_ args ...)
              ((lambda (parms ---) exp ---)
               args ...))))))))

Note that as currently implemented, the effect of 'with-ellipsis'
also does not propagate into nested syntax definition forms such as
'let-syntax', 'letrec-syntax', and 'define-syntax'.  We could go either
way on this.

I confess that I didn't make this decision intentionally.  It was an
accident of the current implementation.  The reason is that transformer
expressions are evaluated in a "macros only" environment, with all other
bindings removed (see 'macros-only-env' in psyntax.scm).  We could
arrange to keep the ellipsis binding in that restricted environment as
well, if desired.  I don't think it matters much.

What do you think?

> Could you wrap lines to 80 columns in psyntax.scm?

Ordinarily I try to keep lines to 80 columns, but psyntax.scm already
has a great deal of code that violates that rule.  Fixing that would be
a rather large commit, and I'm not sure it would be an improvement.

>> +@subsubsection Specifying a custom ellipsis identifier
>
> Should be “Specifying a Custom Ellipsis Identifier”.
>
>> +@subsubsection Custom ellipsis identifiers for syntax-case macros
>
> Likewise.

Okay.

   Thanks!
     Mark



  reply	other threads:[~2014-01-08 20:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-19  0:33 [PATCH] psyntax: custom ellipses using 'with-ellipsis' or R7RS syntax-rules Mark H Weaver
2014-01-08 11:41 ` Ludovic Courtès
2014-01-08 20:10   ` Mark H Weaver [this message]
2014-01-08 20:53     ` Ludovic Courtès
2014-01-09 23:07       ` Mark H Weaver
2014-01-10 13:02         ` Ludovic Courtès
2014-01-10 17:08           ` Mark H Weaver
2014-01-10 20:36             ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8761puxmim.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).