<?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: Efficient Variables in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12856008#M12520</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5231789"&gt;@DonatasAzaravicius&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am reading&amp;nbsp;&lt;A href="https://www.afralisp.net/autolisp/tutorials/efficient-variables.php" target="_blank" rel="noopener"&gt;Efficient Variables&lt;/A&gt; post&amp;nbsp;by Kenny Ramage.&lt;/P&gt;
&lt;P&gt;And in post he says creating many variables in list is not efficient. But I debate&amp;nbsp; what is more efficient:&lt;/P&gt;
&lt;P&gt;1) To create many variables.&lt;/P&gt;
&lt;P&gt;2) To search list multiple times for variables.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Lisp is "&lt;STRONG&gt;lis&lt;/STRONG&gt;t&lt;STRONG&gt; p&lt;/STRONG&gt;rocessing" not variable processing. Food for thought&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 23 Jun 2024 04:47:32 GMT</pubDate>
    <dc:creator>ronjonp</dc:creator>
    <dc:date>2024-06-23T04:47:32Z</dc:date>
    <item>
      <title>Efficient Variables</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855381#M12512</link>
      <description>&lt;P&gt;I am reading&amp;nbsp;&lt;A href="https://www.afralisp.net/autolisp/tutorials/efficient-variables.php" target="_blank" rel="noopener"&gt;Efficient Variables&lt;/A&gt; post&amp;nbsp;by Kenny Ramage.&lt;/P&gt;&lt;P&gt;And in post he says creating many variables in list is not efficient. But I debate&amp;nbsp; what is more efficient:&lt;/P&gt;&lt;P&gt;1) To create many variables.&lt;/P&gt;&lt;P&gt;2) To search list multiple times for variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this code&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun ListEntity (data / layer color linetype lineweight linescale space) 
  (setq data       (if data data (list nil))
        layer      (nth 0 data) ; Layer name (string)
        color      (nth 1 data) ; Color code
        linetype   (nth 2 data) ; Linetype
        lineweight (nth 3 data) ; Lineweight: by block -2
        linescale  (nth 4 data) ; Linetype scale (optional)
        space      (nth 5 data) ; 0 = Model space, 1 = Paper space (optional)
        paper      (if (eq 0 space) "Model" (nth 6 data)) ; Paper space tab name
  )
  (list 
    '(100 . "AcDbEntity")
    (if space (cons 67 space) '(67 . 0))
    (if paper (cons 410 paper) '(410 . "Model"))
    (if layer (cons 8 layer) '(8 . "0"))
    (if linetype (cons 6 linetype) '(6 . "BYLAYER"))
    (if color (cons 62 color) '(62 . 256))
    (if lineweight (cons 370 lineweight) '(370 . -1))
    (if linescale (cons 48 linescale) '(48 . 1.0))
  )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting parameters in list &lt;EM&gt;data&lt;/EM&gt;, because I don't know if all variables will be in list or not. Maybe &lt;EM&gt;data&lt;/EM&gt; itself will be just &lt;EM&gt;nil&lt;/EM&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;First I check if data is nil. If it is I just create list with one nil so next code in setq would work. Retrive data to diffirent variables. They can also be nil.&lt;/P&gt;&lt;P&gt;After it, from line 13, I check if variable is nil or not. If it is not nil I add associative list with it, if it is nil, I just add default associative list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I create 7 variables for data. I could write line 13 like this:&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(if (nth 5 data) (cons 67 (nth 5 data)) '(67 . 0))&lt;/LI-CODE&gt;&lt;P&gt;But will this be more efficient? To get data from list two times? Would here be any meaning with current compiuters power?&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 16:38:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855381#M12512</guid>
      <dc:creator>DonatasAzaravicius</dc:creator>
      <dc:date>2024-06-22T16:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient Variables</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855407#M12513</link>
      <description>&lt;P&gt;You can increase the power -of variabiles, after you grow the speed of write/read variables.&lt;BR /&gt;In other programs languages , they use array[0..255] of integer ; these variabiles are very -fast-of-speed.&lt;BR /&gt;I believe using type of LIST , you decrease speed too much of speed.&lt;BR /&gt;Exists multiples questions&amp;gt;&lt;/P&gt;&lt;P&gt;a) How to blocked type of variabiles with one type ?&lt;BR /&gt;Eg1. (setint xcoo 10); If you use (setq xcoo 10.0) then , after the VLIDe.dll then will crash&lt;BR /&gt;(setstr sircd "Daca vrem sa rezistam in vremurile ce vor urma, trebuie sa ne marturisim credinta")&lt;BR /&gt;b1) How to defined the fast array of integers?&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;How to defined the fast array of doubles?&lt;BR /&gt;b) How to redim the fast array of integer/doubles?&lt;/P&gt;&lt;P&gt;d)Exists other method to store values? (Eg2.&amp;nbsp; You store the values inside WinReg or RegEdit.exe)&lt;/P&gt;&lt;P&gt;&amp;nbsp; but here problem is the speed,&amp;nbsp; need control memory too much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 17:09:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855407#M12513</guid>
      <dc:creator>diagodose2009</dc:creator>
      <dc:date>2024-06-22T17:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient Variables</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855501#M12514</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5231789"&gt;@DonatasAzaravicius&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;....&amp;nbsp;from line 13, I check if variable is nil or not. If it is not nil I add associative list with it, if it is nil, I just add default associative list.&lt;/P&gt;
&lt;P&gt;So, I create 7 variables for data. I could write line 13 like this:&lt;/P&gt;
&lt;LI-CODE lang="lisp"&gt;(if (nth 5 data) (cons 67 (nth 5 data)) '(67 . 0))&lt;/LI-CODE&gt;
&lt;P&gt;But will this be more efficient? To get data from list two times? ....&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If I understand correctly, I think using&lt;FONT face="courier new,courier" color="#000000"&gt;&lt;STRONG&gt; (cond)&lt;/STRONG&gt; &lt;/FONT&gt;instead of&lt;FONT face="courier new,courier" color="#000000"&gt;&lt;STRONG&gt; (if)&lt;/STRONG&gt; &lt;/FONT&gt;would let you skip those variables, pull the information [if it is there] only once, and do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="lisp"&gt;(defun ListEntity (data)
  (if (not data) (setq data (list nil))) 
  (list 
    '(100 . "AcDbEntity")
    (cons 67 (cond ((nth 5 data)) (0)))
    (cons 410 (cond ((nth 6 data)) ("Model")))
    (cons 8 (cond ((nth 0 data)) ("0")))
    (cons 6 (cond ((nth 2 data)) ("BYLAYER")))
    (cons 62 (cond ((nth 1 data)) (256)))
    (cons 370 (cond ((nth 3 data)) (-1)))
    (cons 48 (cond ((nth 4 data)) (1.0)))
  )
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 18:09:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855501#M12514</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2024-06-22T18:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient Variables</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855525#M12515</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/69526"&gt;@Kent1Cooper&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I think you just provided an example of how not to create variables at all.&amp;nbsp; I think it was you who taught me that it is faster to pass values from one operation to the next without having to save and recall a variable, though I still tend to do things the old-fashioned way because assigning a variable helps me remember its origin.&lt;/P&gt;&lt;P&gt;Mapcar is a great example of computing and passing values without ever naming them.&amp;nbsp; I also think that localizing variables saves memory and time.&lt;/P&gt;&lt;P&gt;BTW, instead of&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;  (if (not data) (setq data (list nil))) 
  (list &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;couldn't you have used...&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(if data
  (list
  ...
)&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 22 Jun 2024 18:26:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855525#M12515</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2024-06-22T18:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient Variables</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855541#M12516</link>
      <description>&lt;P&gt;I think I would need to use this&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(if data
  (list
  ...
  )
  (list
  ...
  )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;if I wan't to use your version. Because function needs to return default dxf codes if data is nil. So, it will need to have second list with all defaults and use Kent1Cooper code for first list. So, Kent1Cooper code should be shorter.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 18:44:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855541#M12516</guid>
      <dc:creator>DonatasAzaravicius</dc:creator>
      <dc:date>2024-06-22T18:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient Variables</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855581#M12517</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3930636"&gt;@john.uhden&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;though I still tend to do things the old-fashioned way because assigning a variable helps me remember its origin.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I have same problem. Wanted to use&amp;nbsp;&lt;SPAN&gt;ListAcDbEntity function and had problems remembering order of data in list.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Got idea to use&amp;nbsp;association list for data. So, I have change funtion to this&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun ListAcDbEntity (data) 
  (list 
    '(100 . "AcDbEntity")
    (cons 67 (cond ((cdr (assoc 'Space data))) (0)))
    (cons 410 (cond ((cdr (assoc 'PaperSpace data))) ("Model")))
    (cons 8 (cond ((cdr (assoc 'Layer data))) ("0")))
    (cons 6 (cond ((cdr (assoc 'Linetype data))) ("BYLAYER")))
    (cons 62 (cond ((cdr (assoc 'Color data))) (256)))
    (cons 370 (cond ((cdr (assoc 'Lineweight data))) (-1)))
    (cons 48 (cond ((cdr (assoc 'Linescale data))) (1.0)))
  )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I see meaning of every dxf from code. I also can call function and not care about order of data.&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(ListAcDbEntity '((Layer . "My Layer") (Color . 5)))&lt;/LI-CODE&gt;&lt;P&gt;Because this is helper function to create other lists, I can use one list for data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(defun ListAcDbEntity (data) 
  (list 
    '(100 . "AcDbEntity")
    (cons 67 (cond ((cdr (assoc 'Space data))) (0)))
    (cons 410 (cond ((cdr (assoc 'PaperSpace data))) ("Model")))
    (cons 8 (cond ((cdr (assoc 'Layer data))) ("0")))
    (cons 6 (cond ((cdr (assoc 'Linetype data))) ("BYLAYER")))
    (cons 62 (cond ((cdr (assoc 'Color data))) (256)))
    (cons 370 (cond ((cdr (assoc 'Lineweight data))) (-1)))
    (cons 48 (cond ((cdr (assoc 'Linescale data))) (1.0)))
  )
)

(defun ListAcDbCircle (data) 
  (list 
    '(100 . "AcDbCircle")
    (cons 39 (cond ((cdr (assoc 'Thickness data))) (0.0)))
    (cons 10 (cond ((cdr (assoc 'Coords data))) ('(0.0 0.0 0.0))))
    (cons 40 (cond ((cdr (assoc 'Radius data))) (1.0)))
    (cons 210 (cond ((cdr (assoc 'Extrusion data))) ('(0.0 0.0 1.0))))
  )
)

(defun ListCircle (data) 
  (append 
    '((0 . "CIRCLE"))
    (ListAcDbEntity data)
    (ListAcDbCircle data)
  )
)&lt;/LI-CODE&gt;&lt;P&gt;And to use it&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(entmake (ListCircle '((Layer . "Circle") (Radius . 3.5) (Color . 1))))
; or
(entmake (ListCircle nil))&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 22 Jun 2024 19:53:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855581#M12517</guid>
      <dc:creator>DonatasAzaravicius</dc:creator>
      <dc:date>2024-06-22T19:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient Variables</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855621#M12518</link>
      <description>&lt;P&gt;The 'data' variable needs to exist as a list, even one with only one item in it which is nil.&amp;nbsp; If 'data' itself is nil, the (nth) functions return errors.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 20:49:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855621#M12518</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2024-06-22T20:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient Variables</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855699#M12519</link>
      <description>&lt;LI-CODE lang="general"&gt;(if (and (listp data)(vl-some '(lambda (x)(not (not x))) data))&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 22 Jun 2024 22:23:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12855699#M12519</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2024-06-22T22:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient Variables</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12856008#M12520</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5231789"&gt;@DonatasAzaravicius&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am reading&amp;nbsp;&lt;A href="https://www.afralisp.net/autolisp/tutorials/efficient-variables.php" target="_blank" rel="noopener"&gt;Efficient Variables&lt;/A&gt; post&amp;nbsp;by Kenny Ramage.&lt;/P&gt;
&lt;P&gt;And in post he says creating many variables in list is not efficient. But I debate&amp;nbsp; what is more efficient:&lt;/P&gt;
&lt;P&gt;1) To create many variables.&lt;/P&gt;
&lt;P&gt;2) To search list multiple times for variables.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Lisp is "&lt;STRONG&gt;lis&lt;/STRONG&gt;t&lt;STRONG&gt; p&lt;/STRONG&gt;rocessing" not variable processing. Food for thought&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jun 2024 04:47:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-variables/m-p/12856008#M12520</guid>
      <dc:creator>ronjonp</dc:creator>
      <dc:date>2024-06-23T04:47:32Z</dc:date>
    </item>
  </channel>
</rss>

