unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: Jean Abou Samra <jean@abou-samra.fr>
Cc: Guile User <guile-user@gnu.org>
Subject: Re: Macro id-memv??, workings of tripple dot
Date: Fri, 15 Mar 2024 10:05:48 +0000	[thread overview]
Message-ID: <a6a48f8d-f982-4b2e-89fc-e7fb985db99d@posteo.de> (raw)
In-Reply-To: <58f1231fa7ae3b9e14e0da428c9ead4d21a87394.camel@abou-samra.fr>

Hello Jean!

On 3/15/24 09:03, Jean Abou Samra wrote:
>> My question is: Do the ... in the case
>>
>> ((test id _kt _kf) _kt) ...
>>
>> produce one case for each identifier in the list?
>
> Yes, they do.
>
>
>> I am guessing that this is what they do. However, they are mentioned as literals in the inner syntax-rules,
>
> No, they aren't. The (id ...) form is expanded by the outer syntax-rules
> form, as part of expanding the id-memv?? macro. They don't remain in the
> expanded result. For example, if you call
>
> (id-memv?? foo (foo bar baz) kt kf)
>
> the expansion will look like
>
> (let-syntax ((test
>                (syntax-rules (foo bar baz)
>                  ((test foo _kt _kf) _kf)
>                  ((test bar _kt _kf) _kf)
>                  ((test baz _kt _kf) _kf)
>                  ((test otherwise _kt _kf) _kf))))
>    (test foo kt kf))
Aha! Of course! The inner syntax-rules is nothing special from the perspective 
of the outer syntax-rules! Somehow I saw it as something special and "evaluated 
from the inside out" in my head instead of from the "outside in", as I should 
have been doing. That makes a lot more sense now.
>> so I was thinking the expansion will simply put literally three dots there,
>> instead of understanding the three dots to mean "for each of the ids".
>>
>> And also I still am unsure about whether the three dots work like this at all.
>
> They do.
>
>
>> When one puts the ... after a compound expression, that contains the thing, that
>> the ... were after in the matching -- in this case they were after id, and id is
>> contained in the compound expression (test id _kt _kf) _kt) -- does that make
>> the compound expression be generated for each thing matched?
>
> Yes, see:
>
> (syntax->datum
>   (with-syntax ((simple #'a)
>                 ((compound ...) #'(b c d))
>                 (((nested-compound ...) ...) #'((e f g) (h i j))))
>     #'(((simple compound nested-compound) ...) ...)))
>
> ⇒ (((a b e) (a c f) (a d g)) ((a b h) (a c i) (a d j)))
That example is quite difficult to unpack for me, but I think I get it. Sort of. 
It is showing the reverse thing, not matching, but telling Guile what the match 
is. And then using that in an expression.
>> But if this is the case, then I might be misunderstanding the Guile docs at
>> https://www.gnu.org/software/guile/manual/html_node/Syntax-Rules.html:
>>
>> "Instances of a pattern variable in the template must be followed by an ellipsis."
> Note that this is talking about the patterns, not the syntax forms. But it
> is slightly misleading: also in patterns it is perfectly possible to do
> something like
>
> (syntax->datum
>   (with-syntax ((((a b) ...) #'((1 2) (3 4) (5 6))))
>     #'((a ...) . (b ...))))
>
> ⇒ ((1 3 5) 2 4 6)
OK, this is easier to understand. It tells Guile what values A and B will be and 
then uses A and B in another way. But still quite cool, that this is possible. 
Not sure where to use it yet.
> Note the pattern
>
> ((a b) ...)
>
> An ellipsized pattern is recognized by the ellipsis, but it doesn't
> need to follow a simple pattern variable, it can follow a nested
> pattern.
What do you mean by "follow a nested pattern"?
> Best,
> Jean
As before, thanks for the revelations!
Zelphir

-- 
repositories:https://notabug.org/ZelphirKaltstahl


      reply	other threads:[~2024-03-15 10:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-15  1:19 Macro id-memv??, workings of tripple dot Zelphir Kaltstahl
2024-03-15  8:03 ` Jean Abou Samra
2024-03-15 10:05   ` Zelphir Kaltstahl [this message]

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=a6a48f8d-f982-4b2e-89fc-e7fb985db99d@posteo.de \
    --to=zelphirkaltstahl@posteo.de \
    --cc=guile-user@gnu.org \
    --cc=jean@abou-samra.fr \
    /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).