Shakto Posted October 20, 2014 Share Posted October 20, 2014 (edited) Hello, i've a question, i made 9 function (g1 g2 g3 m1 m2 m3 p1 p2 p3) I want to call each of them in a mapcar function, the 9 functions are into a list in arg of my function : Let see exemple of g1 (defun g1 (l) (if (eq (car l) 1) NIL (cons 1(cdr l)))) My list of function : (g1 g2 g3 m1 m2 m3 p1 p2 p3) When i want to call them for a value in that function, it's not working, someone can help me please ?) (defun newopen (felem lop) (mapcar (lambda (y) (y felem)) lop)) (newopen '(1 2 3) '(g1 g2 g3 m1 m2 m3 p1 p2 p3)) Edited October 21, 2014 by Shakto Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted October 21, 2014 Share Posted October 21, 2014 When i want to call them for a value in that function, it's not working, someone can help me please ?) (defun newopen (felem lop) (mapcar (lambda (y) (y felem)) lop)) (newopen '(1 2 3) '(g1 g2 g3 m1 m2 m3 p1 p2 p3)) hi shako, welcome to forum, read this 1st http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines maybe typo error ? lambda quote missing? [color="red"][b]'[/b][/color](lambda...) also if list= '(g1 g2 g3 m1 m2 m3 p1 p2 p3) ; you need, (([color="red"]eval[/color] y) felem) or just ([color="red"]list[/color] g1 g2 g3 m1 m2 m3 p1 p2 p3) we don't know how the rest functions g2 g3 m2...etc working or have bugs? Quote Link to comment Share on other sites More sharing options...
Shakto Posted October 21, 2014 Author Share Posted October 21, 2014 Didn't know about the eval function, still not working with the function newopen : (defun newopen (felem lop) (mapcar '(lambda (y) ((eval y) felem)) lop)) I have that bug error : FUNCALL : The argument (lambda y) ((eval y) felem)) isn't a function The others functions g1 g2 g3 etc... are working : (defun g1 (l) (if (eq (car l) 1) NIL (cons 1(cdr l)))) (defun g2 (l) (if (eq (car l) 2) NIL (cons 2(cdr l)))) (defun g3 (l) (if (eq (car l) 3) NIL (cons 3(cdr l)))) (defun m1 (l) (if (eq (car l) 1) NIL (if (eq (cadr l) 1) NIL (if (eq (car l) (cadr l)) NIL (cons (car l) (cons 1 (cddr l))))))) (defun m2 (l) (if (eq (car l) 2) NIL (if (eq (cadr l) 2) NIL (if (eq (car l) (cadr l)) NIL (cons (car l) (cons 2 (cddr l))))))) (defun m3 (l) (if (eq (car l) 3) NIL (if (eq (cadr l) 3) NIL (if (eq (car l) (cadr l)) NIL (cons (car l) (cons 3 (cddr l))))))) (defun p1 (l) (if (eq (car l) 1) NIL (if (eq (caddr l) 1) NIL (if (eq (car l) (caddr l)) NIL (if (eq (cadr l) (caddr l)) NIL (append (list(car l)) (list(cadr l)) (cons 1 ()))))))) (defun p2 (l) (if (eq (car l) 2) NIL (if (eq (caddr l) 2) NIL (if (eq (car l) (caddr l)) NIL (if (eq (cadr l) (caddr l)) NIL (append (list(car l)) (list(cadr l)) (cons 2 ()))))))) (defun p3 (l) (if (eq (car l) 3) NIL (if (eq (caddr l) 3) NIL (if (eq (car l) (caddr l)) NIL (if (eq (cadr l) (caddr l)) NIL (append (list(car l)) (list(cadr l)) (cons 3 ()))))))) Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted October 21, 2014 Share Posted October 21, 2014 without eval (defun newopen1 (felem lop) (mapcar '(lambda (y) ([color="red"]y[/color] felem)) lop)) (newopen1 '(1 2 3) ([color="blue"]list[/color] g1 g2 g3 m1 m2 m3 p1 p2 p3)) with eval: (defun newopen2 (felem lop) (mapcar '(lambda (y) (([color="blue"][b]eval[/b][/color] y) felem)) lop)) (newopen2 '(1 2 3) [color="red"][b]'[/b][/color](g1 g2 g3 m1 m2 m3 p1 p2 p3)) This may explain: QUOTE This is your return value? ;(nil (2 2 3) (3 2 3) nil nil (1 3 3) nil (1 2 2) nil) Quote Link to comment Share on other sites More sharing options...
Shakto Posted October 21, 2014 Author Share Posted October 21, 2014 Yes it's my return value. I have errors with both of your function : newopen1 => Error: The variable G1 is unbound. newopen2 => Argument to apply/funcall is not a function: (LAMBDA (Y) ((EVAL Y) FELEM)). Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted October 21, 2014 Share Posted October 21, 2014 Yes it's my return value. I have errors with both of your function : newopen1 => Error: The variable G1 is unbound. newopen2 => Argument to apply/funcall is not a function: (LAMBDA (Y) ((EVAL Y) FELEM)). maybe after version 2007 lambda needs to be optimized though without compile ?? (defun newopen2 (felem lop) (mapcar ([color="blue"]function[/color](lambda (y) ((eval y) felem))) lop)) (newopen2 '(3 2 1) '(g1 g2 g3 m1 m2 m3 p1 p2 p3)) ;((1 2 1) (2 2 1) nil (3 1 1) nil nil nil (3 2 2) nil) Quote Link to comment Share on other sites More sharing options...
Shakto Posted October 21, 2014 Author Share Posted October 21, 2014 Dunno Already tried that and it shows me : (eval y) must be a LAMBDA expression Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 21, 2014 Share Posted October 21, 2014 As hanhphuc has suggested, the following is correct: (defun newopen ( felem lop ) (mapcar '(lambda ( y ) ((eval y) felem)) lop)) In my testing: _$ (newopen '(1 2 3) '(g1 g2 g3 m1 m2 m3 p1 p2 p3)) (nil (2 2 3) (3 2 3) nil nil (1 3 3) nil (1 2 2) nil) What software/method are you using to evaluate your code? Are you entering the code at the AutoCAD 2014 command-line or in the VLIDE console? Quote Link to comment Share on other sites More sharing options...
Shakto Posted October 21, 2014 Author Share Posted October 21, 2014 I was using CLISP 2.49 on windows >. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 21, 2014 Share Posted October 21, 2014 I was using CLISP 2.49 on windows >. AutoLISP =/= Common LISP! Quote Link to comment Share on other sites More sharing options...
Shakto Posted October 21, 2014 Author Share Posted October 21, 2014 Damn, i wanted to try my program on CLISP before AutoCAD Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted October 25, 2014 Share Posted October 25, 2014 I was using CLISP 2.49 on windows >. just for info, all these return '(1) (cons 1 ()) ;<--- your code (cons 1 nil) (list 1) '(1) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.