unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Macro id-memv??, workings of tripple dot
@ 2024-03-15  1:19 Zelphir Kaltstahl
  2024-03-15  8:03 ` Jean Abou Samra
  0 siblings, 1 reply; 3+ messages in thread
From: Zelphir Kaltstahl @ 2024-03-15  1:19 UTC (permalink / raw)
  To: Guile User

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


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

end of thread, other threads:[~2024-03-15 10:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-15  1:19 Macro id-memv??, workings of tripple dot Zelphir Kaltstahl
2024-03-15  8:03 ` Jean Abou Samra
2024-03-15 10:05   ` Zelphir Kaltstahl

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