all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: One more question about elisp
Date: Sat, 07 Nov 2009 18:39:42 +0100	[thread overview]
Message-ID: <87639mb5ep.fsf@galatea.local> (raw)
In-Reply-To: ba835a39-fa44-490e-88e0-038863485872@m38g2000yqd.googlegroups.com

Francis Moreau <francis.moro@gmail.com> writes:

> On 7 nov, 02:40, LanX <lanx.p...@googlemail.com> wrote:
>> On 6 Nov., 22:05, Francis Moreau <francis.m...@gmail.com> 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 named %S aged %S>" 
                 (person-name self) (person-age self))
          stream)
   self)

(print-object (make-instance 'person :name "Mickey" :age 120) (current-buffer))
inserts:

#<PERSON NAMED "Mickey" AGED 120>


You don't have to know that objects are implemented as vectors in emacs lisp.

-- 
__Pascal Bourguignon__


  reply	other threads:[~2009-11-07 17:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-06 16:46 One more question about elisp Francis Moreau
2009-11-06 16:55 ` Joost Kremers
2009-11-06 20:59   ` Francis Moreau
2009-11-06 21:28     ` Pascal J. Bourguignon
2009-11-07  1:42     ` Stefan Monnier
2009-11-08 15:20       ` Francis Moreau
2009-11-08 16:12         ` Pascal J. Bourguignon
2009-11-09 21:14           ` Francis Moreau
2009-11-08 19:53         ` Stefan Monnier
2009-11-06 20:02 ` Xah Lee
2009-11-06 21:05   ` Francis Moreau
2009-11-06 21:13     ` David Kastrup
2009-11-07  1:40     ` LanX
2009-11-07  2:31       ` Barry Margolin
2009-11-07 14:41       ` Francis Moreau
2009-11-07 17:39         ` Pascal J. Bourguignon [this message]
2009-11-07 18:10         ` LanX
2009-11-08  9:53         ` tomas
     [not found]         ` <mailman.10267.1257674530.2239.help-gnu-emacs@gnu.org>
2009-11-08 15:17           ` Francis Moreau
2009-11-08 16:01             ` Pascal J. Bourguignon
2009-11-09 20:43               ` Francis Moreau
2009-11-08 17:06             ` tomas
2009-11-07  2:50     ` Giorgos Keramidas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87639mb5ep.fsf@galatea.local \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.