<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: pass a function to a function in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715738#M150419</link>
    <description>try:&lt;BR /&gt;
(setq lst '("hello" "4,4" "0.5"))&lt;BR /&gt;
(funt_1 lst)&lt;BR /&gt;
(funt_2 lst)</description>
    <pubDate>Tue, 25 Jul 2006 23:18:35 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2006-07-25T23:18:35Z</dc:date>
    <item>
      <title>pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715733#M150414</link>
      <description>I have some lines of code that will iterate through all layouts in a drawing.  I would like to make it into a function.  I want to pass it to another function as a parameter so that function will run on each layout as it iterates through.  Can you pass a function to another function?  Can you pass a function with parameters of its own?&lt;BR /&gt;
&lt;BR /&gt;
Here's the code.  Thanks for help...&lt;BR /&gt;
&lt;BR /&gt;
(setq IAcadDocument (vla-get-ActiveDocument (vlax-get-Acad-Object))&lt;BR /&gt;
        IAcadLayouts (vla-get-Layouts IAcadDocument)&lt;BR /&gt;
        IActiveLayout (vla-get-ActiveLayout IAcadDocument)&lt;BR /&gt;
        ) ;_ setq&lt;BR /&gt;
  (vlax-for IAcadLayout IAcadLayouts&lt;BR /&gt;
    (if (not (wcmatch (vla-get-name IAcadLayout) "Model"))&lt;BR /&gt;
      (progn&lt;BR /&gt;
        (print (vla-get-Name IAcadLayout))&lt;BR /&gt;
        (vla-put-ActiveLayout IAcadDocument IAcadLayout)&lt;BR /&gt;
        ;;;place function to be ran on each layout here;;&lt;BR /&gt;
        (MyFunc)&lt;BR /&gt;
        &lt;BR /&gt;
        ;(print (append (getvar "LIMMIN") (getvar "LIMMAX")))&lt;BR /&gt;
        )&lt;BR /&gt;
      )&lt;BR /&gt;
    ) ;_ vlax-for&lt;BR /&gt;
  (vla-put-ActiveLayout IAcadDocument IActiveLayout)&lt;BR /&gt;
  ;(textscr)&lt;BR /&gt;
  (princ)</description>
      <pubDate>Tue, 25 Jul 2006 21:46:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715733#M150414</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-25T21:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715734#M150415</link>
      <description>I don't have the specifics, but I would think you could pass the function &lt;BR /&gt;
name as a string, then using the READ (maybe not that one) function actually &lt;BR /&gt;
call it.&lt;BR /&gt;
&lt;BR /&gt;
I'm not the best person to respond, but thought I'd throw an idea at you.  I &lt;BR /&gt;
seem to remember doing something similar, but that was waaaay too long ago &lt;BR /&gt;
for me to remember specifics.&lt;BR /&gt;
&lt;BR /&gt;
&lt;JASON roper=""&gt; wrote in message news:5248241@discussion.autodesk.com...&lt;BR /&gt;
I have some lines of code that will iterate through all layouts in a &lt;BR /&gt;
drawing.  I would like to make it into a function.  I want to pass it to &lt;BR /&gt;
another function as a parameter so that function will run on each layout as &lt;BR /&gt;
it iterates through.  Can you pass a function to another function?  Can you &lt;BR /&gt;
pass a function with parameters of its own?&lt;BR /&gt;
&lt;BR /&gt;
Here's the code.  Thanks for help...&lt;BR /&gt;
&lt;BR /&gt;
(setq IAcadDocument (vla-get-ActiveDocument (vlax-get-Acad-Object))&lt;BR /&gt;
        IAcadLayouts (vla-get-Layouts IAcadDocument)&lt;BR /&gt;
        IActiveLayout (vla-get-ActiveLayout IAcadDocument)&lt;BR /&gt;
        ) ;_ setq&lt;BR /&gt;
  (vlax-for IAcadLayout IAcadLayouts&lt;BR /&gt;
    (if (not (wcmatch (vla-get-name IAcadLayout) "Model"))&lt;BR /&gt;
      (progn&lt;BR /&gt;
        (print (vla-get-Name IAcadLayout))&lt;BR /&gt;
        (vla-put-ActiveLayout IAcadDocument IAcadLayout)&lt;BR /&gt;
        ;;;place function to be ran on each layout here;;&lt;BR /&gt;
        (MyFunc)&lt;BR /&gt;
&lt;BR /&gt;
        ;(print (append (getvar "LIMMIN") (getvar "LIMMAX")))&lt;BR /&gt;
        )&lt;BR /&gt;
      )&lt;BR /&gt;
    ) ;_ vlax-for&lt;BR /&gt;
  (vla-put-ActiveLayout IAcadDocument IActiveLayout)&lt;BR /&gt;
  ;(textscr)&lt;BR /&gt;
  (princ)&lt;/JASON&gt;</description>
      <pubDate>Tue, 25 Jul 2006 22:04:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715734#M150415</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-25T22:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715735#M150416</link>
      <description>In second function.. just call the function you want.&lt;BR /&gt;
e..g.&lt;BR /&gt;
&lt;BR /&gt;
(defun 2nd_fun ()&lt;BR /&gt;
 (do_first_fun)&lt;BR /&gt;
)</description>
      <pubDate>Tue, 25 Jul 2006 22:07:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715735#M150416</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-25T22:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715736#M150417</link>
      <description>Or, pass it a number..&lt;BR /&gt;
e.g.&lt;BR /&gt;
(defun 2nd_fun (fun_num)&lt;BR /&gt;
(if (= fun_num 1)(do_first_fun))&lt;BR /&gt;
(if (= fun_num 2)(do_next_fun))&lt;BR /&gt;
) &lt;BR /&gt;
&lt;BR /&gt;
Bob</description>
      <pubDate>Tue, 25 Jul 2006 22:15:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715736#M150417</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-25T22:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715737#M150418</link>
      <description>Thanks for the quick responses.  I forgot you can pass a regular function to another function with no problem.  It's where I pass another function with parameters of its own that I have trouble.  Like, say I have these two functions...&lt;BR /&gt;
&lt;BR /&gt;
(defun Func1 ()&lt;BR /&gt;
  (command "text" "4,4" "0.2" "0" "hello")&lt;BR /&gt;
  )&lt;BR /&gt;
&lt;BR /&gt;
(defun Func2 (text inspnt hght)&lt;BR /&gt;
  (command "text" inspnt hght "0" text)&lt;BR /&gt;
  )&lt;BR /&gt;
&lt;BR /&gt;
Now, I can pass Func1 to my LayoutIterate function.&lt;BR /&gt;
&lt;BR /&gt;
(LayoutIterate Func1)&lt;BR /&gt;
&lt;BR /&gt;
But I can't pass Func2 because it has parameters&lt;BR /&gt;
&lt;BR /&gt;
(LayoutIterate (Func2 "hello" "4,4" "0.5"))&lt;BR /&gt;
&lt;BR /&gt;
Not sure how to go about this.  Like Tom D said, it might work with something like READ or EVAL.  Or maybe my whole approach is  wrong.</description>
      <pubDate>Tue, 25 Jul 2006 23:00:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715737#M150418</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-25T23:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715738#M150419</link>
      <description>try:&lt;BR /&gt;
(setq lst '("hello" "4,4" "0.5"))&lt;BR /&gt;
(funt_1 lst)&lt;BR /&gt;
(funt_2 lst)</description>
      <pubDate>Tue, 25 Jul 2006 23:18:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715738#M150419</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-25T23:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715739#M150420</link>
      <description>Jason Roper wrote:&lt;BR /&gt;
&amp;gt; Thanks for the quick responses.  I forgot you can pass a regular function to another function with no problem.  It's where I pass another function with parameters of its own that I have trouble.  Like, say I have these two functions...&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; (defun Func1 ()&lt;BR /&gt;
&amp;gt;   (command "text" "4,4" "0.2" "0" "hello")&lt;BR /&gt;
&amp;gt;   )&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; (defun Func2 (text inspnt hght)&lt;BR /&gt;
&amp;gt;   (command "text" inspnt hght "0" text)&lt;BR /&gt;
&amp;gt;   )&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Now, I can pass Func1 to my LayoutIterate function.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; (LayoutIterate Func1)&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; But I can't pass Func2 because it has parameters&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; (LayoutIterate (Func2 "hello" "4,4" "0.5"))&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Not sure how to go about this.  Like Tom D said, it might work with something like READ or EVAL.  Or maybe my whole approach is  wrong.&lt;BR /&gt;
&lt;BR /&gt;
(LayoutIterate (function (lambda () (Func2 "hello" "4,4" "0.5"))))&lt;BR /&gt;
&lt;BR /&gt;
- in interpreted code this would work as well with '(lambda ...) instead &lt;BR /&gt;
of (function (lambda ...)), but the latter produces better code when &lt;BR /&gt;
compiled.&lt;BR /&gt;
&lt;BR /&gt;
Also, if you know the parameters inside your LayoutIterate function (not &lt;BR /&gt;
  sensible in a general tool) you could work with APPLY.&lt;BR /&gt;
&lt;BR /&gt;
--</description>
      <pubDate>Wed, 26 Jul 2006 06:38:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715739#M150420</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-26T06:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715740#M150421</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
You don't pass it as a parameter, but you call it within the body of your &lt;BR /&gt;
main function. The next code works flawlesly and it's only normal, because &lt;BR /&gt;
this is what AutoLISP is all about, passing functions to functions, with or &lt;BR /&gt;
without arguments (parameters).&lt;BR /&gt;
&lt;BR /&gt;
(defun Func1 ()&lt;BR /&gt;
  (command "text" "4,4" "0.2" "0" "hello")&lt;BR /&gt;
)&lt;BR /&gt;
(defun Func2 (text inspnt hght)&lt;BR /&gt;
  (command "text" inspnt hght "0" text)&lt;BR /&gt;
)&lt;BR /&gt;
(defun FunctionIterate ()&lt;BR /&gt;
  (command "text" "4,5" "0.2" "0" "This is FunctionIterate")&lt;BR /&gt;
  (func1)&lt;BR /&gt;
  (func2 "Func2" "4,3" "0.2")&lt;BR /&gt;
  (princ)&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
You can see the result in the attached screen shot.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
Constantin&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;JASON roper=""&gt; a écrit dans le message de news: &lt;BR /&gt;
5248241@discussion.autodesk.com...&lt;BR /&gt;
I have some lines of code that will iterate through all layouts in a &lt;BR /&gt;
drawing.  I would like to make it into a function.  I want to pass it to &lt;BR /&gt;
another function as a parameter so that function will run on each layout as &lt;BR /&gt;
it iterates through.  Can you pass a function to another function?  Can you &lt;BR /&gt;
pass a function with parameters of its own?&lt;BR /&gt;
&lt;BR /&gt;
Here's the code.  Thanks for help...&lt;BR /&gt;
&lt;BR /&gt;
(setq IAcadDocument (vla-get-ActiveDocument (vlax-get-Acad-Object))&lt;BR /&gt;
        IAcadLayouts (vla-get-Layouts IAcadDocument)&lt;BR /&gt;
        IActiveLayout (vla-get-ActiveLayout IAcadDocument)&lt;BR /&gt;
        ) ;_ setq&lt;BR /&gt;
  (vlax-for IAcadLayout IAcadLayouts&lt;BR /&gt;
    (if (not (wcmatch (vla-get-name IAcadLayout) "Model"))&lt;BR /&gt;
      (progn&lt;BR /&gt;
        (print (vla-get-Name IAcadLayout))&lt;BR /&gt;
        (vla-put-ActiveLayout IAcadDocument IAcadLayout)&lt;BR /&gt;
        ;;;place function to be ran on each layout here;;&lt;BR /&gt;
        (MyFunc)&lt;BR /&gt;
&lt;BR /&gt;
        ;(print (append (getvar "LIMMIN") (getvar "LIMMAX")))&lt;BR /&gt;
        )&lt;BR /&gt;
      )&lt;BR /&gt;
    ) ;_ vlax-for&lt;BR /&gt;
  (vla-put-ActiveLayout IAcadDocument IActiveLayout)&lt;BR /&gt;
  ;(textscr)&lt;BR /&gt;
  (princ)&lt;/JASON&gt;</description>
      <pubDate>Wed, 26 Jul 2006 14:09:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715740#M150421</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-26T14:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715741#M150422</link>
      <description>Oops,&lt;BR /&gt;
&lt;BR /&gt;
This should be here:&lt;BR /&gt;
&lt;BR /&gt;
"... The next code works flawlesly &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; and it's only normal, because this is &lt;BR /&gt;
what AutoLISP is all about, passing functions to functions, with or without &lt;BR /&gt;
arguments (parameters)...:&lt;BR /&gt;
&lt;BR /&gt;
(alert (strcat "A" "B" "C"))&lt;BR /&gt;
&lt;BR /&gt;
Constantin&lt;BR /&gt;
&lt;BR /&gt;
&lt;JASON roper=""&gt; a écrit dans le message de news: &lt;BR /&gt;
5248241@discussion.autodesk.com...&lt;BR /&gt;
I have some lines of code that will iterate through all layouts in a &lt;BR /&gt;
drawing.  I would like to make it into a function.  I want to pass it to &lt;BR /&gt;
another function as a parameter so that function will run on each layout as &lt;BR /&gt;
it iterates through.  Can you pass a function to another function?  Can you &lt;BR /&gt;
pass a function with parameters of its own?&lt;BR /&gt;
&lt;BR /&gt;
Here's the code.  Thanks for help...&lt;BR /&gt;
&lt;BR /&gt;
(setq IAcadDocument (vla-get-ActiveDocument (vlax-get-Acad-Object))&lt;BR /&gt;
        IAcadLayouts (vla-get-Layouts IAcadDocument)&lt;BR /&gt;
        IActiveLayout (vla-get-ActiveLayout IAcadDocument)&lt;BR /&gt;
        ) ;_ setq&lt;BR /&gt;
  (vlax-for IAcadLayout IAcadLayouts&lt;BR /&gt;
    (if (not (wcmatch (vla-get-name IAcadLayout) "Model"))&lt;BR /&gt;
      (progn&lt;BR /&gt;
        (print (vla-get-Name IAcadLayout))&lt;BR /&gt;
        (vla-put-ActiveLayout IAcadDocument IAcadLayout)&lt;BR /&gt;
        ;;;place function to be ran on each layout here;;&lt;BR /&gt;
        (MyFunc)&lt;BR /&gt;
&lt;BR /&gt;
        ;(print (append (getvar "LIMMIN") (getvar "LIMMAX")))&lt;BR /&gt;
        )&lt;BR /&gt;
      )&lt;BR /&gt;
    ) ;_ vlax-for&lt;BR /&gt;
  (vla-put-ActiveLayout IAcadDocument IActiveLayout)&lt;BR /&gt;
  ;(textscr)&lt;BR /&gt;
  (princ)&lt;/JASON&gt;</description>
      <pubDate>Wed, 26 Jul 2006 14:20:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715741#M150422</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-26T14:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715742#M150423</link>
      <description>I think you are right Constantin,&lt;BR /&gt;
I guess what I was trying to do is make everything too "modular".  My thinking was if I had some routine already developed, I could plug it into the LayoutIterate loop.  But, it would seem the code is more suited to a main body function.  Not to hard to modify.</description>
      <pubDate>Wed, 26 Jul 2006 15:32:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715742#M150423</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-26T15:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715743#M150424</link>
      <description>As a friend of mine uses to say, "sometimes, because of the trees, we can't &lt;BR /&gt;
see the forest &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; But as I said in my last post, you should be able to pass &lt;BR /&gt;
a function to another function too, this is the structure of AutoLISP. The &lt;BR /&gt;
most inner function executes and the result is passed to the next one, and &lt;BR /&gt;
so on, and so on. The call (strcat "A" "B" "C") produces as returning result &lt;BR /&gt;
the string "ABC", which is passed as parameter for (alert string) function. &lt;BR /&gt;
Therefore if (alert (strcat "A" "B" "C")) works, everything respecting the &lt;BR /&gt;
structure, the rules and the syntax should work too, no matter whose &lt;BR /&gt;
functions are and how are they named.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
Constantin&lt;BR /&gt;
&lt;BR /&gt;
&lt;JASON roper=""&gt; a écrit dans le message de news:&lt;BR /&gt;
5249065@discussion.autodesk.com...&lt;BR /&gt;
I think you are right Constantin,&lt;BR /&gt;
I guess what I was trying to do is make everything too "modular".  My&lt;BR /&gt;
thinking was if I had some routine already developed, I could plug it into&lt;BR /&gt;
the LayoutIterate loop.  But, it would seem the code is more suited to a&lt;BR /&gt;
main body function.  Not to hard to modify.&lt;/JASON&gt;</description>
      <pubDate>Wed, 26 Jul 2006 16:35:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715743#M150424</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-26T16:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715744#M150425</link>
      <description>_$ (defun subfun (somethin) (alert somethin))&lt;BR /&gt;
SUBFUN&lt;BR /&gt;
_$ (defun bigfun( smallfun msg) (smallfun msg))&lt;BR /&gt;
BIGFUN&lt;BR /&gt;
_$ (bigfun subfun "look where i'm at")&lt;BR /&gt;
&lt;BR /&gt;
_$ (defun bigfun2 (mess) (eval mess))&lt;BR /&gt;
BIGFUN2&lt;BR /&gt;
_$ (bigfun2 '(subfun "look where i went"))&lt;BR /&gt;
&lt;BR /&gt;
_$ (defun bigfun3 (thing1 thing2) (if (listp thing1) (eval thing1) (thing1 thing2)))&lt;BR /&gt;
BIGFUN3&lt;BR /&gt;
_$ (bigfun3 subfun "look where I'm at")&lt;BR /&gt;
nil&lt;BR /&gt;
_$ (bigfun3 '(subfun "look where i went") nil)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
okay, one more cause thing is getting fun&lt;BR /&gt;
&lt;BR /&gt;
(defun bigfun4 (thing1 thing2) (IF (LISTP thing1)(EVAL (subst (strcat (cadr thing1) thing2) (cadr thing1) thing1) )(thing1 thing2)))&lt;BR /&gt;
(bigfun4 subfun "see where this is going?")&lt;BR /&gt;
(bigfun4 '(subfun "following ") "okay?")&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: uncoolperson

Message was edited by: uncoolperson</description>
      <pubDate>Wed, 26 Jul 2006 16:51:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715744#M150425</guid>
      <dc:creator>uncoolperson</dc:creator>
      <dc:date>2006-07-26T16:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715745#M150426</link>
      <description>&amp;gt;getting fun&lt;BR /&gt;
&lt;BR /&gt;
A little cryptic for my taste. I don't know if the OP is gonna catch your drift. But it is possible to "build" a function call from variables, as you imply. For instance the call to (Func2 "hello" "4,4" "0.5") could take the form:&lt;BR /&gt;
&lt;BR /&gt;
(eval (list 'Func2 string1 string2 string3))</description>
      <pubDate>Wed, 26 Jul 2006 18:10:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715745#M150426</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-26T18:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715746#M150427</link>
      <description>Hi Tom,&lt;BR /&gt;
&lt;BR /&gt;
I had kind of the same feeling. I think that just for the sake of the &lt;BR /&gt;
elegance and beauty of the solutions is worth it, but most of the time it's &lt;BR /&gt;
really necessary to assign data to variables and to pass values between &lt;BR /&gt;
functions in a concise, clear and simple manner.&lt;BR /&gt;
&lt;BR /&gt;
Constantin&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;TOM smith=""&gt; a écrit dans le message de news:&lt;BR /&gt;
5249395@discussion.autodesk.com...&lt;BR /&gt;
&amp;gt;getting fun&lt;BR /&gt;
&lt;BR /&gt;
A little cryptic for my taste. I don't know if the OP is gonna catch your&lt;BR /&gt;
drift. But it is possible to "build" a function call from variables, as you&lt;BR /&gt;
imply. For instance the call to (Func2 "hello" "4,4" "0.5") could take the&lt;BR /&gt;
form:&lt;BR /&gt;
&lt;BR /&gt;
(eval (list 'Func2 string1 string2 string3))&lt;/TOM&gt;</description>
      <pubDate>Wed, 26 Jul 2006 20:39:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715746#M150427</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-26T20:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715747#M150428</link>
      <description>This is not exactly what you asked for but it is an example of a function&lt;BR /&gt;
that will&lt;BR /&gt;
define another function on the fly to reload a lisp file given the string to&lt;BR /&gt;
name the&lt;BR /&gt;
function and the path and filename to load.&lt;BR /&gt;
&lt;BR /&gt;
(defun LOAD_CMD (NAM FIL / PRG$ S ST)&lt;BR /&gt;
  (setq ST (strcat "(()(load " (chr 34) FIL (chr 34) "))")) ;func as a&lt;BR /&gt;
string&lt;BR /&gt;
  (setq S (read ST))                                            ;strip&lt;BR /&gt;
quotes&lt;BR /&gt;
  (setq PRG$ (strcase (strcat "C:" NAM)))                ;cmd name for&lt;BR /&gt;
module&lt;BR /&gt;
  (set (read PRG$) S)                                ;define function as a&lt;BR /&gt;
variable&lt;BR /&gt;
  (or (eval (read PRG$)))                       ;T if new command fuction is&lt;BR /&gt;
defined&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
Call this to make a new command&lt;BR /&gt;
&lt;BR /&gt;
(load_cmd "SUBR" "c:\\programs\\subr.lsp")&lt;BR /&gt;
&lt;BR /&gt;
then at the command line&lt;BR /&gt;
Command: SUBR&lt;BR /&gt;
LAST-DEFUN-NAMED-IN-FILE&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;JASON roper=""&gt; wrote in message news:5248241@discussion.autodesk.com...&lt;BR /&gt;
I have some lines of code that will iterate through all layouts in a&lt;BR /&gt;
drawing.  I would like to make it into a function.  I want to pass it to&lt;BR /&gt;
another function as a parameter so that function will run on each layout as&lt;BR /&gt;
it iterates through.  Can you pass a function to another function?  Can you&lt;BR /&gt;
pass a function with parameters of its own?&lt;BR /&gt;
&lt;BR /&gt;
Here's the code.  Thanks for help...&lt;BR /&gt;
&lt;BR /&gt;
(setq IAcadDocument (vla-get-ActiveDocument (vlax-get-Acad-Object))&lt;BR /&gt;
        IAcadLayouts (vla-get-Layouts IAcadDocument)&lt;BR /&gt;
        IActiveLayout (vla-get-ActiveLayout IAcadDocument)&lt;BR /&gt;
        ) ;_ setq&lt;BR /&gt;
  (vlax-for IAcadLayout IAcadLayouts&lt;BR /&gt;
    (if (not (wcmatch (vla-get-name IAcadLayout) "Model"))&lt;BR /&gt;
      (progn&lt;BR /&gt;
        (print (vla-get-Name IAcadLayout))&lt;BR /&gt;
        (vla-put-ActiveLayout IAcadDocument IAcadLayout)&lt;BR /&gt;
        ;;;place function to be ran on each layout here;;&lt;BR /&gt;
        (MyFunc)&lt;BR /&gt;
&lt;BR /&gt;
        ;(print (append (getvar "LIMMIN") (getvar "LIMMAX")))&lt;BR /&gt;
        )&lt;BR /&gt;
      )&lt;BR /&gt;
    ) ;_ vlax-for&lt;BR /&gt;
  (vla-put-ActiveLayout IAcadDocument IActiveLayout)&lt;BR /&gt;
  ;(textscr)&lt;BR /&gt;
  (princ)&lt;/JASON&gt;</description>
      <pubDate>Wed, 26 Jul 2006 22:14:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715747#M150428</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-26T22:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715748#M150429</link>
      <description>Thanks for all the great responses everyone.  Just wanted to let you know that I'm still following this interesting post.  I'll need some time to play with these ideas.</description>
      <pubDate>Fri, 28 Jul 2006 14:29:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715748#M150429</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-28T14:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715749#M150430</link>
      <description>Aha!&lt;BR /&gt;
&lt;BR /&gt;
First pass function with variables as a list...&lt;BR /&gt;
&lt;BR /&gt;
(LayoutIterate (list 'Func2 "hello" "4,4" "0.5"))&lt;BR /&gt;
&lt;BR /&gt;
...and then in LayoutIterate&lt;BR /&gt;
&lt;BR /&gt;
(defun LayoutIterate (PassFunc)&lt;BR /&gt;
...&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
(eval PassFunc);evaluate list&lt;BR /&gt;
...&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Brillant!  Just what I was looking for.&lt;BR /&gt;
&lt;BR /&gt;
Thanks WB, CG, TS, uncool, chubby, TD.&lt;BR /&gt;
All of your input helped a lot.</description>
      <pubDate>Fri, 28 Jul 2006 20:38:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715749#M150430</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-28T20:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715750#M150431</link>
      <description>Jason Roper wrote:&lt;BR /&gt;
&amp;gt; Aha!&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; First pass function with variables as a list...&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; (LayoutIterate (list 'Func2 "hello" "4,4" "0.5"))&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; ...and then in LayoutIterate&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; (defun LayoutIterate (PassFunc)&lt;BR /&gt;
&amp;gt; ...&lt;BR /&gt;
&amp;gt; ...&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; (eval PassFunc);evaluate list&lt;BR /&gt;
&amp;gt; ...&lt;BR /&gt;
&amp;gt; )&lt;BR /&gt;
&lt;BR /&gt;
That is a slightly brute-force method of solving this, but works as long &lt;BR /&gt;
as your parameters are constants or global variables. If you use &lt;BR /&gt;
variables that have different values inside your function and outside, &lt;BR /&gt;
you might have different results than you expected.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
_$ (setq a 'outer-a b 'outer-b)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
_$ (defun test1 (func / a b)&lt;BR /&gt;
        (setq a 'inner-a b 'inner-b)&lt;BR /&gt;
        (eval func))&lt;BR /&gt;
&lt;BR /&gt;
_$ (test1 (list 'cons a b))&lt;BR /&gt;
(nil)&lt;BR /&gt;
_$ (test1 (list 'cons 'a 'b))&lt;BR /&gt;
(INNER-A . INNER-B)&lt;BR /&gt;
&lt;BR /&gt;
_$ (defun test2 (func / a b)&lt;BR /&gt;
        (setq a 'inner-a b 'inner-b)&lt;BR /&gt;
        (apply (car func) (cdr func)))&lt;BR /&gt;
&lt;BR /&gt;
_$ (test2 (list 'cons a b))&lt;BR /&gt;
(OUTER-A . OUTER-B)&lt;BR /&gt;
_$ (test2 (list 'cons 'a 'b))&lt;BR /&gt;
(A . B)&lt;BR /&gt;
_$ (test2 (function(lambda()(cons a b))))&lt;BR /&gt;
(quote #&lt;USUBR&gt;)&lt;BR /&gt;
&lt;BR /&gt;
_$ (defun test3 (func / a b)&lt;BR /&gt;
         (setq a 'inner-a b 'inner-b)&lt;BR /&gt;
         (apply func nil))&lt;BR /&gt;
&lt;BR /&gt;
_$ (test3 (function(lambda()(cons a b))))&lt;BR /&gt;
(INNER-A . INNER-B)&lt;BR /&gt;
&lt;BR /&gt;
This test3 was rather surprising, as I expected the outer values&lt;BR /&gt;
(as I would get in Common Lisp).&lt;BR /&gt;
&lt;BR /&gt;
--&lt;/USUBR&gt;</description>
      <pubDate>Mon, 31 Jul 2006 09:21:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715750#M150431</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-31T09:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715751#M150432</link>
      <description>Hi Jason,&lt;BR /&gt;
&lt;BR /&gt;
Is there something that I miss or  what ? I can not understand&lt;BR /&gt;
what are you up to ! Why would do you want to scratch your&lt;BR /&gt;
left ear with your right hand behind your head ? The next&lt;BR /&gt;
AutoLISP statement,&lt;BR /&gt;
&lt;BR /&gt;
(defun Func2 (text inspnt hght) &lt;BR /&gt;
[1]&lt;BR /&gt;
  (command "text" inspnt hght "0" text)&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
is already a list, although defun [DEfine FUNction] makes it&lt;BR /&gt;
a special one. So why do you want to pass a list as a list, but&lt;BR /&gt;
with "don't eval" quote as in:&lt;BR /&gt;
&lt;BR /&gt;
(list 'Func2 "hello" "4,4" "0.5") &lt;BR /&gt;
[2]&lt;BR /&gt;
&lt;BR /&gt;
and then try to evaluate it later ? Why first "don't eval" and then&lt;BR /&gt;
"eval" later, when in fact&lt;BR /&gt;
&lt;BR /&gt;
(LayoutIterate (list 'Func2 "hello" "4,4" "0.5"))                   [3]&lt;BR /&gt;
&lt;BR /&gt;
would do exactly the same thing as&lt;BR /&gt;
&lt;BR /&gt;
(defun LayoutIterate () &lt;BR /&gt;
[4]&lt;BR /&gt;
  (Func2 "hello" "4,4" "0.5")&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
and then call it&lt;BR /&gt;
&lt;BR /&gt;
(LayoutIterate) &lt;BR /&gt;
[5]&lt;BR /&gt;
&lt;BR /&gt;
or&lt;BR /&gt;
&lt;BR /&gt;
(defun LayoutIterate (text inspnt hght)                                [6]&lt;BR /&gt;
  (Func2 (text inspnt hght))&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
and then call it&lt;BR /&gt;
&lt;BR /&gt;
(LayoutIterate "hello" "4,4" "0.5")                                      [7]&lt;BR /&gt;
&lt;BR /&gt;
Why do you need to pass the function as an argument ?&lt;BR /&gt;
&lt;BR /&gt;
Constantin&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;JASON roper=""&gt; a écrit dans le message de news: &lt;BR /&gt;
5252241@discussion.autodesk.com...&lt;BR /&gt;
Aha!&lt;BR /&gt;
&lt;BR /&gt;
First pass function with variables as a list...&lt;BR /&gt;
&lt;BR /&gt;
(LayoutIterate (list 'Func2 "hello" "4,4" "0.5"))&lt;BR /&gt;
&lt;BR /&gt;
...and then in LayoutIterate&lt;BR /&gt;
&lt;BR /&gt;
(defun LayoutIterate (PassFunc)&lt;BR /&gt;
...&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
(eval PassFunc);evaluate list&lt;BR /&gt;
...&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Brillant!  Just what I was looking for.&lt;BR /&gt;
&lt;BR /&gt;
Thanks WB, CG, TS, uncool, chubby, TD.&lt;BR /&gt;
All of your input helped a lot.&lt;/JASON&gt;</description>
      <pubDate>Mon, 31 Jul 2006 13:11:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715751#M150432</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-31T13:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: pass a function to a function</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715752#M150433</link>
      <description>I think that that the wrapping make it hard to understand so&lt;BR /&gt;
I post it again:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Is there something that I miss or  what ? I can not understand&lt;BR /&gt;
what are you up to ! Why would do you want to scratch your&lt;BR /&gt;
left ear with your right hand behind your head ? The next&lt;BR /&gt;
AutoLISP statement,&lt;BR /&gt;
&lt;BR /&gt;
(defun Func2 (text inspnt hght)                          [1]&lt;BR /&gt;
  (command "text" inspnt hght "0" text)&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
is already a list, although defun [DEfine FUNction] makes it&lt;BR /&gt;
a special one. So why do you want to pass a list as a list, but&lt;BR /&gt;
with "don't eval" quote as in:&lt;BR /&gt;
&lt;BR /&gt;
(list 'Func2 "hello" "4,4" "0.5")                           [2]&lt;BR /&gt;
&lt;BR /&gt;
and then try to evaluate it later ? Why first "don't eval" and&lt;BR /&gt;
 then "eval" later, when in fact&lt;BR /&gt;
&lt;BR /&gt;
(LayoutIterate (list 'Func2 "hello" "4,4" "0.5"))   [3]&lt;BR /&gt;
&lt;BR /&gt;
would do exactly the same thing as&lt;BR /&gt;
&lt;BR /&gt;
(defun LayoutIterate ()                                      [4]&lt;BR /&gt;
  (Func2 "hello" "4,4" "0.5")&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
and then call it&lt;BR /&gt;
&lt;BR /&gt;
(LayoutIterate)                                                 [5]&lt;BR /&gt;
&lt;BR /&gt;
or&lt;BR /&gt;
&lt;BR /&gt;
(defun LayoutIterate (text inspnt hght)               [6]&lt;BR /&gt;
  (Func2 (text inspnt hght))&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
and then call it&lt;BR /&gt;
&lt;BR /&gt;
(LayoutIterate "hello" "4,4" "0.5")                     [7]&lt;BR /&gt;
&lt;BR /&gt;
Why do you need to pass the function as an argument ?"&lt;BR /&gt;
&lt;BR /&gt;
Constantin&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;JASON roper=""&gt; a écrit dans le message de news: &lt;BR /&gt;
5252241@discussion.autodesk.com...&lt;BR /&gt;
Aha!&lt;BR /&gt;
&lt;BR /&gt;
First pass function with variables as a list...&lt;BR /&gt;
&lt;BR /&gt;
(LayoutIterate (list 'Func2 "hello" "4,4" "0.5"))&lt;BR /&gt;
&lt;BR /&gt;
...and then in LayoutIterate&lt;BR /&gt;
&lt;BR /&gt;
(defun LayoutIterate (PassFunc)&lt;BR /&gt;
...&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
(eval PassFunc);evaluate list&lt;BR /&gt;
...&lt;BR /&gt;
)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Brillant!  Just what I was looking for.&lt;BR /&gt;
&lt;BR /&gt;
Thanks WB, CG, TS, uncool, chubby, TD.&lt;BR /&gt;
All of your input helped a lot.&lt;/JASON&gt;</description>
      <pubDate>Mon, 31 Jul 2006 13:17:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-a-function-to-a-function/m-p/1715752#M150433</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-31T13:17:24Z</dc:date>
    </item>
  </channel>
</rss>

