[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: functional programming is great, but why lists?



If the goals of this list aren't to discuss pedagogical aspects of
scheme, what are the goals? I feel like Bill has been responded to in
an unduly harsh manner for asking a question about some of the
fundamentals of scheme.


| "Why are we using such a strange data structure?  It takes a lotta
|  cleverness to get at the innards of a list (a (b (c (d)))), it'd be
|  easier with vectors (a, b, c, d).  Just reversing a list to get 
|  (d (c (b (a)))) is itself a recursive gem."

I'm not sure what is "strange" about cons as a data structure. It can
be thought of as a two-vector, and of course 2-vectors are sufficient,
when chained together, to form vectors of arbitrary length. So it is
as about as basic data structure as they get.

On a picky note:
(reverse (a (b (c (d)))))      => ((b (c (d))) a) 
(deep-reverse (a (b (c (d))))) => ((((d) c) b) a)

I recommend, if you don't see that right away, that you draw some box
diagrams of this structure and convince yourself of that. Note that
although (a b c d) could be represented readily by a 4-vector (or 4
2-vectors), (a (b (c (d)))) is more complex, and actually needs 7
2-vectors (pairs) to represent it. Just out of curiousity, would you
still find nested vectors any easier to reverse than nested lists?

-bogo