[plt-scheme] Using student-defined structures in a teachpack

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Sun Dec 11 02:15:10 EST 2005

On 12/11/05, Mike Burns <mike at mike-burns.com> wrote:
> Shouldn't work on capital-p-Point, or with fields a and b, but a third field
> shouldn't be a problem.

How would you expect it to behave in the failure cases?  Because some
students will do things like that, and the code has to do something in
their case, and what it does will have a major impact on how quickly
they figure out their error.

> > To do any of this, you would have to redefine define-struct (or define
> > an alternate define-struct-like form).
> Excellent, I'll look into that.

To be honest, I meant that as an explanation of the technical
difficulty of what you presented, not a suggestion.  First of all, you
can't redefine how define-struct works in a given language, only
provide a different definition to a new langauge or provide a similar
macro with a different name (define-type instead of define-struct or
something).  Second, changing how a fundamental coding tool works
undermines all the time spent teaching students that all data
definitions work uniformly and predictably.

> I'm actually wrapping functions which take Posns. The idea was to have the
> student create her own data structure but have it play nicely with the rest
> of the system, giving them quick satisfaction. The problem they need to
> solve is something like:
>   We've been dealing with single values, but to play Battleship we need two
>   numbers. Once you have a way of representing two numbers then we can play
>   Battleship.
> You do raise good points; maybe we'll just use Posns instead.

This seems like a very bizarre thing to ask them to do.  It has
nothing to do with any coding practice anyone will have to do - you
never have to write a data definition with the requirement that it fit
code already written based on assumptions about it.  Perfectly valid
solutions (changes in structure or field name, or reversed field
order) will yield errors instead of working.

Basically, I don't see much sense in providing code for nonexistent
datatypes.  Either provide the datatype too, or make the student write
the code after they define the type.

Posted on the users mailing list.