Tharwat Posted November 21, 2013 Posted November 21, 2013 Does lambda need more than one argument. I keep getting an error that says there are too few arguments? Lambda is unnamed sub-function , so it can have as many argument as you want . Can you post the code that you work for that is related to lambda at least at the moment ? Quote
ksperopoulos Posted November 21, 2013 Author Posted November 21, 2013 Here is what I have so far. I am also not sure what the string "Abcd12345x7789Z" is for either. (defun c:insl ( / obj num) (vl-load-com) (setq obj (entget (car (entsel "\nSelect Object")))) (setq num (cdr (nth 18 obj))) (vl-string->list num) (vl-remove-if '(lambda (x) (not (member x '(46 48 49 50 51 52 53 54 55 56 57)) ) ) ) (vl-list->string "Abcd12345X7789wZ") (princ) ) Quote
Lee Mac Posted November 21, 2013 Posted November 21, 2013 Does lambda need more than one argument. I keep getting an error that says there are too few arguments? A lambda function is simply an anonymous function definition, an unnamed 'defun' - it will hence accept as many or as few arguments as it has been defined to accept. Here is an example of a lambda function accepting a single argument being evaluated by the vl-remove-if function: _$ (vl-remove-if '(lambda ( a ) (= 2 a)) '(0 1 2 3 4 5 6)) (0 1 3 4 5 6) Here is an example of a lambda function accepting two arguments being evaluated by the mapcar function: _$ (mapcar '(lambda ( a b ) (* a (1+ b))) '(1 2 3 4) '(5 6 7 ) (6 14 24 36) For more information on lambda, refer to my tutorial: Mapcar & Lambda Quote
Lee Mac Posted November 21, 2013 Posted November 21, 2013 Here is what I have so far. I am also not sure what the string "Abcd12345x7789Z" is for either. Hopefully these comments will point you in the right direction: (defun c:insl ( / obj num) (vl-load-com) (setq obj (entget (car (entsel "\nSelect Object")))) [color=green] ;; Be careful if the user does not select anything ;; as (entget nil) will error[/color] (setq num (cdr (nth 18 obj))) [color=green] ;; I recommend using ASSOC to retrieve a DXF pair, ;; as you cannot rely on the DXF pair being in the ;; same position in the DXF list for every obejct[/color] (vl-string->list num) [color=green] ;; This is redundant as you are not doing anything ;; with the value returned by the function[/color] [color=green] ;; I have formatted the following code so that you ;; can see the missing list argument:[/color] (vl-remove-if '(lambda (x) (not (member x '(46 48 49 50 51 52 53 54 55 56 57)) ) ) ) [color=green] ;; The following expression is also redundant as ;; you are not doing anything with the value returned.[/color] (vl-list->string "Abcd12345X7789wZ") (princ) ) Quote
ksperopoulos Posted November 21, 2013 Author Posted November 21, 2013 Lee Mac - (setq num (cdr (nth 18 obj))) [color=green] ;; I recommend using ASSOC to retrieve a DXF pair, ;; as you cannot rely on the DXF pair being in the ;; same position in the DXF list for every obejct[/color] I have to use this method due to multiple 300 dxf codes that are predetermined by the vertical AutoCad product I use. (vl-string->list num) [color=green] ;; This is redundant as you are not doing anything ;; with the value returned by the function[/color] Instead of this, would you recommend doing it this way? (setq num (vl-string->list (cdr (nth 18 obj))) [color=#008000] ;; I have formatted the following code so that you ;; can see the missing list argument:[/color] (vl-remove-if '(lambda (x) (not (member x '(46 48 49 50 51 52 53 54 55 56 57)) ) ) ) What you reformatted is exactly what I have in my code (see post #22). I am lost at this point. I have tried for hours now to figure this out with no luck at all. Quote
hmsilva Posted November 21, 2013 Posted November 21, 2013 Kyle, Lee was pointing your code redundancies... try this code (defun c:insl (/ obj num str) (vl-load-com) (setq obj (entget (car (entsel "\nSelect Object")))) (setq num (cdr (nth 18 obj))) (setq str (vl-list->string (vl-remove-if '(lambda (x) (not (member x '(46 48 49 50 51 52 53 54 55 56 57)) ) ) (vl-string->list num) ) ) ) (alert (strcat "Your number is \nstored at str variable \nand is : " str)) (princ) ) HTH Henrique Quote
ksperopoulos Posted November 22, 2013 Author Posted November 22, 2013 WOW! I was all sorts of messed up! I am still unclear how to use lambda, but I think the other stuff is making sense. I did have to make one revision to your code Henrique. I had to flip-flop the locations of (vl-list->string) and (vl-string->list) due to what was being returned. The value of the symbol "num" returns a string. I appreciate you and Lee (along with everyone else) trying to help me understand what is going on with the code. I am trying not to be one of those people who come on here and ask others to do their programming for them. Thanks a million! Quote
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.