From: Maxime Devos <maximedevos@telenet.be>
To: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>,
Guile User <guile-user@gnu.org>
Subject: RE: Understanding `symbol??` macro from okmij.org
Date: Thu, 14 Mar 2024 02:03:07 +0100 [thread overview]
Message-ID: <20240314020307.yR322B00F319MNK01R36Mg@andre.telenet-ops.be> (raw)
In-Reply-To: <9142ff20-0722-4fb7-b35a-7434e68d1777@posteo.de>
(define-syntax symbol??
(syntax-rules ()
;; The check is done by first pattern matching against some other
;; forms, that are not a symbol.
((symbol?? (x . y) kt kf) kf) ; It's a pair, not a symbol
((symbol?? #(x ...) kt kf) kf) ; It's a vector, not a symbol
The first two cases don’t need any explanation I think.
;; After those things are excluded, the thing might be a symbol.
((symbol?? maybe-symbol kt kf)
(let-syntax ((test
(syntax-rules ()
((test maybe-symbol t f) t)
((test x t f) f))))
(test abracadabra kt kf)))))
If maybe-symbol is a symbol, then (test abracadabra kt kf) matches (test maybe-symbol t f) (let t=kt, f=kf, maybe-symbol=abracadabra).
If maybe-symbol is not a symbol, for example it is a string “hello” (please ignore wrong quoting), then
(test maybe-symbol t f) becomes (test “hello” t f). The string “hello” cannot act as an identifier (because it is a string, not a symbol), so (test abracadabra kt kf) does not match the first case (test maybe-symbol t f). Only the second case (test x t f) remains, and (test abracadabra kt kf) matches this (set x to abracadabra, t to kt, f to kf).
I think the first two cases are superfluous, but perhaps there is a performance advantage.
(I’m wondering if this still works in the case (symbol? ...), because ... is special in syntax-rules)
Best regards,
Maxime Devos.
next prev parent reply other threads:[~2024-03-14 1:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-14 0:18 Understanding `symbol??` macro from okmij.org Zelphir Kaltstahl
2024-03-14 1:01 ` Jean Abou Samra
2024-03-14 1:03 ` Maxime Devos [this message]
2024-03-14 13:46 ` Zelphir Kaltstahl
2024-03-14 14:52 ` Olivier Dion
2024-03-14 15:57 ` Jean Abou Samra
2024-03-14 16:39 ` Olivier Dion
2024-03-14 18:01 ` Jean Abou Samra
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=20240314020307.yR322B00F319MNK01R36Mg@andre.telenet-ops.be \
--to=maximedevos@telenet.be \
--cc=guile-user@gnu.org \
--cc=zelphirkaltstahl@posteo.de \
/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).