On Tue, Aug 9, 2016 at 2:20 PM, John Clements <[email protected]>
wrote:

>
> Racket is essentially a lexically scoped language. That is: it should be
> possible to look at a piece of code and figure out where the binding for a
> given variable is. It does have a dynamic binding mechanism, but the names
> that are bound dynamically … can be determined lexically.
>
> This might seem to prevent the kind of code that you’re talking about, but
> Racket compensates for this with an extraordinarily flexible macro system,
> and a very permissive notion of what exactly constitutes “compile-time.”
> It’s certainly possible to dynamically generate a piece of code using
> macros. Once generated, though, this piece of code is going to behave
> dependably.
>
> How does this affect your particular example? Well, it’s extremely easy to
> write a macro that does what you describe:
>
> #lang racket
>
> (define-syntax makefuns
>   (syntax-rules ()
>     [(_ name ...)
>      (begin (define name (lambda () (displayln "foo")))
>             ...)]))
>
> (makefuns x y z)
>
> (x)
>
> (y)
>
> (z)
>
>

This solves the problem of creating top-level bindings at run time (more or
less run time, anyway), but it doesn't handle the lexical closure part.  Is
there a way to do that?



> Hope this helps, apologies for telling you anything that you already knew.
>

I actually knew none of that, so I appreciate the telling. :>

Dave


>
> John
>
>
>

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