[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: One more question about elisp
From: |
tomas |
Subject: |
Re: One more question about elisp |
Date: |
Sun, 8 Nov 2009 10:53:43 +0100 |
User-agent: |
Mutt/1.5.15+20070412 (2007-04-11) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sat, Nov 07, 2009 at 06:41:07AM -0800, Francis Moreau wrote:
> 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.
But Python *does* anyway use a hash behind the scenes for that. Like
Perl and friends (as you seem to know, see below).
>
> 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, and
> 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).
You have been pointed to "defstruct" already. From it info page:
+---------------------------------------------------------------------
| defstruct is an autoloaded Lisp macro in `cl-macs.el'.
|
| (defstruct (name options...) (slot slot-opts...)...)
|
| Define a struct type.
| This macro defines a new Lisp data type called name, which contains data
| stored in slots. This defines a `make-name' constructor, a `copy-name'
| copier, a `name-p' predicate, and setf-able `NAME-SLOT' accessors.
+---------------------------------------------------------------------
> > 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.
If you don't care in Python, why you should care in Lisp? Just define a
couple of accessor macros and be done with it. Or let Lisp do it for
you, via a clever set of macros, als cl-macs.el does for you :-)
Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFK9pUnBcgs9XrR2kYRAoWaAJ0VtHsdLiDEFGsvN6Z+WfbOs9/91gCfczPg
tL0/3pI9YbQx+jpVoIP51gw=
=aYy7
-----END PGP SIGNATURE-----
- Re: One more question about elisp, (continued)
- Re: One more question about elisp, Xah Lee, 2009/11/07
- Re: One more question about elisp, Francis Moreau, 2009/11/06
- Re: One more question about elisp, David Kastrup, 2009/11/06
- Re: One more question about elisp, LanX, 2009/11/06
- Re: One more question about elisp, Barry Margolin, 2009/11/06
- Re: One more question about elisp, Francis Moreau, 2009/11/07
- Re: One more question about elisp, Pascal J. Bourguignon, 2009/11/07
- Re: One more question about elisp, LanX, 2009/11/07
- Re: One more question about elisp,
tomas <=
- Message not available
- Re: One more question about elisp, Francis Moreau, 2009/11/08
- Re: One more question about elisp, Pascal J. Bourguignon, 2009/11/08
- Re: One more question about elisp, Francis Moreau, 2009/11/09
- Re: One more question about elisp, tomas, 2009/11/08
- Re: One more question about elisp, Giorgos Keramidas, 2009/11/06