MAPCAR-LAMBDA problem
helloi wrote something like this. it reads line from file and split it into 3:
(defun C:TEST (/ FL) (setq FL (getfiled "SelectFile" "*." "txt" ) (princ (kr:SplitList (kr:ReadFile FL))) (princ))(defun kr:ReadFile (File / OFL L LST) (if (findfile File) (if (setq OFL (open File "r")) (progn (setq L "") (while (/= L :EOF) (setq LST (cons (setq L (read-line OFL)) LST)) ) (close OFL) (reverse (cdr LST)) ) ) (alert (strcat "Can't find file " File ".")) ))(defun kr:SplitList (In / LST) (foreach % In (setq LST (cons (list (substr % 1 10) (substr % 10 16) (substr % 26 5) ) LST ) ) ) LST)everything works ok but i want practice mapcar-lambda function so i try to rewrite SplitList function. it is working but returns wrong list. code below
(defun kr:SplitList2 (In / LST 3L) (mapcar'(lambda (%) (setq LST (cons (mapcar '(lambda (%1) (setq 3L (append 3L (list (substr % (car %1) (last %1))))) ) (list '(1 10) '(10 16) '(26 5)) ) LST ) ) ) In ) LST)can someone help with this?
thanks
kruuger (defun kr:SplitList2 (In / LST 3L) (mapcar'(lambda (%) (setq LST (cons (mapcar '(lambda (%1) (setq 3L(substr % (car %1) (last %1))) ) (list '(1 10) '(10 16) '(26 5)) ) LST ) ) ) In ) LST)
(append 3L (listno need because mapcar creates list by himself. And without extra variables:
(defun kr:SplitList3 (In) (mapcar'(lambda (%) (list (mapcar '(lambda (%1) (substr % (car %1) (last %1)) ) (list '(1 10) '(10 16) '(26 5)) ) ) ) In ))
Beauty:) Thanks Smirnoff
like this is perfect:
(defun kr:SplitList3 (In) (mapcar'(lambda (%) (mapcar '(lambda (%1) (substr % (car %1) (last %1)) ) (list '(1 10) '(10 16) '(26 5)) ) ) In ))kruuger
页:
[1]