Using SRFI 212 to detect boundness of an identifier in syntax-rules Daphne Preston-Kendal (22 Oct 2022 16:06 UTC)
Re: Using SRFI 212 to detect boundness of an identifier in syntax-rules Marc Nieper-Wißkirchen (22 Oct 2022 16:27 UTC)
Re: Using SRFI 212 to detect boundness of an identifier in syntax-rules Marc Nieper-Wißkirchen (22 Oct 2022 19:07 UTC)

Re: Using SRFI 212 to detect boundness of an identifier in syntax-rules Marc Nieper-Wißkirchen 22 Oct 2022 19:06 UTC

Am Sa., 22. Okt. 2022 um 18:06 Uhr schrieb Daphne Preston-Kendal
<xxxxxx@nonceword.org>:
>
> A neat trick/edge case I just discovered:
>
> (define-syntax bound?
>   (syntax-rules ()
>     ((_ id)
>      (let-syntax
>          ((test
>            (syntax-rules (id)
>              ((_ id id) #t)
>              ((_ _ _) #f))))
>        (alias abracadabra id)
>        (test abracadabra id)))))
>
> > (bound? cons)
> #t
> > (bound? foo)
> #f
>
> This works in Gerbil (where it’s called `define-alias` by default) but not in Chez or Unsyntax for some reason (even adding an extra (let () …) to account for the fact that R6RS let-syntax is splicing) where it always returns #t, and not in Kawa where it always returns #f. Also, it always thinks the identifier ‘abracadabra’ is bound.

You could use an extra macro invocation (or generate-temporaries) to
solve the problem with "abracadabra", of course.

You get "#t" in Chez and Unsyntax because you probably tried this at
the REPL where every identifier is bound (usually to the void value).
If you try your snippet in an R6RS program in Chez (with the (let* ()
...) wrapper), you will get an error because you are not allowed to
alias an unbounded identifier in Chez.