[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Understanding `symbol??` macro from

From: Zelphir Kaltstahl
Subject: Understanding `symbol??` macro from
Date: Thu, 14 Mar 2024 00:18:59 +0000

Hello Guile Users!

I am having trouble understanding how the `symbol??` macro from works.

Here is what I have so far:

;; (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)))))

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,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]