From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Creating a list Date: Thu, 19 Nov 2009 20:26:40 +0100 Organization: Informatimago Message-ID: <87y6m2gvtb.fsf@galatea.local> References: <87k4xnge1t.fsf@Traian.DecebalComp> <87y6m2kj3m.fsf@lola.goethe.zz> <874ooqhjaw.fsf@Traian.DecebalComp> <874ooqkah6.fsf@lola.goethe.zz> <873a4afyi0.fsf@Traian.DecebalComp> <87fx8aeeh1.fsf@Traian.DecebalComp> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1258659866 13205 80.91.229.12 (19 Nov 2009 19:44:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 19 Nov 2009 19:44:26 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 19 20:44:19 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NBCvQ-0005sM-9s for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Nov 2009 20:44:16 +0100 Original-Received: from localhost ([127.0.0.1]:37690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NBCvP-0002sY-K1 for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Nov 2009 14:44:15 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 113 Original-X-Trace: individual.net Az5pRt0NQCtOLMDNnpDU9gkBipJqToSiQ8Z2F7bS53wnPrNFyl Cancel-Lock: sha1:ZGI5YmNjMDQ3Y2Q0ZGUwMTU5NjRhZDk3ODlmNDQxNzdlYzA5YmM3Ng== sha1:CvnTR6gouifdZQGooa6jvBI5h9Y= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) Original-Xref: news.stanford.edu gnu.emacs.help:174869 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:69941 Archived-At: Cecil Westerhof writes: > Barry Margolin writes: > >>> Off course. >> >> I think you mean "of course". > > English is not my first language. I'll try to be more correct. > > >>> But I have a few questions on my mind. >>> - Why is the first shown as value and the second as _symbol_? >> >> Because you quoted the list containing the symbol, so it wasn't >> evaluated. > > Okay, thanks. At the moment it is not important, because I now work with > list instead off with cons, of Lisp lists are implemented with cons cells. So when you work with lists, in lisp, you do work with conses at the same time. This is an important thing to understand about lisp. While you can develop in lisp abstract data type, where the implementation details are hidden, and where you provide all the functional abstraction needed, in the case of conses, and lists and trees and any other data structure built upon them, the implementation is left leaking, so you can pun, you can play word games with these data. Cons level functions are: cons car cdr consp (and atom). Symbol level functions are: null List level functions are: list list* first second ... tenth rest endp listp. When you write: (let ((la (list 1 2 3))) (let ((lb (cons 0 la))) lb)) you are punning on the fact that a lisp list is a chain of conses or the symbol nil, and that a reference to a list is also a reference to the first cons of the list (or nil when it's empty). To be consistent, you should actually write: (require 'cl) (let ((la (list 1 2 3))) (let ((lb (list* 0 la))) lb)) Similarly, you shouldn't write (null list), but (endp list). Notice that endp doesn't behave exactly like null, and that in general, when you are processing lists, you want the meaning of endp, not that of null. So while it may be important for the human reader to use the functions corresponding to the right level of the data type considered, it is also nice to be able to change of level from time to time, and be able to write (cddr tree) to get the children of the node tree, if we implement these trees as lists containing the label, the color, and the children. Only you don't use cddr all over the program, you wrap it in a tree-children function: (defun make-tree (label color children) (list* label color children)) ; list function (defun tree-children (tree) (cddr tree)) ; pun: cons function, we're considering the ; list as the sequence of conses it is. > but how would I get it evaluated? You can get a symbol, or any expression, evaluated by not doing what you do to prevent it being evaluated. Let's read again the question and the answer: >>> - Why is the first shown as value and the second as _symbol_? >> >> Because you quoted the list containing the symbol, so it wasn't >> evaluated. So when you quote an object it doesn't get evaluated. How can you get it evaluated? By NOT quoting it. Just try it. Type M-x ielm RET Then type each expression followed by a RET in the *ielm* buffer: (defvar current 42) 'current current (quote current) current (defun furrent () (* 21 2)) '(furrent) (furrent) (quote (furrent)) (furrent) -- __Pascal Bourguignon__