|
 |
Nov 27, 2004, 01:37 AM
|
#1 (permalink)
|
|
DriverHeaven Extreme Member
Join Date: Jun 2004
Location: Floatin'...
Posts: 4,958
|
Anyone know LISP?
Is anyone here good at LISP? I got some homework due next tues and i haven't started it as yet mainly because i have absolutely no idea what to do. i am currently reading the lecture notes and i am completely lost. so can anyone help with my hw, please? not asking for someone to do it for me (althought that would be appreciated  ), but some help will do, if possible. Thanks...
link to hw assignment:
http://www.csee.umbc.edu/331/fall04/homework/hw9/
|
|
|
Nov 27, 2004, 11:41 AM
|
#2 (permalink)
|
|
Delete Me
Join Date: Mar 2004
Posts: 15,115
|
ewww 'Lost In Senseless Parenthesis'
if it isn't due for a while I can have ms. Vandevenne look at it monday, as she knows LISP
|
|
|
Nov 27, 2004, 03:56 PM
|
#3 (permalink)
|
|
DriverHeaven Extreme Member
Join Date: Jun 2004
Location: Floatin'...
Posts: 4,958
|
Quote:
|
Originally Posted by pr0digal jenius
ewww 'Lost In Senseless Parenthesis'
if it isn't due for a while I can have ms. Vandevenne look at it monday, as she knows LISP
|
well it's due next tues which is the 30th at 4 pm. if u get back to me
before that would be great, John. Thanks for helping... 
|
|
|
Nov 27, 2004, 11:56 PM
|
#4 (permalink)
|
|
Delete Me
Join Date: Mar 2004
Posts: 15,115
|
haha....can't help you then....as I won't see her until monday the 29th at 2pm and am busy all day monday 
|
|
|
Nov 28, 2004, 11:23 AM
|
#5 (permalink)
|
|
DriverHeaven Extreme Member
Join Date: Jun 2004
Location: Floatin'...
Posts: 4,958
|
Quote:
|
Originally Posted by pr0digal jenius
haha....can't help you then....as I won't see her until monday the 29th at 2pm and am busy all day monday 
|
oh darn... 
|
|
|
Nov 28, 2004, 05:03 PM
|
#6 (permalink)
|
|
Delete Me
Join Date: Mar 2004
Posts: 15,115
|
you want her email? 
|
|
|
Nov 28, 2004, 08:07 PM
|
#7 (permalink)
|
|
Your Inner Child
Join Date: Oct 2004
Location: NJ
Posts: 2,404
|
1. Look at the definition and usage of cons and list. You need to construct the lists in the first column using only cons for the second column and only list for the third column.
(a b c) for instance is (cons (cons (cons 'a nil) b) c) and (list 'a 'b 'c)
2. Look at the definition and usage of car and cdr. car returns the first element in a list and cdr returns the rest of the list. Play around in lisp with expressions like (car (list 'a 'b 'c)) and (cdr (list 'a 'b 'c)).
Everything else should be pretty standard assuming you already know how to program in some other language. It takes time to get used to programming and thinking in lisp, but you're only conquering a syntax hurdle.
|
|
|
Nov 29, 2004, 01:17 AM
|
#8 (permalink)
|
|
DriverHeaven Extreme Member
Join Date: Jun 2004
Location: Floatin'...
Posts: 4,958
|
thanks for the help, andrew. it seems to figure out #1 and #2 is by trial and error. try different expressions until i get it right. must be a better way of figuring out these things. anyways i managed to figure out the first 2 rows of #1 by pure luck. one answer troubles me though, it's for (a b c). for the cons i put : (cons ‘a ‘(b c) ). is this a possible answer or is the answer u provided the only one? thanks again, andrew...
|
|
|
Nov 29, 2004, 07:39 AM
|
#9 (permalink)
|
|
Your Inner Child
Join Date: Oct 2004
Location: NJ
Posts: 2,404
|
The instructions for number 1 dictate that you aren't allowed to use a quoted list.
|
|
|
Nov 29, 2004, 11:14 AM
|
#10 (permalink)
|
|
DriverHeaven Extreme Member
Join Date: Jun 2004
Location: Floatin'...
Posts: 4,958
|
ok. btw, i checked and ur suggestion for (a b c) for the cons was wrong. it's (cons 'a (cons 'b (cons 'c nil))).
|
|
|
Nov 29, 2004, 03:18 PM
|
#11 (permalink)
|
|
Your Inner Child
Join Date: Oct 2004
Location: NJ
Posts: 2,404
|
Sorry looks like I forgot the single quots before b and c, so it thought they were variable names. Try what I had before but with 'b and 'c. If it still doesn't work, then there's something special about cons in lisp that I don't know about and doesn't exist in scheme.
I really know scheme and not lisp, but they're pretty similar.
|
|
|
Nov 29, 2004, 05:45 PM
|
#12 (permalink)
|
|
Your Inner Child
Join Date: Oct 2004
Location: NJ
Posts: 2,404
|
as per your IM:
nil is an empty list. ()
cons joins an element with a list. (cons element list). This may be why mine didn't work before I was doing (cons list element). Anyway, (cons 'a nil) will be the element 'a added to the nil list. You get (a). (cons 'a (cons 'b nil)) is tricky. Work inside out just like in algebra. First (cons 'b nil) is (b). now we have (cons 'a (b)) which is (a b). If we wanted to get mor confused we could do (cons (cons 'a nil) (cons 'b nil)). That breaks to (cons (a) (b)) and should give the list ((a) b). I think you need (cons (cons 'a nil) (cons (cons 'b nil) nil)) to get ((a) (b)). Play around with it.
list is a little different, you specify all the elements of the list in the declaration. (list element1 element2 element3 ...). So (list a b c) is (a b c) and (list (list a) (list b)) is (list (a) (b)) is ((a) (b)).
When working in Lisp you need to be able to get your bearings straight when surrounded by parenthesis. Think of the algebraic equation (4 + (2 * (4 + 7 + (2 - 6) * (2 + 4)))). You'd solve that the same way you go about working in lisp. From the inside out.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|