On Apr 25, 2009, at 7:38 PM, Michele Simionato wrote:

Now I remember that I had even another use case in mind, i.e. an enumeration
macro, to be shown in future episodes:

$ cat enum.ss
(import (rnrs) (sweet-macros) (aps list-utils))

(def-syntax (enum name ...)
  (with-syntax (((i ...) (range (length #'(name ...)))))
  #'(syntax-match (name ...)
      (sub (ctx name) #'i) ...))
  (distinct? free-identifier=? #'(name ...))
  (syntax-violation 'enum "Duplicate name" #'(name ...)))

(def-syntax color (enum red green blue))

(display (list (color red) (color green) (color blue))); => (0 1 2)

;;(def-syntax color (enum red red blue)) ; raises a syntax-violation


Is free-identifier=? right in this use case?

If you're going to compare the identifiers using free-identifier=?,
then using (distinct? free-identifier=? #'(name ...)) makes sense.
If you intend to compare them literally (the way they're spelled),
then it also makes sense to use identifier=? both in the distinct?
check and when the enum macro is used.  Either way, it probably
doesn't make sense to use bound-identifier=? unless you're going
to bind these identifiers.

Aziz,,,


Reply via email to