(defun bv:scompare (a b)
(cond ((atom a) (atom b))
((atom b) nil)
((bv:scompare (car a) (car b)) (bv:scompare (cdr a) (cdr b)))
)
)
Regards,
Hello,I think we may already have our winner... Very good bruno_vdh!
My proposal for a similar structure...Code: [Select](defun bv:scompare (a b)
Regards,
(cond ((atom a) (atom b))
((atom b) nil)
((bv:scompare (car a) (car b)) (bv:scompare (cdr a) (cdr b)))
)
)
My proposal for a similar structure...Code: [Select](defun bv:scompare (a b)
(cond ((atom a) (atom b))
((atom b) nil)
((bv:scompare (car a) (car b)) (bv:scompare (cdr a) (cdr b)))
)
)
Incompatible with dotted pairs however, as a 'car/cdr' iterator must be used.Yes, dotted pairs with difficult to work differently
Can we assume you want to assert the TYPE of the content of lists ; not that they evaluate to the same thing.My variant for this hypothèse
(defun bv:compareStrTyp (a b)
(if (or (atom a) (atom b))
(eq (type a) (type b))
(and (bv:compareStrTyp (car a) (car b)) (bv:compareStrTyp (cdr a) (cdr b)))
)
)
Regards,(defun maptree (f l m)
(cond
((null l) nil)
((atom l) (apply f (list l m)))
((cons (maptree f (car l) (car m)) (maptree f (cdr l) (cdr m))))
)
)
_$ (maptree '+ (list 1 (list 2 3))(list 4 (list 5 6)))
(5 (7 9))
Regards,
Nice Lee, especially the second,
In the first beware of ((eval f) l m), it does not support special form.
I prefer (apply f (list l m)) slower
Or (eval (list f l m)) more general
Or, since mapcar accepts multiple list arguments:For the game, and not have to rewrite the function :wink:
_$ (reduceKey 'maptree '+ '((1 (2 3)) (4 (5 6)) (7 (8 9))))
(12 (15 18))
Regards,