[plt-scheme] How to write and read structs? Follow-up and fun with modules

From: Phil Rand (philrand at gmail.com)
Date: Mon Oct 1 01:25:25 EDT 2007

> (provide (struct point (x y))
>           (all-from (lib "serialize.ss")))

I tried that in my real program, and had trouble.  I should have
immediately fallen back to simple test code, instead of calling for
help first.  Of course it works in the simple test.

> ...provides your struct and everything from serialize.ss.  The help
> desk can show you how to provide only what is needed from
> serialize.ss, if that is what you want.

Well, maybe if you're good at reading like a language-lawyer.  I find
a lot of the help desk prose very precise, but none too friendly.
More examples would help, along with some judicious use of bullet
lists and such to show structure.  My eyes glaze over too quickly.  I
wish I could use Safari or Firefox with the helpdesk, with larger
fonts one keystroke away, too.  Yes, I know about the preference
settings.  Sorry to whine.

> If it *can* be written as a functional program, it probably *should*
> be written that way:
>
> (define (points)
>    (map deserialize (with-input-from-file "test.txt" read)))
>
> In other words, let'ing and set'ing shouldn't be used to make the
> code harder ;)

Much nicer.  It's funny how I admire functional style when I see it,
but often slip back into my old ways, almost without noticing.

>
> > (map point? (points))
> >
> > The final (map point? (points)) returns (#t #t), so I claim success.
>
> That' not enough to verify success, though.  Texts like HtDP show how
> to make and verify examples as functions are developed.

Yes, I'd better add it to my reading list.  Reading it and doing what
it teaches are two different things of course.

Thanks for the help, Richard!

Phil


Posted on the users mailing list.