Comparing lists' values

Discussion of Common Lisp

Comparing lists' values

Postby dthreatz » Tue Sep 13, 2011 8:57 pm

Hello there, I'm new to Lisp and I would like to know why this doesnt work.
I have this list
Code: Select all
 (compare `((something 5) (qwer 3)) 2)


and im trying to compare the 5 with the 2, but I get this error
Error: (5) is not of type (OR RATIONAL FLOAT). Is there anyway I can compare these two values?
Code: Select all
(defun compare (L N)
   (if
      (> (cdr (car L)  N  ))
         T
   )
)
dthreatz
 
Posts: 3
Joined: Tue Sep 13, 2011 8:47 pm

Re: Comparing lists' values

Postby nuntius » Wed Sep 14, 2011 2:23 pm

Try printing the values you are comparing.
User avatar
nuntius
 
Posts: 500
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: Comparing lists' values

Postby dthreatz » Wed Sep 14, 2011 3:21 pm

I did and they are 5 and 2... so I don't understand why that error happens..
dthreatz
 
Posts: 3
Joined: Tue Sep 13, 2011 8:47 pm

Re: Comparing lists' values

Postby Konfusius » Wed Sep 14, 2011 4:45 pm

(cdar L) returns (5), not 5. You have to use (cadar L).
Konfusius
 
Posts: 62
Joined: Fri Jun 10, 2011 6:38 am

Re: Comparing lists' values

Postby dthreatz » Wed Sep 14, 2011 6:15 pm

that error made me waste so much time until now, thanks!
dthreatz
 
Posts: 3
Joined: Tue Sep 13, 2011 8:47 pm


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 5 guests