[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unhygienic macros



Given ARC-IF from my previous message, consider ARC-COND:

  (define-syntax (arc-cond expr)
    (syntax-case expr ()
      [(_)
       (syntax (void))]
      [(_ q0 a0 rest ...)
       (syntax (arc-if q0
                       a0
                       (arc-cond rest ...)))]))

With this, I can write

  (arc-cond 1 2) ==> 2
  (arc-cond #f 2
             3 4) ==> 4
  (arc-cond (+ 1 2) it  ;; IT captured by ARC-IF in exp'n of ARC-COND
            #f      4) ==> 3

For the IT capture to work correctly for ARC-COND, you need (syntax
test) rather than (syntax _) in the definition of ARC-IF.  (You
typically won't notice this difference from testing ARC-IF alone.)

By the way, I really don't like the use of the term "unhygienic macro"
in *this* context.  Even the very first paper on hygienic macros
observed the need for eluding the hygiene mechanism.  They provided a
fairly clunky first cut at defining such macros; Dybvig and others
have since greatly refined the mechanism.  But explicit capture is a
different concept entirely from truly unhygienic macros, which offer
no hygiene facility at all.  Let's keep the two separate.

Shriram