[plt-scheme] graphics states and Scheme

From: Dave Griffiths (dave at pawfal.org)
Date: Wed Jul 4 11:18:51 EDT 2007

> On 04/07/07, Dave Griffiths <dave at pawfal.org> wrote:
>> (push)                    ; push the state stack
>> (translate (vector 0 1 0)); move up in y axis by 1
>> (build-cube)              ; makes a red rotated cube, translated up by 1
>> (pop)                     ; pop the state stack
> <snip>
>> (grab mycube)             ; following commands now set to mycube's state
>> (rotate (vector 1 0 0))   ; rotate it a bit in the x axis
>> (ungrab)                  ; grabs can be nested
> First thing I did when I started using opengl in scheme was eliminate
> this sort of explicit parenthesizing. I found it really ugly, because
> if we are using these hordes of parentheses anyways, we may as well
> leverage them for all they're worth. Compare:
> (push)
> (translate (vector 0 1 0))
> (build-cube)
> (pop)
> vs.:
> (pushed
>   (translate (vector 0 1 0))
>   (build-cube))
> This also helps prevent problems which would be caused by unmatched
> push and pop calls. The indentation will also improve readability with
> nested calls. Just my $0.02. =)

I like this a lot - but the problem is that the scope of the state may not
coincide with the scope of the code. You sometimes need to push the stack,
go off and do something else, then pop from somewhere else again.

I was doing something like this when building L System structures from
string descriptions once (which contained codes for push and pop).

Maybe it's a Good Thing to be forced to match them up like this though,
I'll give it a try.



Posted on the users mailing list.