unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Understanding `symbol??` macro from okmij.org
@ 2024-03-14  0:18 Zelphir Kaltstahl
  2024-03-14  1:01 ` Jean Abou Samra
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Zelphir Kaltstahl @ 2024-03-14  0:18 UTC (permalink / raw)
  To: Guile User

Hello Guile Users!

I am having trouble understanding how the `symbol??` macro from 
https://okmij.org/ftp/Scheme/assert-syntax-rule.txt works.

Here is what I have so far:

~~~~start~~~~
;; (symbol?? FORM KT KF)
;; FORM is an arbitrary form or datum.
;; A symbol? predicate at the macro-expand time.
;; Expands in KT if FORM is a symbol (identifier), Otherwise, expands in KF.
;; KT: Continuation/Case in case of true.
;; KF: Continuation/Case in case of false.
(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
     ;; 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)))))
~~~~~end~~~~~

So I don't understand why `test` works or how it works to check, whether 
`maybe-symbol` is a symbol or not. And I don't understand how `abracadabra` 
helps with that, or why it helps, to pass something undefined.

Can someone help me understand, what is going on there?

Actually I am trying to understand the whole page, and I got there while looking 
for a good `assert` macro ... rabbit hole and all that.

Best regards,
Zelphir

-- 
repositories:https://notabug.org/ZelphirKaltstahl


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

end of thread, other threads:[~2024-03-14 18:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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