Page 1 of 1

Comparing lists' values

Posted: Tue Sep 13, 2011 8:57 pm
by dthreatz
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
	)
)

Re: Comparing lists' values

Posted: Wed Sep 14, 2011 2:23 pm
by nuntius
Try printing the values you are comparing.

Re: Comparing lists' values

Posted: Wed Sep 14, 2011 3:21 pm
by dthreatz
I did and they are 5 and 2... so I don't understand why that error happens..

Re: Comparing lists' values

Posted: Wed Sep 14, 2011 4:45 pm
by Konfusius
(cdar L) returns (5), not 5. You have to use (cadar L).

Re: Comparing lists' values

Posted: Wed Sep 14, 2011 6:15 pm
by dthreatz
that error made me waste so much time until now, thanks!