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

Pages: 1-

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 2008-01-07 8:11

read SICP.

Name: Anonymous 2008-01-07 8:16

>>2
I have re-read SICP, but was unable to find an answer

Name: Anonymous 2008-01-07 8:42

displayLisp (Cons car Nil) = ...
displayLisp (Cons car cdr@(Atom x)) = ...
displayLisp (Cons car cdr) = "(" ++ (displayLisp car) ++ " " ++ (displayLisp cdr)


... are left as an exercise for the reader.

Name: Anonymous 2008-01-07 8:42

>>2
DON'T HELP HIM

Name: Anonymous 2008-01-07 13:13

I came up with something!  If I use a different function for rendering cars and cdrs, perhaps it'll work!

Name: Anonymous 2008-01-07 13:53

This appears to pass all the test cases I have, comments?

displayLisp Nil = "NIL"
displayLisp (Atom x) = x
displayLisp (Cons car cdr) = "(" ++ (displayLisp car) ++ (displayCudder cdr)

displayCdr Nil = ")"
displayCdr (Atom x) = " . " ++ x ++ ")"
displayCdr (Cons car cdr) = " " ++ (displayLisp car) ++ (displayCudder cdr)

Name: Anonymous 2009-03-18 3:18

I feel the need, the need for weed!

Marijuana MUST be legalized.

Name: Trollbot9000 2009-07-01 11:14


Cons of light hope.

Name: Anonymous 2011-01-31 20:16

<-- check em dubz

Name: Anonymous 2011-02-03 5:48

Name: Anonymous 2012-01-04 21:14

>>11
COOL DUBZ, BRO

Name: Anonymous 2012-01-05 0:19

>>1
Haskell
There's your problem.

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