[plt-scheme] syntax and promises and possibly phases

From: Neil W. Van Dyke (neil at neilvandyke.org)
Date: Sun May 18 12:07:30 EDT 2003

I suspect I'm blinded by the blindingly obvious this morning, but...

Is there a way to do the following with define-syntax?

I want to define a syntax extension "rx" that will make an expensive
computation "compile-rx" happen only once, so that:

    (define foo
      (lambda (...)
        ...
        (rx-match (rx "abc") ...)
        ...))

is equivalent to:

    (define foo
      (let ((rx-promise-1 (delay (compile-rx "abc"))))
        (lambda (...)
          ...
          (rx-match (force rx-promise-1) ...)
          ...)))

If this is possible, then I can make "rx-match" syntax that
automagically compiles regexps expressed as string literals only once
per syntactic occurrence.

This would really help code readability for the most common uses of
regexps, especially since one often needs to refer to regexp submatches.

(BTW, I'd rather not maintain a table mapping strings to compiled regexp
form, except perhaps as a complement to this syntax extension, since I'd
want to avoid a table lookup on each "rx-match" call anyway.)

(Also BTW, I'm not concerned with concurrency issues right now; I
suspect that's orthogonal to the syntax extension question.)

-- 
                                             http://www.neilvandyke.org/


Posted on the users mailing list.