<?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: Calling sub function syntax in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5833609#M138094</link>
    <description>Next.&lt;BR /&gt;Try this as a function with a call:&lt;BR /&gt;(defun c:AAA ()&lt;BR /&gt; (alert "this is a")&lt;BR /&gt; (bbb "This is bbb-1")&lt;BR /&gt; (alert "this is a")&lt;BR /&gt; (bbb "This is bbb-2")&lt;BR /&gt; (alert "this is a")&lt;BR /&gt; (princ)&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;(defun bbb ( a / )&lt;BR /&gt; (alert a)&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;bbb cannot be a command in this instance because&lt;BR /&gt;of the call (item in front of the forward slash).&lt;BR /&gt;&lt;BR /&gt;Next.&lt;BR /&gt;Function returns a value:&lt;BR /&gt;(defun c:AAA ()&lt;BR /&gt; (alert (bbb))&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;(defun bbb ()&lt;BR /&gt; "This is bbb-3"&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;Another way to do this:&lt;BR /&gt;(defun bbb ()&lt;BR /&gt; (setq b "this is bbb-4")&lt;BR /&gt; (princ)&lt;BR /&gt; b&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;???&lt;BR /&gt;</description>
    <pubDate>Fri, 25 Sep 2015 22:15:10 GMT</pubDate>
    <dc:creator>scot-65</dc:creator>
    <dc:date>2015-09-25T22:15:10Z</dc:date>
    <item>
      <title>Calling sub function syntax</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5832321#M138087</link>
      <description>&lt;P&gt;I've never written a lisp with a subfunction within it before, please can someone check the following syntax is correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it's not very ambitious to say the least but if I can get the basics right then subsequent lisps might stand a chance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(defun c:aaa ()
    (alert "this is aaa")
   (bbb)
      (alert "this is aaa again")
  (princ)
  )


(defun c:bbb ()
    (alert "this is bbb")
  )&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 07:14:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5832321#M138087</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-09-25T07:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calling sub function syntax</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5832349#M138088</link>
      <description>&lt;P&gt;If you're about calling your bbb sub multiply just from main c:aaa routine, then something like this. Put it inside of c:aaa and localize bbb.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;(defun c:aaa ( / bbb)

  (defun bbb ()
    (alert "this is bbb")
  )

  ; main program
  
  (alert "this is aaa") 
  (bbb)
  (alert "this is aaa again")
  (princ)
)&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you about to call bbb from other routines as well (e.g. c:ccc), then use this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;(defun c:aaa ()
  (alert "this is aaa") 
  (bbb)
  (alert "this is aaa again")
  (princ)
)

(defun c:ccc ()
  (alert "this is ccc") 
  (bbb)
  (alert "this is ccc again")
  (princ)
)

(defun bbb ()
    (alert "this is bbb")
)&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you want to call bbb separately as command as well, use c: prefix. But usually you don't...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;(defun c:aaa ()
  (alert "this is aaa") 
  (c:bbb)
  (alert "this is aaa again")
  (princ)
)

(defun c:bbb ()
    (alert "this is c:bbb")
)
&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 07:55:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5832349#M138088</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2015-09-25T07:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calling sub function syntax</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5832356#M138089</link>
      <description>&lt;P&gt;Thanks ever so for that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll definitely be keeping this page in my Favourites to refer to again !&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 07:56:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5832356#M138089</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-09-25T07:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calling sub function syntax</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5832628#M138090</link>
      <description>&lt;P&gt;You can either define bbb &lt;EM&gt;without&lt;/EM&gt; the C: prefix, as already suggested, or you can &lt;EM&gt;use&lt;/EM&gt; it &lt;EM&gt;with&lt;/EM&gt; the C: prefix:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(defun c:aaa ()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;(alert "this is aaa")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;(&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;c:&lt;/STRONG&gt;&lt;/FONT&gt;bbb)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;(alert "this is aaa again")&lt;BR /&gt;&amp;nbsp; (princ)&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;(defun c:bbb ()&lt;BR /&gt;&amp;nbsp; (alert "this is bbb")&lt;BR /&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The advantage of that is that, if you want to, you can enter bbb itself as a command name.&amp;nbsp; If it's defined without the C: prefix, to use it on its own you need to call it with the parentheses:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Command:&amp;nbsp;&lt;FONT color="#ff0000"&gt; (&lt;/FONT&gt;bbb&lt;FONT color="#ff0000"&gt;)&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 12:19:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5832628#M138090</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2015-09-25T12:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calling sub function syntax</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5833030#M138091</link>
      <description>&lt;P&gt;Thanks for that Kent, it's all clear to me now. My mistake was that I referred to other people lisps, but couldn’t work out why my little test lisp failed. All the other folks lisps don’t have the c: at the beginning of their sub functions &amp;amp; I didn’t notice. I’m so used to starting a function these days with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(defun c:my_func ()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that it’s become automatic.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I couldn’t find much about it with a Google either.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 15:44:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5833030#M138091</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-09-25T15:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calling sub function syntax</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5833046#M138092</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I couldn’t find much about it with a Google either.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How about&amp;nbsp;&lt;A href="http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-EF910176-86D2-4158-A7C3-E926A002F421" target="_self"&gt;help!&lt;/A&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 15:52:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5833046#M138092</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2015-09-25T15:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calling sub function syntax</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5833478#M138093</link>
      <description>&lt;P&gt;When writing a routine that I think might be useful to be called from another routine, but also one that I want to use as a command unto itself, I usually write it WITHOUT the c: (what I refer to as a performing function) and then write a function that gathers the user input and then passes it to the other function (aka a gathering function).&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;;;This is how a routine might normally be written as a command.
;;
(defun c:mycommand ( / ents var1 var2)
  (setq ents(ssget))
  (setq var1 (getpoint "Point1:  "))
  (setq var2 (getpoint "Point2:  "))
  (command "move" ents "" var1 var2)
)

;;now if I want to make it so that a different routine can gather the user input
;;(and probably do other things too) then perform the tasks, I would break it 
;;into a performing function and a gathering function.

;;this is the gathering function.
(defun c:mycommand( / ents var1 var2)
  (setq ents(ssget))
  (setq var1 (getpoint "Point1:  "))
  (setq var2 (getpoint "Point2:  "))
  (mycommand ents var1 var2) ;; &amp;lt;--it might look like it's calling itself.  
                                                  ;;     But it's calling the performing function
)
;;this is the performing function
(defun mycommand (ents var1 var2)
  (command "Move" ents "" var1 var2)
)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;This is just one example as to why both styles are useful.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 20:10:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5833478#M138093</guid>
      <dc:creator>doni49</dc:creator>
      <dc:date>2015-09-25T20:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calling sub function syntax</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5833609#M138094</link>
      <description>Next.&lt;BR /&gt;Try this as a function with a call:&lt;BR /&gt;(defun c:AAA ()&lt;BR /&gt; (alert "this is a")&lt;BR /&gt; (bbb "This is bbb-1")&lt;BR /&gt; (alert "this is a")&lt;BR /&gt; (bbb "This is bbb-2")&lt;BR /&gt; (alert "this is a")&lt;BR /&gt; (princ)&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;(defun bbb ( a / )&lt;BR /&gt; (alert a)&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;bbb cannot be a command in this instance because&lt;BR /&gt;of the call (item in front of the forward slash).&lt;BR /&gt;&lt;BR /&gt;Next.&lt;BR /&gt;Function returns a value:&lt;BR /&gt;(defun c:AAA ()&lt;BR /&gt; (alert (bbb))&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;(defun bbb ()&lt;BR /&gt; "This is bbb-3"&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;Another way to do this:&lt;BR /&gt;(defun bbb ()&lt;BR /&gt; (setq b "this is bbb-4")&lt;BR /&gt; (princ)&lt;BR /&gt; b&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;???&lt;BR /&gt;</description>
      <pubDate>Fri, 25 Sep 2015 22:15:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calling-sub-function-syntax/m-p/5833609#M138094</guid>
      <dc:creator>scot-65</dc:creator>
      <dc:date>2015-09-25T22:15:10Z</dc:date>
    </item>
  </channel>
</rss>

