[plt-scheme] FrTime implementation

From: Dave Griffiths (dave at pawfal.org)
Date: Tue Jan 8 04:40:57 EST 2008

Hi Greg,

Sorry for the delay, I seem to be trying to do too many things at once...

I've updated to the 372 version of frtime, and I've put together the
minimum I think is needed to play with the implementation of animation.ss.
So, a few questions have arisen :)

Firstly, I still seem to be getting the case where both time behavours are
expressed at the same rate - i.e. in the example below the action given
the seconds is called as many times as the milliseconds one, implying that
my list is not created properly.

Also, I just wondered what vn is - the argument to the procedure given to
compound lift. As it's used to get the values from the behaviours, I'm
guessing it's the all important procedure which actually expresses the
lifting? Why does it also need to be called on each of the elements of the
draw list?

Do the calls inside the draw list procedure which do the actual work have
to be lifted (printf in this case) is it enough to just use v-n to extract
the value from the behaviour? I've had some unpredicable behavour when
I've used procedures from my binary extensions here, but I'm probably
missing something simple.

My code:

(module frtest (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")
           (rename mzscheme mz:define-struct define-struct))

  (provide
   display-shapes
   (lifted make-a make-b))

  (define-struct a (x))
  (define-struct b (x))

  (define l (new-cell empty))

  (define (display-shapes x)
    (set-cell! l x))

  (define (top-level-draw-list a-los)
    (compound-lift
     (lambda (vn)
       (draw-list a-los vn))))

  (define (my-for-each proc lst v-n)
    (let ([lst (v-n lst)])
      (if (empty? lst)
          (void)
          (begin
            (proc (v-n (first lst)))
            (my-for-each proc (rest lst) v-n)))))

  (define (draw-list a-los v-n)
    (let loop ([a-los a-los])
      (my-for-each
       (lambda (v)
         (match (v-n v)
           [(? undefined?) (void)]
           [($ a x)
            (printf "a ~a~n" (v-n x))]
           [($ b x)
            (printf "b ~a~n" (v-n x))]
           [(? list? x) (loop (v-n x))]
           [(? void?) (void)]))
       a-los v-n)))

  (define d (top-level-draw-list l))

  )

(require frtest)

(display-shapes
(list
  (make-a seconds)
  (make-b milliseconds)
  ))



On Sat, 2007-12-08 at 22:52 -0500, Gregory Cooper wrote:
> 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




Posted on the users mailing list.