Email list hosting service & mailing list manager

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)

Using SRFI 212 to detect boundness of an identifier in syntax-rules Daphne Preston-Kendal 22 Oct 2022 16:06 UTC

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.

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.

Daphne