Comparing lists' values

Discussion of Common Lisp
Post Reply
dthreatz
Posts: 3
Joined: Tue Sep 13, 2011 8:47 pm

Comparing lists' values

Post by 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
	)
)

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Comparing lists' values

Post by nuntius » Wed Sep 14, 2011 2:23 pm

Try printing the values you are comparing.

dthreatz
Posts: 3
Joined: Tue Sep 13, 2011 8:47 pm

Re: Comparing lists' values

Post by 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..

Konfusius
Posts: 62
Joined: Fri Jun 10, 2011 6:38 am

Re: Comparing lists' values

Post by Konfusius » Wed Sep 14, 2011 4:45 pm

(cdar L) returns (5), not 5. You have to use (cadar L).

dthreatz
Posts: 3
Joined: Tue Sep 13, 2011 8:47 pm

Re: Comparing lists' values

Post by dthreatz » Wed Sep 14, 2011 6:15 pm

that error made me waste so much time until now, thanks!

Post Reply