From: Maxime Devos <maximedevos@telenet.be>
To: "Михаил Бахтерев" <mob@k.imm.uran.ru>, guile-user@gnu.org
Subject: Re: Is it possible to expand syntax inside match?
Date: Sun, 24 Oct 2021 19:48:01 +0000 [thread overview]
Message-ID: <60fe167bfab829583b1ba6dca28c06b76fd41b9c.camel@telenet.be> (raw)
In-Reply-To: <YXT/qI6FDv17VqWM@z>
Михаил Бахтерев schreef op zo 24-10-2021 om 11:49 [+0500]:
> Greetings!
>
> I wondering, if is it possible to implement something like
> this?
>
> (define-syntax R (syntax-rules () ((_ r v l) #(red r v l))))
> (define-syntax B (syntax-rules () ((_ r v l) #(black r v l))))
>
> (define red-black-set-balance
> (match-lambda
> ((or (B (R (R a x b) y c) z d)
> (B (R a x (R b y c)) z d)
> (B a x (R (R b y c) z d))
> (B a x (R b y (R c z d)))) (R (B a x b) y (B c z d)))
> (node node)))
Not exactly what you were looking for, but maybe use quasisyntax /
unsyntax #` #, something like (untested):
;; define, not define-syntax!
(define R (syntax-rules () ((_ r v l) #(red r v l))))
(define B (syntax-rules () ((_ r v l) #(black r v l))))
(define-syntax red-black-set-balance-m
(lambda (s)
#`(match-lambda
((or #,(B (R (R a x b) y c) z d)
#,(B (R a x (R b y c)) z d)
...))
(node node))))
(define red-black-set-balance red-black-set-balance-m)
Greetings,
Maxime
prev parent reply other threads:[~2021-10-24 19:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-24 6:49 Is it possible to expand syntax inside match? Михаил Бахтерев
2021-10-24 19:48 ` Maxime Devos [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=60fe167bfab829583b1ba6dca28c06b76fd41b9c.camel@telenet.be \
--to=maximedevos@telenet.be \
--cc=guile-user@gnu.org \
--cc=mob@k.imm.uran.ru \
/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).