Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

need help with this cudder

Name: Anonymous 2008-01-07 8:03

Okay, I have this data structure (Haskell):
data Lisp = Nil | Atom String | Cons Lisp Lisp
I'm trying to write a function for correctly rendering the data... however, I cannot figure out how to... I have re-read SICP, but was unable to find an answer, I also re-read McCarthy's paper, which didn't help either.  This is what I have so far:
displayLisp Nil = "()" -- this doesn't matter so much, could be #nil or NIL something
displayLisp (Atom x) = x
displayLisp (Cons car cdr) = "(" ++ (displayLisp car) ++ " . " ++ (displayLisp cdr) ++ ")"

Now what to do about lists?  I know there's a list when the final cdr is NIL, but... hmm.  And also, I think you can have lists where the final element is not NIL as well (is that so?).

I can parse no problem (well, a little, I'm forced to omit the spaces around the . in the conses to avoid some ambiguity) -- lists, conses, etc.

Please help me Sussman!

Name: Anonymous 2011-01-31 20:16

<-- check em dubz

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List