tags:

views:

69

answers:

2

Given 2 lists, I want to ensure that they are the same size, I'm having a tough time with this code. Should I be using variables to do this?

(defun samesize (list1 list2)
  (cond (;logic here) T))
+1  A: 

You can use recursion if you want to implemet this yourself.

2 lists are the same size if they are both empty. They are different size if one is empty and the other is not. And if none of these is true, they are of the same size-comparison as those lists sans one element (i.e. their cdr-s)

DVK
I think you meant "i.e." not "e.g.". Your answer makes more sense if it's homework.
Jack Kelly
Yep, i.e. it is supposed to be. Fixed. And it does smell homeworkiyish to me :)
DVK
homeworkish? lol I guess, it's from work, code from a co-worker that i'm trying to learn lisp from. I don't have a good "primer"
Firoso
@Firoso: Implement @DVK's method then. It'll be more instructive than mine :-).
Jack Kelly
I was thinking that :-D
Firoso
+6  A: 

Both Common Lisp and elisp have length:

(defun samesize (list1 list2)
  (= (length list1) (length list2)))
Jack Kelly