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

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Oct 8 17:12:31 EDT 2003

On Oct  9, Lauri Alanko wrote:
> 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)))
>   ...
> )

If regexps is your only usage, then this is what #rx is for.
(BTW, "^-?[0-9]+$" is probably a better regexp for the above.)


> 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...

Yeah, I tried it once -- for regexps, but couldn't find any sane
solution either.  My solution was to have a `regexp*' macro that
expands to the regexp, which makes it uncompilable.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.