Re: [racket-users] How to dynamically generate top-level procedures?

2016-08-10 Thread David Storrs
Yes. Yes, that exactly solves my problem. *sheepish look* Thanks. On Tue, Aug 9, 2016 at 8:47 PM, Matthew Butterick wrote: > > On Aug 9, 2016, at 7:52 PM, David Storrs wrote: > > > This solves the problem of creating top-level bindings at run time

Re: [racket-users] How to dynamically generate top-level procedures?

2016-08-09 Thread Matthew Butterick
On Aug 9, 2016, at 7:52 PM, David Storrs wrote: > 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? The code generated by a macro

Re: [racket-users] How to dynamically generate top-level procedures?

2016-08-09 Thread David Storrs
On Tue, Aug 9, 2016 at 2:20 PM, John Clements 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,

Re: [racket-users] How to dynamically generate top-level procedures?

2016-08-09 Thread David Storrs
On Tue, Aug 9, 2016 at 2:35 PM, Ben Greenman wrote: > Here's something in the ballpark. > > #lang racket > > (define-namespace-anchor nsa) > (define ns (namespace-anchor->namespace nsa)) > > (let ((xyz 1)) > (for ((name '(x y z))) >

Re: [racket-users] How to dynamically generate top-level procedures?

2016-08-09 Thread Ben Greenman
Here's something in the ballpark. #lang racket (define-namespace-anchor nsa) (define ns (namespace-anchor->namespace nsa)) (let ((xyz 1)) (for ((name '(x y z))) (namespace-set-variable-value! name (lambda () (displayln (format "~a: ~a" name xyz)) (set! xyz (add1 xyz))) #f ns))) (eval

Re: [racket-users] How to dynamically generate top-level procedures?

2016-08-09 Thread 'John Clements' via Racket Users
> On Aug 9, 2016, at 4:46 PM, David Storrs wrote: > > In Perl it's possible to generate main-namespace functions like so: > > perl -E 'my $z = 1; for (qw/foo bar baz/) {my $x = $_; *$_ = sub{ say "$x: ", > $z++ }}; foo(); bar(); baz();' > > This outputs: > foo: 1 >

[racket-users] How to dynamically generate top-level procedures?

2016-08-09 Thread David Storrs
In Perl it's possible to generate main-namespace functions like so: perl -E 'my $z = 1; for (qw/foo bar baz/) {my $x = $_; *$_ = sub{ say "$x: ", $z++ }}; foo(); bar(); baz();' This outputs: foo: 1 bar: 2 baz: 3 Note that it is generating top-level subroutines that can be called from