unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: Guile User <guile-user@gnu.org>
Subject: Understanding `symbol??` macro from okmij.org
Date: Thu, 14 Mar 2024 00:18:59 +0000	[thread overview]
Message-ID: <9142ff20-0722-4fb7-b35a-7434e68d1777@posteo.de> (raw)

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


             reply	other threads:[~2024-03-14  0:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14  0:18 Zelphir Kaltstahl [this message]
2024-03-14  1:01 ` Understanding `symbol??` macro from okmij.org 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

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=9142ff20-0722-4fb7-b35a-7434e68d1777@posteo.de \
    --to=zelphirkaltstahl@posteo.de \
    --cc=guile-user@gnu.org \
    /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).