On Jun 14, 2009, at 10:46 PM, Abdulaziz Ghuloum wrote:


On Jun 14, 2009, at 6:01 PM, Abdulaziz Ghuloum wrote:

(define-syntax when-bound
  (lambda (x)
    (syntax-case x ()
      [(ctxt (id) e* ...)
       (let ([t (car (generate-temporaries '(t)))])
         (if (free-identifier=? #'id
                (datum->syntax t (syntax->datum #'id)))
             #'(begin)
             #'(begin e* ...)))])))

BTW, this is not a 100% correct definition of when-bound, but
it should suffice for given need.

Clarifications:

In R6RS, about datum->syntax, it says:

  (datum->syntax template-id datum )        procedure
  Template-id must be a template identifier and datum
  should be a datum value.

I have no idea what it means for an identifier to be a "template
identifier", so, I don't know if (car (generate-temporaries '(t)))
qualifies as one.  That might be a portability concern if some
implementation has a different interpretation of this undefined
term.

Also in R6RS:

  (generate-temporaries l)                 procedure
  [...] Each temporary is guaranteed to be unique,
  i.e., different from all other identifiers.

Here, R6RS does not explicitly require that temporaries have
empty environments associated with them, only that they are
"different" from other identifiers (which I take to mean that
they cannot be free-identifier=? or bound-identifier=? to any
other identifier).  Ikarus, Larceny, and PLT happen to produce
identifiers with an empty lexical environment, but this does
not seem to be a guaranteed behavior according to R6RS as far
as I can tell.

Aziz,,,

Reply via email to