[plt-scheme] kids, worlds and functional updates
I'm playing around with the universe teachpack, and am curious whether
anyone has thoughts about how to make the coding of worlds reasonably easy
and intuitive for kids. I've been playing around with structuring worlds as
structs. The issue then becomes how to make modifications to a world in a
clean way. What seems most natural to me is to use some kind of functional
update to change individual fields. So, for a simple world consisting of a
position and velocity:
;; world type
(define-struct world (pos vel))
But then, I want a lightweight way of changing just the position or just the
velocity, so I write operations like this:
(define (set-world-pos world x)
(make-world x (world-vel world)))
(define (set-world-vel world x)
(make-world (world-pos world) x))
This is obviously somewhat brittle, since the code above will break if I add
a new field to the world struct.
So, there are really two questions. The first is, is there a better way of
doing this in the student-oriented languages. And second, is this a good
way of encouraging kids to write this kind of code? Or is the right thing
to have them recreate the entire struct from scratch every time they want to
modify a field.
y
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090926/60e3ab96/attachment.html>