Name: Anonymous 2008-01-07 8:03
Okay, I have this data structure (Haskell):
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:
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!
data Lisp = Nil | Atom String | Cons Lisp LispI'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!