0 Members and 1 Guest are viewing this topic.
(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))) ))
Hello,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))) ))Regards,
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.
Can we assume you want to assert the TYPE of the content of lists ; not that they evaluate to the same thing.
(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))) ))
(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))
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)) slowerOr (eval (list f l m)) more general
Or, since mapcar accepts multiple list arguments:
_$ (reduceKey 'maptree '+ '((1 (2 3)) (4 (5 6)) (7 (8 9))))(12 (15 18))