[plt-scheme] continuing to write newbie notes on units; feedback?

From: Noel Welsh (noelwelsh at yahoo.com)
Date: Wed Jul 27 06:23:16 EDT 2005

--- Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:

> I'm about to start diving into the use of units in others
> parts of the PLT
> Scheme system, and would like some suggestions before I
> jump in too
> deeply.  I think the next part I'll need to cover is
> signed units, but
> we'll see... I want to jump into how units are applied in
> PLT Scheme as
> soon as I can.

I'm agreed signed units are the next logical step (well,
I've never used unsigned units...)  I typically use units
for two things:

  - servlets 

  - GUIs

Use in GUIs may be non-obvious.  The MVC pattern requires
the controller has access to the model, and the model has
access to the view.  As MrEd conflates the view and
controller into a single object mutual recursion is
necessary.  I imagine this could be solved using objects
but I think objects are a less elegant solution, and to be
truthful I don't much like the object system -- there's
just too much for me to cram into my little brain.  So I
have code such as:

(require (lib "class.ss")
         (lib "unitsig.ss")

(define-signature pacman^ (start))
(define pacman@
    (link (GUI : gui^ (gui@ MODEL))
          (MODEL : model^ (model@ GUI)))
    (export (var (GUI start)))))

(define-values/invoke-unit/sig pacman^

(send (start) show #t)

The start function is worth noting.  As in letrec the RHS
of units w/ mutual recursion must delay evaluation till
after initialisation of all bindings.  My initial version
of Pacman had initialisation expressions that depended on
values from the other unit; this failed as the values were
undefined at the time the expressions where evaluated.  If
that doesn't make sense I'll explain in more detail.


Email: noelwelsh <at> yahoo <dot> com   noel <at> untyped <dot> com
AIM: noelhwelsh
Blogs: http://monospaced.blogspot.com/  http://www.untyped.com/untyping/

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

Posted on the users mailing list.