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: One more question about elisp Date: Sat, 07 Nov 2009 18:39:42 +0100 Organization: Informatimago Message-ID: <87639mb5ep.fsf@galatea.local> References: <53781544-57b8-4cde-a07a-c3632d8bac7f@a32g2000yqm.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1257615667 6783 80.91.229.12 (7 Nov 2009 17:41:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 7 Nov 2009 17:41:07 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Nov 07 18:41:00 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 1N6pHT-00084Z-1M for geh-help-gnu-emacs@m.gmane.org; Sat, 07 Nov 2009 18:40:55 +0100 Original-Received: from localhost ([127.0.0.1]:51292 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N6pHS-00081B-La for geh-help-gnu-emacs@m.gmane.org; Sat, 07 Nov 2009 12:40:54 -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: 81 Original-X-Trace: individual.net 9Pe3JUnLpYdgs0LcaF//7gxgN2TASDxLrMbZB0/IM4NscLfkH/ Cancel-Lock: sha1:MzFhMGQ4YzQ2MjFhYTFjYzIxYjk5NzVkZDljZmJkODBmM2FmZDRjMA== sha1:DubNdCpZQCPjNJBKWFHo0GnIm6w= 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:174513 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:69588 Archived-At: Francis Moreau writes: > On 7 nov, 02:40, LanX wrote: >> On 6 Nov., 22:05, Francis Moreau wrote: >> >> > It sounds strange to me (knowing C, python) to use hash tables to >> > structure data. >> >> You never used dicts in python for structured data??? > > No since python is known to be an object oriented language, if I want > to create an object, I'm defining a new class. I don't use a hash > table for that. > > C allows to define new type. So I won't use a hash table to do that. > > But I can understand that elisp has no way to create new types, This is wrong. > hash tables can serve the purpose although I'm wondering how the code > will be readable (yes I already found elisp quite hard to read). Actually, lisp code is more readable because there is no impedence mismatch between primitive and user defined data types. You should read SICP: Structure and Interpretation of Computer Programs http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html http://swiss.csail.mit.edu/classes/6.001/abelson-sussman-lectures/ http://www.codepoetics.com/wiki/index.php?title=Topics:SICP_in_other_languages http://eli.thegreenplace.net/category/programming/lisp/sicp/ http://www.neilvandyke.org/sicp-plt/ The code will be readable because you will be using functional abstraction: you will defined, (or more usually, have defined) functions to access your abstract data type, the implementation of which won't be relevant (unless you have some efficiency bottleneck, but this remains to be proved by a profiler). Said otherwise, you never use directly primitive functions such as car, cdr, aref, or gethash, etc. Always wrap them by the functions of your own abstract data types. >> IIRC an object instance  (like in your example) is actually just a >> dictionary and "dictionary" is just the python way to say hash table. > > That's an implementation detail. The way you access fields of an > object through a hash table doesn't mean that an object is equivalent > to a hash table. The same occurs in emacs lisp. You write: (require 'eieio) (defclass person () ((name :initarg :name :type string :accessor person-name) (age :initarg :age :type integer :accessor person-age))) (defmethod print-object ((self person) stream) (princ (format "#" (person-name self) (person-age self)) stream) self) (print-object (make-instance 'person :name "Mickey" :age 120) (current-buffer)) inserts: # You don't have to know that objects are implemented as vectors in emacs lisp. -- __Pascal Bourguignon__