unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Arne Babenhauserheide <arne_bab@web.de>
To: Matt Wette <matt.wette@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: syntax taste: use of unquote in macros
Date: Mon, 30 Mar 2020 15:07:36 +0200	[thread overview]
Message-ID: <87sghqat47.fsf@web.de> (raw)
In-Reply-To: <dd403a66-123b-2855-39cb-7b5c5f36cd9a@gmail.com>


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



  parent reply	other threads:[~2020-03-30 13:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2020-03-31 16:56 ` 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=87sghqat47.fsf@web.de \
    --to=arne_bab@web.de \
    --cc=guile-user@gnu.org \
    --cc=matt.wette@gmail.com \
    /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).