On Thursday, June 2, 2016 at 10:06:25 AM UTC-7, Matthew Butterick wrote:
> I have a solution to this problem — is it legit, or is there some slick 
> Rackety technique I'm missing?
> 
> I'm making a toy #lang interpreter for Basic, which allows variables to be 
> created with an assignment statement (like Python). The wrinkle in Basic is 
> that the execution order of the lines isn't known till runtime, so there's no 
> way to identify the "first" use of a variable and change it from a `set!` to 
> a `define` (e.g., by testing `identifier-binding`)
> 
> To fix this, I gather a list of variable identifiers from the parsed AST, 
> insert the `define`s at the top of the `#%module-begin`, and then the rest of 
> the AST, and the expander proceeds. That works.
> 
> But it seems like the gathering of variables should be able to happen as the 
> expander encounters them in the code (ie., do everything with one pass rather 
> than two). The problem is that by the time all the variables have been 
> discovered & gathered, the expansion is done, so AFAICT I can't go back and 
> `define` them retroactively.

I think you can do this by having your language provide it's own #%top syntax 
that defines what to do with unknown variables. 
http://docs.racket-lang.org/reference/__top.html?q=%24%25top#%28form._%28%28quote._~23~25kernel%29._~23~25top%29%29

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to