Merge branch 'master' of ssh://git.informatimago.com/srv/git/sites

Pascal J. Bourguignon [2016-08-20 19:54]
Merge branch 'master' of ssh://git.informatimago.com/srv/git/sites
Filename
com.informatimago.www/articles/lisp-list/index.html
diff --git a/com.informatimago.www/articles/lisp-list/index.html b/com.informatimago.www/articles/lisp-list/index.html
new file mode 100644
index 0000000..75fd421
--- /dev/null
+++ b/com.informatimago.www/articles/lisp-list/index.html
@@ -0,0 +1,115 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<!-- -*- coding:utf-8 -*- -->
+
+<HTML>
+<HEAD>
+  <link rel="icon"          href="/favicon.ico" type="image/x-icon">
+  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
+  <link rel="stylesheet"    href="../../default.css"  type="text/css">
+  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
+  <META NAME="author"             CONTENT="Pascal J. Bourguignon">
+  <META HTTP-EQUIV="Description"
+        NAME="description"        CONTENT="Common Lisp: How do I add an element to a list from a function?">
+  <TITLE>Common Lisp: How do I add an element to a list from a function?</TITLE>
+</HEAD>
+
+<BODY>
+
+<!--TOP-BEGIN-->
+<!-- This section is automatically generated by html-update, -->
+<!-- from data in 'node.el'.    Please, do not edit it here. -->
+<DIV CLASS="TOP"></DIV>
+<!--TOP-END-->
+<!--MENU-BEGIN-->
+<!-- This section is automatically generated by html-update, -->
+<!-- from data in 'node.el'.    Please, do not edit it here. -->
+<DIV CLASS="MENU"><HR><P>|
+ <A HREF="../../toc.html">Contents</a> |
+ <A HREF="../../index.html">Home</a> |
+ <A HREF="../flpl/index.html">Previous</a> |
+ <A HREF="../usenet.html">Up</a> |
+ <A HREF="ccl-sur-qemu.html">Down</a> |
+ <A HREF="ccl-sur-qemu.html">Next</a> |
+</P><HR></DIV>
+<!--MENU-END-->
+
+<h1>Common Lisp: How do I add an element to a list from a function?</h1>
+
+<h2>This doesn't work</h2>
+
+<pre>
+<tt>
+(defun add-element (element list)
+  (push element list))
+
+(let ((list-of-nums (list 1 2 3)))
+  (add-element 42 list-of-nums)
+  list-of-nums)
+
+;; --> (1 2 3)
+</tt>
+</pre>
+
+<p>Actually, it works exactly as it should.  Here is what happens:</p>
+
+<pre>
+<tt>
+cl-user&gt; (mkupack :stepper t)
+
+#&lt;Package "USER2"&gt;
+user2&gt; (defun add-element (element list)
+         (push element list))
+
+
+add-element
+user2&gt; (step (let ((list-of-nums (list 1 2 3)))
+               (add-element 42 list-of-nums)
+               list-of-nums) :trace)
+
+(Will evaluate (let ((list-of-nums #)) (add-element 42 list-of-nums) list-of-nums)
+ (Will evaluate (list 1 2 3)
+  Evaluation of (list 1 2 3) returned one result ==&gt; (1 2 3))
+  (Bind list-of-nums     to (1 2 3))
+ (Will evaluate (add-element 42 list-of-nums)
+  (list-of-nums ==&gt; (1 2 3))
+  (Entering function add-element
+    (Bind element          to 42)
+    (Bind list             to (1 2 3))
+   (Will evaluate (push element list)
+    Evaluation of (push element list) returned one result ==&gt; (42 1 2 3))
+   Exiting  function add-element returned one result ==&gt; (42 1 2 3))
+  Evaluation of (add-element 42 list-of-nums) returned one result ==&gt; (42 1 2 3))
+ (list-of-nums ==&gt; (1 2 3))
+ Evaluation of (let ((list-of-nums #)) (add-element 42 list-of-nums) list-of-nums) returned one result ==&gt; (1 2 3))
+(1 2 3)
+user2&gt;
+</tt>
+</pre>
+
+<p>The parameter <code>list</code> inside the <code>add-element</code>
+  function is effectively modified by the macro <code>push</code>, and
+  you can see its new value being returned <code>(42 1 2 3)</code>.</p>
+
+
+
+
+
+
+<!--BOTTOM-BEGIN-->
+<!-- This section is automatically generated by html-update, -->
+<!-- from data in 'node.el'.    Please, do not edit it here. -->
+<DIV CLASS="BOTTOM">
+<hr><code><small>
+ | <a href="http://www.informatimago.com//articles/raspberrypi/index.html">Mirror on informatimago.com</a>
+ | <a href="http://informatimago.free.fr/i//articles/raspberrypi/index.html">Mirror on free.fr</a>
+ | </small></code>
+
+<BR><SMALL>
+      <a href="http://validator.w3.org/check?uri=referer"><img
+          src="http://www.w3.org/Icons/valid-html401"
+          alt="Valid HTML 4.01!" height="31" width="88"></a>
+   </SMALL>
+</DIV>
+<!--BOTTOM-END-->
+</BODY>
+</HTML>
ViewGit