I have a little question about =REPEAT vs COND= Look at this LISP-monster: (setq rlst '()) (setq lst1 '(1.0 2.0 3.0 4.0)) (setq lst2 '(0.0 -1.5 -3.0 4.5 6.0)) (setq lst3 lst2);| helper list|; (repeat (length lst1) (repeat (length lst2) (setq rlst (append rlst (reverse (list (cons (car lst2) (list (car lst1))))) ) ) (setq lst2 (cdr lst2)) lst1 ) (setq lst2 lst3) (setq lst1 (cdr lst1)) rlst ) (print rlst) ; result list : ((0.0 1.0) (-1.5 1.0) (-3.0 1.0) (4.5 1.0) (6.0 1.0) (0.0 2.0) (-1.5 2.0) (-3.0 2.0) (4.5 2.0) (6.0 2.0) (0.0 3.0) (-1.5 3.0) (-3.0 3.0) (4.5 3.0) (6.0 3.0) (0.0 4.0) (-1.5 4.0) (-3.0 4.0) (4.5 4.0) (6.0 4.0)) Why can I substitute this expression for COND function like this: (defun VLF-APPEND-X-COORD (X LENGTH-LIST) (if (null LENGTH-LIST) nil (append (mapcar 'list (list X) LENGTH-LIST) (VLF-APPEND-X-COORD X (cdr LENGTH-LIST))))) ;Example: (setq X 3.0);|constant|; (setq LENGTH-LIST '(101 104 105 106)) (VLF-APPEND-X-COORD X LENGTH-LIST) ; result : ((3.0 101) (3.0 104) (3.0 105) (3.0 106))
Hi Fatty Monster substitute: Code: (defun MergeLists (Ls1 Ls2) (apply 'append (mapcar '(lambda (l1) (mapcar '(lambda (l2) (list l2 l1)) Ls2) ) Ls1 ) ) ) Call: (MergeLists '(1.0 2.0 3.0 4.0) '(0.0 -1.5 -3.0 4.5 6.0)) Returns: ((0.0 1.0) (-1.5 1.0) (-3.0 1.0) (4.5 1.0) (6.0 1.0) (0.0 2.0) (-1.5 2.0) (-3.0 2.0) (4.5 2.0) (6.0 2.0) (0.0 3.0) (-1.5 3.0) (-3.0 3.0) (4.5 3.0) (6.0 3.0) (0.0 4.0) (-1.5 4.0) (-3.0 4.0) (4.5 4.0) (6.0 4.0) ) I don't know what you wanna do with 'cond', but to get the same result like your sample use this: Code: (defun VLF-APPEND-X-COORD (Con Lst) (if Lst (mapcar '(lambda (l) (list Con l)) Lst)) ) Cheers
Thanks for your help, this is a lot nicer than my abrahcadabrah. I hope my programm will be operate trouble-free. Our routine need me to be construct a ground profile and water pipeline. Best regards, Fatty
Hi, Jurg! I'm understand your suggestion... Excuse me for my aplomb, next time I will be naming my functions "quietly". Thanks more. Apropos, on your site are excellent routines, to all intents and purposes efficiency. Best whishes and good luck, press Enter with care! Fatty. <>