unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* syntax taste: use of unquote in macros
@ 2020-03-29 15:11 Matt Wette
  2020-03-29 22:07 ` Zelphir Kaltstahl
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Matt Wette @ 2020-03-29 15:11 UTC (permalink / raw)
  To: Guile User

Hi All,

I'm not sure if you know about this, but there is a discrepancy in the
way some folks define macros to use unquote (aka ,).   For example,

 > (use-modules (system base pmatch))
 > (pmatch '(foo "bar")  ((foo ,val)  (write val) (newline)))
=> "bar"

 > (use-modules (ice-9 match))
 > (match '(foo "bar")  (`(foo ,val)  (write val) (newline)))
=> "bar"

Note the difference in the use of quasiquote (aka `) in the pattern
for (foo ,val): match syntax uses it, pmatch does not.
In Scheme, quasiquote and unquote always come together.

Is pmatch syntax in bad taste?  I'm looking for opinions.

Another example is sxml-match, which omits use of quasiquote.
I have written a variation of sxml-match.  Should I keep the sxml-match
usage, which keeps it compatible with sxml-match,  or adopt that
used by (ice-9 match)?

Matt




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: syntax taste: use of unquote in macros
  2020-03-29 15:11 syntax taste: use of unquote in macros Matt Wette
@ 2020-03-29 22:07 ` Zelphir Kaltstahl
  2020-03-30 10:34   ` tomas
  2020-03-30 13:07 ` Arne Babenhauserheide
  2020-03-31 16:56 ` Ludovic Courtès
  2 siblings, 1 reply; 7+ messages in thread
From: Zelphir Kaltstahl @ 2020-03-29 22:07 UTC (permalink / raw)
  To: Matt Wette, Guile User


On 3/29/20 5:11 PM, Matt Wette wrote:
> Hi All,
>
> I'm not sure if you know about this, but there is a discrepancy in the
> way some folks define macros to use unquote (aka ,).   For example,
>
> > (use-modules (system base pmatch))
> > (pmatch '(foo "bar")  ((foo ,val)  (write val) (newline)))
> => "bar"
>
> > (use-modules (ice-9 match))
> > (match '(foo "bar")  (`(foo ,val)  (write val) (newline)))
> => "bar"
>
> Note the difference in the use of quasiquote (aka `) in the pattern
> for (foo ,val): match syntax uses it, pmatch does not.
> In Scheme, quasiquote and unquote always come together.
>
> Is pmatch syntax in bad taste?  I'm looking for opinions.
>
> Another example is sxml-match, which omits use of quasiquote.
> I have written a variation of sxml-match.  Should I keep the sxml-match
> usage, which keeps it compatible with sxml-match,  or adopt that
> used by (ice-9 match)?
>
> Matt

Hi Matt!

I'm not sure where I first read about pmatch doing the quasiquote
internally automatically and I of course had already forgotten about it,
until I read your e-mail. I remember though: When I read about it, I
thought something like: "Ehhh? That's confusing. Everywhere else you
have to quasiquote to unquote, but in pmatch it's different. Easy to
forget that and I need to remember more. I would not mind having to
write a simple quasiquote myself."

So, with my limited experience, I would definitely vote for the, in my
opinion more natural way, to have the user write the quasiquote, instead
of doing that internally. It's not saving that much time or writing
really. I understand the idea, that "if it is always done anyway, one
could save the user some typing of the same thing over and over again",
but in my opinion it is not worth it to deviate from, what one would
expect without knowing about this behavior.

Regards,
Zelphir




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: syntax taste: use of unquote in macros
  2020-03-29 22:07 ` Zelphir Kaltstahl
@ 2020-03-30 10:34   ` tomas
  2020-03-30 23:43     ` Matt Wette
  0 siblings, 1 reply; 7+ messages in thread
From: tomas @ 2020-03-30 10:34 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 983 bytes --]

