From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: Symbol properties :prop vs 'prop Date: Sun, 12 Oct 2014 09:44:42 +0200 Organization: Informatimago Message-ID: <87k3454tqt.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1413100226 4696 80.91.229.3 (12 Oct 2014 07:50:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 12 Oct 2014 07:50: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 Sun Oct 12 09:50:24 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XdDv5-00065P-ME for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Oct 2014 09:50:23 +0200 Original-Received: from localhost ([::1]:56444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XdDv5-0003P7-Ch for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Oct 2014 03:50:23 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 99 Original-X-Trace: individual.net txUoqfrCE2xWqn8lm0Q4jwkR30kjta3D2WKfGfu77j1oDLW9sx Cancel-Lock: sha1:YjFhMGVlNzFjZjk1YzdkY2UxNzI2OTRmYTAyM2QzMmY0NjAxZTFjZg== sha1:DTfCCwpa7DoulVTXFDhbg4hDJJE= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:208168 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100444 Archived-At: Paul Rankin writes: > Is there any difference between naming a symbol property as :prop vs > 'prop? i.e. what does the colon ":" mean? > > (put 'my-symbol :width 45) > > (put 'my-symbol 'width 45) In emacs lisp, there's no difference. In emacs lisp, symbols whose name start with a colon are named keyword, and they are automatically set to evaluate to themselves. (symbol-value :hello) --> :hello :hello --> :hello Notice that in emacs lisp, the colon is part of the symbol name: (symbol-name :hello) --> ":hello" therefore you don't need to quote them in expressions. The other symbols which are also interpreted as variables, often have a value that is not themselves (notable exceptions are t and nil). Therefore when you want to obtain the symbol in an expression, you need to quote it: (defvar example 42) example --> 42 'example --> example However, in Common Lisp, there are packages and keywords are symbols that are in the KEYWORD package, while the other symbols are in other packages. Notably, each library and each program use its own set of packages, to avoid collisions and overwritting the symbols of same name in others' packages. CL packages are namespaces. Now imagine that you have in the same lisp image (the same emacs session), a library that manages vehicules (bicycles, motorcycles, cars, trucks, etc), and let's say, a library that draws sexps with box diagrams. The first library wants to store the width of the vehicule in a property named width, the other wants to store the width of the diagram representing the sexp in a property named width. in elisp in CL (setf (getf ford :width) (meter 3.3)) collision! collision! (setf (getf ford :width) (pixel 220)) in elisp in CL (setf (getf ford 'vehicule:width) (meter 3.3)) no package! ok (setf (getf ford 'diagram:width) (pixel 220)) in elisp in CL (in-package :vehicule) no package! ok (setf (getf ford 'width) (meter 3.3)) collision! ok (in-package :diagram) no package! ok (setf (getf ford 'width) (pixel 220)) collision! ok Therefore in elisp, you have to use prefixes all the time: in elisp in CL (setf (getf ford 'vehicule-width) (meter 3.3)) ok ugly (setf (getf ford 'diagram-width) (pixel 220)) Notice that since in elisp the colon is not a special character in symbol names (apart from marking self-evaluating keywords), we can actually use vehicule:width and diagram:width in elisp, using vehicule: instead of vehicule- as prefix. But contrarily to CL where the package qualifier is optional (a current default package is given by the CL:*PACKAGE* variable), thes prefixes are not optional in emacs, if you use one, you have to use them all the time. But this is what you hace to do in elisp, until packages are added. In conclusion, don't use :width or width for your symbol properties, because other libraries use the same name for their symbol properties, so collisions may occur. Instead, use a prefixed symbol: (setf (getf ford 'co-tilk-paul--width) 33) -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk