[plt-scheme] Generating top-level definitions from inner syntax

From: Lauri Alanko (la at iki.fi)
Date: Wed Oct 8 17:02:03 EDT 2003

Here's something that would be very handy:

(module foo mzscheme
  ...
  (define (decimal? str)
    (pair? (match-optimized "-?[0-9]+" str)))
  ...
)

Would get transformed to:

(module foo mzscheme
  ...
  (define g125235 (regexp "-?[0-9]+"))
  (define (decimal? str)
    (pair? (regexp-match g125235 str)))
  ...
)

That is, I'd like an inner syntax to somehow introduce a top-level
definition to hoist a complex computation so that it only gets computed
once. Of course one can always use memoization, but it'd be nice to be
able to do this right.

Any suggestions on how something like this could be accomplished? I'd
prefer this sort of thing to be completely invisible to the user, but I
can see that maybe it requires either defining one's own language, or
embedding everything into a huge top-level macro that "grabs" the
generated extra variables from within...


Lauri Alanko
la at iki.fi


Posted on the users mailing list.