[plt-scheme] The role of proper and improper lists?
Good point,
and where structs are insufficient use objects.
what I struggle with is *when* to change from list to struct to object?
On 1/25/08, Aleks Bromfield <aleks at cs.brown.edu> wrote:
> On Thu, Jan 24, 2008 at 09:24:07PM -0600, Grant Rettke wrote:
> > Suppose you got a list of key-pair values. You could assemble it, for
> > example, in one of the two ways:
> >
> > (list (list 'a 1) (list 'b 2) (list 'b 3))
> >
> > or
> >
> > (list (cons 'a 1) (cons 'b 2) (cons 'c 3))
>
> Here's a third way:
>
> (define-struct kvpair (key value))
> (list (make-kvpair 'a 1) (make-kvpair 'b 2) (make-kvpair 'c 3))
>
> Lists hold an indefinite amount of homogeneous data; structs hold a fixed
> amount
> of heterogeneous data.
>
> It's possible to use Scheme lists as if they were structures, but it's not a
> good idea. The more structured your data is, the easier it is to work with,
> and
> the easier it will be to understand your code at a later point in time.
>
> As far as improper pairs go, avoid the temptation. It'll save you a bit of
> typing, but you're much better off defining a struct.
>
> ~ Aleks
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
--
Sent from Google Mail for mobile | mobile.google.com
Cheers,
Stephen
--
Stephen De Gabrielle
s.degabrielle at ucl.ac.uk
Telephone +44 (0)20 7679 5242 (x45242)
Mobile 079 851 890 45
Project: Making Sense of Information (MaSI)
http://www.uclic.ucl.ac.uk/annb/MaSI.html
UCLIC: University College London Interaction Centre
http://www.uclic.ucl.ac.uk/
Remax House - 31/32 Alfred Place
London - WC1E 7DP