<?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: Recursive construction of associated list in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-construction-of-associated-list/m-p/8792952#M88577</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The makeorsubst function also need an argument for the exisitng list/tree (nil if none)&lt;/P&gt;
&lt;PRE&gt;(defun makeorsubst (keys val lst / sub)
  (cond
    ((null keys)
     (if (setq sub (assoc (car val) lst))
       (subst val sub lst)
       (cons val lst)
     )
    )
    ((setq sub (assoc (car keys) lst))
     (subst (cons (car keys)
		  (makeorsubst (cdr keys) val (cdr sub))
	    )
	    sub
	    lst
     )
    )
    (T
     (append
       (list (cons (car keys) (makeorsubst (cdr keys) val nil)))
       lst
       )
    )
  )
)&lt;/PRE&gt;
&lt;PRE&gt;_$ (setq tree (makeorsubst '("GRP1" "A" 2) '(21 . "b") nil))&lt;BR /&gt;(("GRP1" ("A" (2 (21 . "b")))))&lt;BR /&gt;_$ (setq tree (makeorsubst '("GRP1" "A" 2) '(22 . "c") tree))&lt;BR /&gt;(("GRP1" ("A" (2 (22 . "c") (21 . "b")))))&lt;BR /&gt;_$ (setq tree (makeorsubst '("GRP1" "A" 2) '(22 . "d") tree))&lt;BR /&gt;(("GRP1" ("A" (2 (22 . "d") (21 . "b")))))&lt;BR /&gt;_$ (setq tree (makeorsubst '("GRP1" "A" 3) '(31 . "a") tree))&lt;BR /&gt;(("GRP1" ("A" (3 (31 . "a")) (2 (22 . "d") (21 . "b")))))&lt;/PRE&gt;</description>
    <pubDate>Wed, 15 May 2019 15:02:56 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2019-05-15T15:02:56Z</dc:date>
    <item>
      <title>Recursive construction of associated list</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-construction-of-associated-list/m-p/8792096#M88574</link>
      <description>&lt;P&gt;I read a very interesting forum in &lt;A href="https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-assoc-and-subst/m-p/7823584?collapse_discussion=true&amp;amp;page=2&amp;amp;q=nested%20association%20list&amp;amp;search_type=thread" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-assoc-and-subst/m-p/7823584?collapse_discussion=true&amp;amp;page=2&amp;amp;q=nested%20association%20list&amp;amp;search_type=thread&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;where Gile gave an optimum explanation and a solution to a question regarding the search of associated values and the substitution of values in nested&amp;nbsp; association lists.&lt;/P&gt;
&lt;P&gt;Now I have a subsequente question, of how making from the scratch a nested association list, giving a key list and the final, nested value.&lt;/P&gt;
&lt;P&gt;For example, if I want to assign to the variable al a nested association list&amp;nbsp; (setq al '(("GRP1" ("A" (2 (21 . "b")))))) is it possible to construct a recursive function of the tipe (MAKEORSUBST (list "GRP1" "A" 2) '(21 . "b"))&lt;/P&gt;
&lt;P&gt;In addition, if I have fixed the preceding value for al and I want to add a new value (22 . "c") to the inner value (21 . "b") with the last key 2, can I obtain the result with a command of type (MAKEORSUBST (list "GRP1" "A" 2) '(22 . "c"))?&lt;/P&gt;
&lt;P&gt;I have made numerous attempts to construct such a function on the basis of the functions provided by Gile in that forum, but with no results.&lt;/P&gt;
&lt;P&gt;Please, can Gile himself or someone other give me a help?&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 10:05:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-construction-of-associated-list/m-p/8792096#M88574</guid>
      <dc:creator>giuseppebeatrice222</dc:creator>
      <dc:date>2019-05-15T10:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive construction of associated list</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-construction-of-associated-list/m-p/8792184#M88575</link>
      <description>&lt;P&gt;OT. If you want to draw someone's attention you can use the&amp;nbsp;@ character to do that:&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Then he receives an email that he was mentioned by someone.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 10:43:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-construction-of-associated-list/m-p/8792184#M88575</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2019-05-15T10:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive construction of associated list</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-construction-of-associated-list/m-p/8792643#M88576</link>
      <description>&lt;P&gt;&lt;A href="https://www.theswamp.org/index.php?topic=10837.msg137453#msg137453" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;HERE&lt;/STRONG&gt;&lt;/A&gt; is some code by master ElpanovEvgeniy.&lt;/P&gt;
&lt;P&gt;Another thread &lt;A href="https://www.theswamp.org/index.php?topic=4064.0" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;HERE&lt;/STRONG&gt;&lt;/A&gt;&amp;nbsp;to flatten lists by master MP &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 13:39:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-construction-of-associated-list/m-p/8792643#M88576</guid>
      <dc:creator>ronjonp</dc:creator>
      <dc:date>2019-05-15T13:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive construction of associated list</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-construction-of-associated-list/m-p/8792952#M88577</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The makeorsubst function also need an argument for the exisitng list/tree (nil if none)&lt;/P&gt;
&lt;PRE&gt;(defun makeorsubst (keys val lst / sub)
  (cond
    ((null keys)
     (if (setq sub (assoc (car val) lst))
       (subst val sub lst)
       (cons val lst)
     )
    )
    ((setq sub (assoc (car keys) lst))
     (subst (cons (car keys)
		  (makeorsubst (cdr keys) val (cdr sub))
	    )
	    sub
	    lst
     )
    )
    (T
     (append
       (list (cons (car keys) (makeorsubst (cdr keys) val nil)))
       lst
       )
    )
  )
)&lt;/PRE&gt;
&lt;PRE&gt;_$ (setq tree (makeorsubst '("GRP1" "A" 2) '(21 . "b") nil))&lt;BR /&gt;(("GRP1" ("A" (2 (21 . "b")))))&lt;BR /&gt;_$ (setq tree (makeorsubst '("GRP1" "A" 2) '(22 . "c") tree))&lt;BR /&gt;(("GRP1" ("A" (2 (22 . "c") (21 . "b")))))&lt;BR /&gt;_$ (setq tree (makeorsubst '("GRP1" "A" 2) '(22 . "d") tree))&lt;BR /&gt;(("GRP1" ("A" (2 (22 . "d") (21 . "b")))))&lt;BR /&gt;_$ (setq tree (makeorsubst '("GRP1" "A" 3) '(31 . "a") tree))&lt;BR /&gt;(("GRP1" ("A" (3 (31 . "a")) (2 (22 . "d") (21 . "b")))))&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 May 2019 15:02:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-construction-of-associated-list/m-p/8792952#M88577</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-05-15T15:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive construction of associated list</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-construction-of-associated-list/m-p/8793182#M88578</link>
      <description>&lt;P&gt;Many many thanks Gile, it works very fine.&lt;/P&gt;
&lt;P&gt;Your knowledge of recursion is fantastic.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 16:24:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-construction-of-associated-list/m-p/8793182#M88578</guid>
      <dc:creator>giuseppebeatrice222</dc:creator>
      <dc:date>2019-05-15T16:24:20Z</dc:date>
    </item>
  </channel>
</rss>

