[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Macro id-memv??, workings of tripple dot
From: |
Zelphir Kaltstahl |
Subject: |
Macro id-memv??, workings of tripple dot |
Date: |
Fri, 15 Mar 2024 01:19:42 +0000 |
Hello Guile Users,
I have another macro understanding question and I think I don't yet grasp all
the usages of the ellipsis/tripple dot/... :
Again it is a macro from https://okmij.org/ftp/Scheme/assert-syntax-rule.txt.
This time the id-memv macro, which I think I mostly understand, but have
questions about:
~~~~
;; A macro-expand-time memv function for identifiers
;; id-memv?? FORM (ID ...) KT KF
;; FORM is an arbitrary form or datum, ID is an identifier.
;; The macro expands into KT if FORM is an identifier, which occurs
;; in the list of identifiers supplied by the second argument.
;; All the identifiers in that list must be unique.
;; Otherwise, id-memv?? expands to KF.
;; Two identifiers match if both refer to the same binding occurrence, or
;; (both are undefined and have the same spelling).
(define-syntax id-memv??
(syntax-rules ()
((id-memv?? form (id ...) kt kf)
(let-syntax ((test
;; Putting the ID matched in the outer syntax-rules
;; form, where it is flexible to stand for any
;; identifier, into the literals list makes it so,
;; that whatever was matched in the outer
;; syntax-rules is now literally matched against in
;; the inner syntax-rules.
(syntax-rules (id ...)
;; If indeed FORM is the same identifier as ID,
;; then the result is the continuation for the
;; true case.
((test id _kt _kf) _kt) ...
((test otherwise _kt _kf) _kf))))
;; Pass the form to be checked to test.
(test form kt kf)))))
~~~~
My question is: Do the ... in the case
((test id _kt _kf) _kt) ...
produce one case for each identifier in the list? I am guessing that this is
what they do. However, they are mentioned as literals in the inner syntax-rules,
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.
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?
For example:
(id-memv?? c (a b c) #t #f)
would internally expand into the cases:
((test a _kt _kf) _kt) _kt)
((test b _kt _kf) _kt) _kt)
((test c _kt _kf) _kt) _kt)
((test otherwise _kt _kf) _kf)
?
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."
So maybe I am just trying to see things here.
Best regards,
Zelphir
repositories:https://notabug.org/ZelphirKaltstahl
- Macro id-memv??, workings of tripple dot,
Zelphir Kaltstahl <=