[racket] Programmatically start a big-bang?

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Sun Apr 21 11:17:18 EDT 2013

On Sun, Apr 21, 2013 at 11:11 AM, Robby Findler
<robby at eecs.northwestern.edu> wrote:
> One way is to just write:
>
> (define (my-big-bang ht) (big-bang [on-tick (hash-ref ht 'on-tick)]
> ...etcetcetc...))
>
> and you'd be duplicating the default values but maybe that's enough to get
> going for now?

This is what I would suggest as well, and it's what we do in our
class-based version of big-bang:
https://github.com/dvanhorn/dpc/blob/master/class/universe.rkt

There are a couple complications with this that you should know about:

1. The presence of a register clause changes the whole behavior of the
system, and as far as we could tell, the only way to address this is
the code duplication you see in that file.
2. Some other clauses (like stop-when) don't have easy defaults. I
think the values we provide there should be sufficient for your
purposes though.

Sam

> On Sun, Apr 21, 2013 at 10:04 AM, Joe Gibbs Politz <joe at cs.brown.edu> wrote:
>>
>> I'd like to write a library function that takes a hash table of
>> handlers and starts a running world in big-bang style, for example:
>>
>> (my-big-bang
>>  0
>>  (make-immutable-hash
>>   `((on-tick . ,add1)
>>     (stop-when . ,(lambda (x) (> x 100))))))
>>
>> Is there an interface that I could use to write this?  I suppose I
>> could try to generate a syntax object containing an appropriate
>> big-bang and eval it, but that seems like a big hammer to wield here.
>> I've poked around a little bit in 2htdp/ but haven't found anything
>> provided that seems to fit the bill.
>>
>> Motivation: I want to support big-bang in a language that doesn't
>> support macros (yet), and I don't want to add special-case syntax for
>> big-bang.  I'd like the usage in that language (Pyret, which has
>> Python-like syntax) to look like:
>>
>> big-bang(init, {
>>   event_name: event_handler,
>>   ...
>> })
>>
>> Which calls something like `my-big-bang` under the hood.
>>
>> Thanks!
>> Joe
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users
>
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>

Posted on the users mailing list.