Re: Using SRFI 212 to detect boundness of an identifier in syntax-rules Marc Nieper-WiÃkirchen
22 Oct 2022 16:26 UTC
At least under an R6RS-like where violations must not be ignored, you
can also use SRFI 213:
(syntax-case stx ()
(guard (exc [(syntax-violation? exc) #'#f])
(lookup #'id #'*)
Am Sa., 22. Okt. 2022 um 18:06 Uhr schrieb Daphne Preston-Kendal
> A neat trick/edge case I just discovered:
> (define-syntax bound?
> (syntax-rules ()
> ((_ id)
> (syntax-rules (id)
> ((_ id id) #t)
> ((_ _ _) #f))))
> (alias abracadabra id)
> (test abracadabra id)))))
> > (bound? cons)
> > (bound? foo)
> 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.
> Since this falls under ‘If identifier2 is unbound, it is an error’, I think this is not very useful. But I was still pretty pleased when I found it worked on Gerbil.