[plt-scheme] FrTime implementation

From: Gregory Cooper (greg at cs.brown.edu)
Date: Sat Dec 8 22:52:07 EST 2007

Hi Dave,

It looks like you have the right idea.  :-)

Are you running a pre-v371 version of DrScheme / FrTime?  (From the
code and description you give, it sounds like you are...)  I ask
because around July I changed the way FrTime deals with lists and
other data structures, and this change makes it a bit more complicated
to lift over data structures containing behaviors.

In pre-v371, all data constructors (including "cons") are lifted, so
any reactivity inside a data structure spreads to the structure
itself.  When you lift a procedure over a reactive structure, the
procedure gets called repeatedly with snapshots of the structure
(computed each time anything inside the structure changes).  This is
why the second (make-torus ...) gets redrawn every millisecond, even
though it only changes once a second: draw-list processes the entire
list whenever anything inside it changes.

In v371 and later, data constructors are not lifted, so behaviors can
hide inside structures.  In order to lift over such structures, you'll
first need to use "raise-reactivity" to make the reactivity spread to
the top of the structure, or use "compound-lift" (like the new
animation.ss does), which lets your procedure find the reactivity
while traversing the structure.  (This avoids the work of constructing
a deep snapshot each time something changes.)  If you decide to
upgrade to v371 at some point, let me know and I'll be happy to help
explain this.

A couple of small comments: I'm surprised that you don't have code to
clear the buffer before rendering the list of shapes, like
animation.ss does.  Also, I'm not sure why you don't just write:

  (define clock milliseconds)

Please let me know if you have any more questions or run into any
difficulties using FrTime.

Cheers,
Greg

On Dec 8, 2007 7:38 AM, Dave Griffiths <dave at pawfal.org> wrote:
> On Mon, 2007-12-03 at 13:45 -0500, Matt Jadud wrote:
> > Hi Dave, Greg,
> >
> > On Dec 3, 2007 11:28 AM, Gregory Cooper <greg at cs.brown.edu> wrote:
> > > If you want to talk in more detail about the interface you're looking
> > > to define and how best to use FrTime, feel free to contact me
> > > directly.
> >
> > I'm on both the Fluxus and PLT Scheme lists, because... well, Fluxus
> > represents a very cool environment built on top of my favorite Scheme.
> > And someday, I hope to have the free time to 1) seriously play with
> > Fluxus, and 2) teach a course where Fluxus plays a critical part,
> > perhaps in conjunction with some cool peeps in a music department.
> >
> > That said, if the conversation about lifting an existing, substantial
> > project into a functional reactive paradigm in PLT Scheme could happen
> > in the open, I think that would be great.  There would be much to be
> > learned just by being able to follow the conversation.
>
> Thanks guys, I have something rudimentary working - but I still don't
> really understand enough about the basics, so I'm going to read up on it
> a little.
>
> As I'm going to have to hide all the statefulness of the game engine
> (which is partly the point) I think it's going to be best to figure out
> a new interface for doing this. At the moment it's very much based on
> animation.ss (some code below). One odd thing I notice is that the
> second make-torus gets called every millisecond even though it's only
> dependant on seconds. Not a big deal - but is this something I'm doing
> wrong?
>
>
> (module frflux (lib "frtime.ss" "frtime")
>   (require  (lib "match.ss")
>             (as-is:unchecked (lib "lang-ext.ss" "frtime") lift)
>             (lib "class.ss")
>             (lib "list.ss" "frtime")
>             (lib "etc.ss" "frtime")
>             (lib "math.ss" "frtime")
>             (lib "mzscheme-core.ss" "frtime")
>             (prefix flx: (lib "drflux.ss" "fluxus-0.14")))
>
>   (provide
>    display-shapes
>    make-cube
>    make-torus
>    (all-from (lib "drflux.ss" "fluxus-0.14"))
>    (all-from (lib "mzscheme-core.ss" "frtime")))
>
>   (define-struct cube (tr rt sc col))
>   (define-struct torus (tr rt sc col))
>
>   (define (draw-list a-los)
>     (for-each
>      (match-lambda
>        (($ cube tr rt sc col)
>         (flx:with-state
>          (flx:translate tr)
>          (flx:rotate rt)
>          (flx:scale sc)
>          (flx:colour col)
>          (flx:draw-cube)))
>        (($ torus tr rt sc col)
>         (flx:with-state
>          (flx:translate tr)
>          (flx:rotate rt)
>          (flx:scale sc)
>          (flx:colour col)
>          (flx:draw-torus)))
>        [(? undefined?) (void)]
>        [(? list? x) (draw-list x)]
>        [(? void?) (void)])
>      a-los))
>
>   (define (top-level-draw-list a-los)
>     (draw-list a-los))
>
>   (define l (new-cell empty))
>
>   (define (display-shapes x)
>     (set-cell! l x))
>
>   (define d (lift #t top-level-draw-list l))
>
>   )
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> (require frflux)
>
> (define clock (* milliseconds 1))
>
> (display-shapes
> (list
>   (make-cube
>    (vector 0 0 0)
>    (vector (* 0.1 (modulo clock 3600))
>            (* 0.23 (modulo clock 3600))
>            (* 0.4 (modulo clock 3600)))
>    (vector 1 5 1)
>    (vector 1 1 0))
>
>   (make-torus
>    (vector 0 0 0)
>    (vector (* 0.1 (modulo clock 3600))
>            (* 0.2 (modulo clock 3600))
>            (* 0.4 (modulo clock 3600)))
>    (vector 2 2 2)
>    (vector 0 1 1))
>
>   (make-torus
>    (vector 4 0 0)
>    (vector 0 (* 10 (modulo seconds 100)) 0)
>    (vector 1 1 1)
>    (vector 1 1 1))
>
>   ))
>
>
>


Posted on the users mailing list.