On Mon, Mar 30, 2020 at 12:07:07AM +0200, Zelphir Kaltstahl wrote:
> 
> On 3/29/20 5:11 PM, Matt Wette wrote:
> > Hi All,
> >
> > I'm not sure if you know about this, but there is a discrepancy in the
> > way some folks define macros to use unquote (aka ,).   For example,

[pmatch vs. match]

> I'm not sure where I first read about pmatch doing the quasiquote
> internally automatically and I of course had already forgotten about it,

[...]

I didn't even know about `pmatch'. Is it supposed to be equivalent
to `match' (except that outer quasiquote, that is)?

With the caveat that I don't have much of a stylistic feeling for
Scheme, I'd clearly prefer `match': the writer has the choice of
quote or quasiquote, as appropriate to the case -- and the reader
sees what's going on (after all, quote and quasiquote are "low
weight" primitives: everyone more or less knows what they do.

But perhaps I misunderstood what you're after?

Cheers
-- tomás

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: syntax taste: use of unquote in macros
  2020-03-29 15:11 syntax taste: use of unquote in macros Matt Wette
  2020-03-29 22:07 ` Zelphir Kaltstahl
@ 2020-03-30 13:07 ` Arne Babenhauserheide
  2020-03-31 16:56 ` Ludovic Courtès
  2 siblings, 0 replies; 7+ messages in thread
From: Arne Babenhauserheide @ 2020-03-30 13:07 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user


Matt Wette <matt.wette@gmail.com> writes:

> Hi All,
>
> I'm not sure if you know about this, but there is a discrepancy in the
> way some folks define macros to use unquote (aka ,).   For example,
>
>> (use-modules (system base pmatch))
>> (pmatch '(foo "bar")  ((foo ,val)  (write val) (newline)))
> => "bar"
>
>> (use-modules (ice-9 match))
>> (match '(foo "bar")  (`(foo ,val)  (write val) (newline)))
> => "bar"
>
> Note the difference in the use of quasiquote (aka `) in the pattern
> for (foo ,val): match syntax uses it, pmatch does not.
> In Scheme, quasiquote and unquote always come together.
>
> Is pmatch syntax in bad taste?  I'm looking for opinions.

I did not know about pmatch, but it gives me the feeling that this is a
pattern that will appear again for other embedded domain specific
languages.

I had a usecase for that in dryads-wake¹ for embedding instructions in
otherwise declarative code. It looks like this:

(Enter (Speaker))
(Speaker
    (My Text, line 1)
    (Second line)
    (very ,(color 'red) important ,(color #f) line))

At this point the difference to quasiquote doesn’t look big. It gets
much bigger when this code is used from wisp:²

Enter : Speaker
Speaker
    My Text, line 1
    Second line
    very ,(color 'red) important ,(color #f) line

With written quasiquote there would either be line-noise on every line
or this would have structure-noise because it would have to be wrapped
in a list instead of working like arguments to a procedure call:

(Enter (Speaker))
(Speaker
  `((My Text, line 1)
    (Second line)
    (very ,(color 'red) important ,(color #f) line)))

or

(Enter (Speaker))
(Speaker
    `(My Text, line 1)
    `(Second line)
    `(very ,(color 'red) important ,(color #f) line))

Best wishes,
Arne

¹: https://hg.sr.ht/~arnebab/dryads-wake/browse/default/dryads-wake.w#L231
²: https://www.draketo.de/english/wisp
-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: syntax taste: use of unquote in macros
  2020-03-30 10:34   ` tomas
@ 2020-03-30 23:43     ` Matt Wette
  2020-03-31  9:19       ` tomas
  0 siblings, 1 reply; 7+ messages in thread
From: Matt Wette @ 2020-03-30 23:43 UTC (permalink / raw)
  To: guile-user

On 3/30/20 3:34 AM, tomas@tuxteam.de wrote:
> On Mon, Mar 30, 2020 at 12:07:07AM +0200, Zelphir Kaltstahl wrote:
>> On 3/29/20 5:11 PM, Matt Wette wrote:
>>> Hi All,
>>>
>>> I'm not sure if you know about this, but there is a discrepancy in the
>>> way some folks define macros to use unquote (aka ,).   For example,
> [pmatch vs. match]
>
>> I'm not sure where I first read about pmatch doing the quasiquote
>> internally automatically and I of course had already forgotten about it,
> [...]
>
> I didn't even know about `pmatch'. Is it supposed to be equivalent
> to `match' (except that outer quasiquote, that is)?
>
> With the caveat that I don't have much of a stylistic feeling for
> Scheme, I'd clearly prefer `match': the writer has the choice of
> quote or quasiquote, as appropriate to the case -- and the reader
> sees what's going on (after all, quote and quasiquote are "low
> weight" primitives: everyone more or less knows what they do.
>
> But perhaps I misunderstood what you're after?
>
> Cheers
> -- tomás

The other thing about match that is attractive is that use of
quasiquote+unquote is "reflexive" (or maybe self-adjoint?)
in the following sense:

'(foo "bar") => (match-lambda (`(foo ,val) `(foo ,val))) => '(foo "bar")






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: syntax taste: use of unquote in macros
  2020-03-30 23:43     ` Matt Wette
@ 2020-03-31  9:19       ` tomas
  0 siblings, 0 replies; 7+ messages in thread
From: tomas @ 2020-03-31  9:19 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 422 bytes --]

On Mon, Mar 30, 2020 at 04:43:47PM -0700, Matt Wette wrote:

[...]

> The other thing about match that is attractive is that use of
> quasiquote+unquote is "reflexive" (or maybe self-adjoint?)
> in the following sense:
> 
> '(foo "bar") => (match-lambda (`(foo ,val) `(foo ,val))) => '(foo "bar")

Sorry, my head just exploded :-)

Will take it more slowly later today. Thanks for the riddle.

Cheers
-- t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: syntax taste: use of unquote in macros
  2020-03-29 15:11 syntax taste: use of unquote in macros Matt Wette
  2020-03-29 22:07 ` Zelphir Kaltstahl
  2020-03-30 13:07 ` Arne Babenhauserheide
@ 2020-03-31 16:56 ` Ludovic Courtès
  2 siblings, 0 replies; 7+ messages in thread
From: Ludovic Courtès @ 2020-03-31 16:56 UTC (permalink / raw)
  To: guile-user

Hi Matt,

Matt Wette <matt.wette@gmail.com> skribis:

> I'm not sure if you know about this, but there is a discrepancy in the
> way some folks define macros to use unquote (aka ,).   For example,
>
>> (use-modules (system base pmatch))
>> (pmatch '(foo "bar")  ((foo ,val)  (write val) (newline)))
> => "bar"
>
>> (use-modules (ice-9 match))
>> (match '(foo "bar")  (`(foo ,val)  (write val) (newline)))
> => "bar"
>
> Note the difference in the use of quasiquote (aka `) in the pattern
> for (foo ,val): match syntax uses it, pmatch does not.
> In Scheme, quasiquote and unquote always come together.
>
> Is pmatch syntax in bad taste?  I'm looking for opinions.

It really depends on what you’re going to use the pattern matcher for.
For ‘sxml-match’, it’s more convenient to have literals be the default
because there are usually more literals than variables, as in:

       (sxml-match x
         ((album (@ (title ,t)) (catalog (num ,n) (fmt ,f)) ...)
          `(ul (li ,t)
               (li (b ,n) (i ,f)) ...)))

In more general cases, I prefer the (ice-9 match) style because patterns
typically have more variables than literals.

In one case, I found myself implementing pmatch-style quoting on top of
(ice-9 match) so I would have the best of both worlds:

  https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/installer/tests.scm#n84

:-)

Ludo’.




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-03-31 16:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-29 15:11 syntax taste: use of unquote in macros Matt Wette
2020-03-29 22:07 ` Zelphir Kaltstahl
2020-03-30 10:34   ` tomas
2020-03-30 23:43     ` Matt Wette
2020-03-31  9:19       ` tomas
2020-03-30 13:07 ` Arne Babenhauserheide
2020-03-31 16:56 ` Ludovic Courtès

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).