* One more question about elisp @ 2009-11-06 16:46 Francis Moreau 2009-11-06 16:55 ` Joost Kremers 2009-11-06 20:02 ` Xah Lee 0 siblings, 2 replies; 23+ messages in thread From: Francis Moreau @ 2009-11-06 16:46 UTC (permalink / raw) To: help-gnu-emacs Hello, I'm now wondering what is the elisp way to create structured objects and how to access them later. For example I want to create a structure/object which store information about a person. In C language, I would do something like this: structure person { int age; char *name; }; For an object oriented language, Python for example, I would do: class Person(object): def __init__(self, age, name): self.age = age self.name = name but how I do that in elisp ? Should I use a list ? That wouldn't be convenient for accessing the 'fields' of the object later since I need to use an index rather than a name field. Could anybody provide a pointer or any hints ? Thanks ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 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 20:02 ` Xah Lee 1 sibling, 1 reply; 23+ messages in thread From: Joost Kremers @ 2009-11-06 16:55 UTC (permalink / raw) To: help-gnu-emacs Francis Moreau wrote: > I'm now wondering what is the elisp way to create structured objects > and how to access them later. in the cl package, there is defstruct, which does basically what your C-example does: (defstruct person (age) (name)) if you don't want to use that, elisp has hash tables and alists, which are discussed in the elisp manual. HTH -- Joost Kremers joostkremers@yahoo.com Selbst in die Unterwelt dringt durch Spalten Licht EN:SiS(9) ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 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 0 siblings, 2 replies; 23+ messages in thread From: Francis Moreau @ 2009-11-06 20:59 UTC (permalink / raw) To: help-gnu-emacs Joost Kremers <joostkremers@yahoo.com> writes: > Francis Moreau wrote: >> I'm now wondering what is the elisp way to create structured objects >> and how to access them later. > > in the cl package, there is defstruct, which does basically what your > C-example does: > > (defstruct person > (age) > (name)) Actually I'm not trying to do elisp the C way, I'm just wondering the usual/right way to do this in elisp. > if you don't want to use that, elisp has hash tables and alists, which > are discussed in the elisp manual. So alist, hashmap ... ? Thanks -- Francis ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-06 20:59 ` Francis Moreau @ 2009-11-06 21:28 ` Pascal J. Bourguignon 2009-11-07 1:42 ` Stefan Monnier 1 sibling, 0 replies; 23+ messages in thread From: Pascal J. Bourguignon @ 2009-11-06 21:28 UTC (permalink / raw) To: help-gnu-emacs Francis Moreau <francis.moro@gmail.com> writes: > Joost Kremers <joostkremers@yahoo.com> writes: > >> Francis Moreau wrote: >>> I'm now wondering what is the elisp way to create structured objects >>> and how to access them later. >> >> in the cl package, there is defstruct, which does basically what your >> C-example does: >> >> (defstruct person >> (age) >> (name)) > > Actually I'm not trying to do elisp the C way, I'm just wondering the > usual/right way to do this in elisp. Lisp is a programming language which, like any other, has types, data structures and functions, to let you build abstract data type like in any other programming language. >> if you don't want to use that, elisp has hash tables and alists, which >> are discussed in the elisp manual. > > So alist, hashmap ... ? What is the question? -- __Pascal Bourguignon__ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 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 1 sibling, 1 reply; 23+ messages in thread From: Stefan Monnier @ 2009-11-07 1:42 UTC (permalink / raw) To: help-gnu-emacs >>> I'm now wondering what is the elisp way to create structured objects >>> and how to access them later. >> in the cl package, there is defstruct, which does basically what your >> C-example does: >> (defstruct person >> (age) >> (name)) > Actually I'm not trying to do elisp the C way, I'm just wondering the > usual/right way to do this in elisp. defstruct is the right way to do it. Stefan ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-07 1:42 ` Stefan Monnier @ 2009-11-08 15:20 ` Francis Moreau 2009-11-08 16:12 ` Pascal J. Bourguignon 2009-11-08 19:53 ` Stefan Monnier 0 siblings, 2 replies; 23+ messages in thread From: Francis Moreau @ 2009-11-08 15:20 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: >>>> I'm now wondering what is the elisp way to create structured objects >>>> and how to access them later. >>> in the cl package, there is defstruct, which does basically what your >>> C-example does: >>> (defstruct person >>> (age) >>> (name)) > >> Actually I'm not trying to do elisp the C way, I'm just wondering the >> usual/right way to do this in elisp. > > defstruct is the right way to do it. > Ok thanks but that's the clisp way actually. -- Francis ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 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 1 sibling, 1 reply; 23+ messages in thread From: Pascal J. Bourguignon @ 2009-11-08 16:12 UTC (permalink / raw) To: help-gnu-emacs Francis Moreau <francis.moro@gmail.com> writes: > Stefan Monnier <monnier@iro.umontreal.ca> writes: > >>>>> I'm now wondering what is the elisp way to create structured objects >>>>> and how to access them later. >>>> in the cl package, there is defstruct, which does basically what your >>>> C-example does: >>>> (defstruct person >>>> (age) >>>> (name)) >> >>> Actually I'm not trying to do elisp the C way, I'm just wondering the >>> usual/right way to do this in elisp. >> >> defstruct is the right way to do it. >> > > Ok thanks but that's the clisp way actually. You cannot say that. You could say that it's the Common Lisp way, but you'd be wrong, since Common Lisp is a synthesis, a unification of existing lisp languages. defstruct is included in Common Lisp because it existed in previous lisps, such as MacLisp or ZetaLisp, etc. Notice that emacs lisp being slightly earlier than Common Lisp, inherits rather from MacLisp than Common Lisp. -- __Pascal Bourguignon__ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-08 16:12 ` Pascal J. Bourguignon @ 2009-11-09 21:14 ` Francis Moreau 0 siblings, 0 replies; 23+ messages in thread From: Francis Moreau @ 2009-11-09 21:14 UTC (permalink / raw) To: help-gnu-emacs pjb@informatimago.com (Pascal J. Bourguignon) writes: > Francis Moreau <francis.moro@gmail.com> writes: > >> Stefan Monnier <monnier@iro.umontreal.ca> writes: >> >>>>>> I'm now wondering what is the elisp way to create structured objects >>>>>> and how to access them later. >>>>> in the cl package, there is defstruct, which does basically what your >>>>> C-example does: >>>>> (defstruct person >>>>> (age) >>>>> (name)) >>> >>>> Actually I'm not trying to do elisp the C way, I'm just wondering the >>>> usual/right way to do this in elisp. >>> >>> defstruct is the right way to do it. >>> >> >> Ok thanks but that's the clisp way actually. > > You cannot say that. You could say that it's the Common Lisp way, but > you'd be wrong, since Common Lisp is a synthesis, a unification of > existing lisp languages. defstruct is included in Common Lisp because > it existed in previous lisps, such as MacLisp or ZetaLisp, etc. > > Notice that emacs lisp being slightly earlier than Common Lisp, > inherits rather from MacLisp than Common Lisp. Ok thanks for the clarification. -- Francis ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-08 15:20 ` Francis Moreau 2009-11-08 16:12 ` Pascal J. Bourguignon @ 2009-11-08 19:53 ` Stefan Monnier 1 sibling, 0 replies; 23+ messages in thread From: Stefan Monnier @ 2009-11-08 19:53 UTC (permalink / raw) To: help-gnu-emacs >>> Actually I'm not trying to do elisp the C way, I'm just wondering the >>> usual/right way to do this in elisp. >> defstruct is the right way to do it. > Ok thanks but that's the clisp way actually. Other lanagues are irrelevant here: in Elisp, `defstruct' is the right way to do it. Stefan "Emacs maintainer" PS: As for "why isn't it used more in Emacs's packages?", one of the reasons is that most Emacs packages provide little more than some description of the language they support, and the real code using it is implemented elsewhere (e.g. in C). Also for most packages the only "data structures" they use is the buffer's text. OTOH most applications written in Elisp do use defstruct or something comparable. ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-06 16:46 One more question about elisp Francis Moreau 2009-11-06 16:55 ` Joost Kremers @ 2009-11-06 20:02 ` Xah Lee 2009-11-06 21:05 ` Francis Moreau 1 sibling, 1 reply; 23+ messages in thread From: Xah Lee @ 2009-11-06 20:02 UTC (permalink / raw) To: help-gnu-emacs On Nov 6, 8:46 am, Francis Moreau <francis.m...@gmail.com> wrote: > Hello, > > I'm now wondering what is the elisp way to create structured objects > and how to access them later. > > For example I want to create a structure/object which store > information about a person. > > In C language, I would do something like this: > > structure person { > int age; > char *name; > > }; > > For an object oriented language, Python for example, I would do: > > class Person(object): > def __init__(self, age, name): > self.age = age > self.name = name > > but how I do that in elisp ? > > Should I use a list ? That wouldn't be convenient for accessing the > 'fields' of the object later since I need to use an index rather than > a name field. > > Could anybody provide a pointer or any hints ? you can use Association Lists or hash table. For a short tutorial, see: • Elisp Lesson: Hash Table http://xahlee.org/emacs/elisp_hash_table.html Xah ∑ http://xahlee.org/ ☄ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-06 20:02 ` Xah Lee @ 2009-11-06 21:05 ` Francis Moreau 2009-11-06 21:13 ` David Kastrup ` (2 more replies) 0 siblings, 3 replies; 23+ messages in thread From: Francis Moreau @ 2009-11-06 21:05 UTC (permalink / raw) To: help-gnu-emacs Xah Lee <xahlee@gmail.com> writes: > On Nov 6, 8:46 am, Francis Moreau <francis.m...@gmail.com> wrote: [...] >> Could anybody provide a pointer or any hints ? > > you can use Association Lists or hash table. For a short tutorial, > see: > > • Elisp Lesson: Hash Table > http://xahlee.org/emacs/elisp_hash_table.html > Thanks for the pointer. It sounds strange to me (knowing C, python) to use hash tables to structure data. -- Francis ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-06 21:05 ` Francis Moreau @ 2009-11-06 21:13 ` David Kastrup 2009-11-07 1:40 ` LanX 2009-11-07 2:50 ` Giorgos Keramidas 2 siblings, 0 replies; 23+ messages in thread From: David Kastrup @ 2009-11-06 21:13 UTC (permalink / raw) To: help-gnu-emacs Francis Moreau <francis.moro@gmail.com> writes: > Xah Lee <xahlee@gmail.com> writes: > >> On Nov 6, 8:46 am, Francis Moreau <francis.m...@gmail.com> wrote: > > [...] > >>> Could anybody provide a pointer or any hints ? >> >> you can use Association Lists or hash table. For a short tutorial, >> see: >> >> • Elisp Lesson: Hash Table >> http://xahlee.org/emacs/elisp_hash_table.html >> > > Thanks for the pointer. > > It sounds strange to me (knowing C, python) to use hash tables to > structure data. Then you should take a look at Lua. (hash) tables are the only available data _structure_ (of course, there are more data _types_, but still quite a small number). -- David Kastrup ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 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 2:50 ` Giorgos Keramidas 2 siblings, 2 replies; 23+ messages in thread From: LanX @ 2009-11-07 1:40 UTC (permalink / raw) To: help-gnu-emacs 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??? IIRC an object instance (like in your example) is actually just a dictionary and "dictionary" is just the python way to say hash table. If this is not the answer you should maybe try to extend the question. HTH Rolf ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-07 1:40 ` LanX @ 2009-11-07 2:31 ` Barry Margolin 2009-11-07 14:41 ` Francis Moreau 1 sibling, 0 replies; 23+ messages in thread From: Barry Margolin @ 2009-11-07 2:31 UTC (permalink / raw) To: help-gnu-emacs In article <df099ab0-0fca-4a34-8b2d-f02fc068c6d1@v30g2000yqm.googlegroups.com>, LanX <lanx.perl@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??? That's also how it's done in Perl, where they're called hashes. This is a very convenient way to implement structured data that's easily extended. You don't have to predefine the object layout, you can add new elements on the fly easily. It probably wouldn't have been practical 20-30 years ago when Lisp idioms were being created. The overhead of hashing so frequently would have been excessive on that generation of computers. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group *** ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 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 ` (3 more replies) 1 sibling, 4 replies; 23+ messages in thread From: Francis Moreau @ 2009-11-07 14:41 UTC (permalink / raw) To: help-gnu-emacs 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, 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). > 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. Thanks ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-07 14:41 ` Francis Moreau @ 2009-11-07 17:39 ` Pascal J. Bourguignon 2009-11-07 18:10 ` LanX ` (2 subsequent siblings) 3 siblings, 0 replies; 23+ messages in thread From: Pascal J. Bourguignon @ 2009-11-07 17:39 UTC (permalink / raw) To: help-gnu-emacs 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__ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-07 14:41 ` Francis Moreau 2009-11-07 17:39 ` Pascal J. Bourguignon @ 2009-11-07 18:10 ` LanX 2009-11-08 9:53 ` tomas [not found] ` <mailman.10267.1257674530.2239.help-gnu-emacs@gnu.org> 3 siblings, 0 replies; 23+ messages in thread From: LanX @ 2009-11-07 18:10 UTC (permalink / raw) To: help-gnu-emacs > 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. So your question is how to realize a "classical" object model in elisp ! With constructors, classes, class-methods and class-variables ? Private attributes and public attributes? ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-07 14:41 ` Francis Moreau 2009-11-07 17:39 ` Pascal J. Bourguignon 2009-11-07 18:10 ` LanX @ 2009-11-08 9:53 ` tomas [not found] ` <mailman.10267.1257674530.2239.help-gnu-emacs@gnu.org> 3 siblings, 0 replies; 23+ messages in thread From: tomas @ 2009-11-08 9:53 UTC (permalink / raw) To: Francis Moreau; +Cc: help-gnu-emacs -----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----- ^ permalink raw reply [flat|nested] 23+ messages in thread
[parent not found: <mailman.10267.1257674530.2239.help-gnu-emacs@gnu.org>]
* Re: One more question about elisp [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-08 17:06 ` tomas 0 siblings, 2 replies; 23+ messages in thread From: Francis Moreau @ 2009-11-08 15:17 UTC (permalink / raw) To: help-gnu-emacs tomas@tuxteam.de writes: [...] > > You have been pointed to "defstruct" already. From it info page: I realized this is not part of elips but clisp, that's why I missed it. The weird thing (for now) is that "defstruct" is not very used in the source code of emacs. Anyway, I'll keep trying to learn the basic concept of elisp. Thanks -- Francis ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 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 1 sibling, 1 reply; 23+ messages in thread From: Pascal J. Bourguignon @ 2009-11-08 16:01 UTC (permalink / raw) To: help-gnu-emacs Francis Moreau <francis.moro@gmail.com> writes: > tomas@tuxteam.de writes: > > [...] > >> >> You have been pointed to "defstruct" already. From it info page: > > I realized this is not part of elips but clisp, that's why I missed it. There is no programming language named clisp. There is one named Common Lisp, which has several implementations, one of which is called clisp. But "clisp" is not the name of a programming language, it's the name of a program. > The weird thing (for now) is that "defstruct" is not very used in the > source code of emacs. > > Anyway, I'll keep trying to learn the basic concept of elisp. THE basic concept of all the languages in the lisp family, is that of the uniform syntax for data and code (symbolic expressions, sexp). This allows to easily write programs to transform programs, since programs are normal lisp data. Hence the notion of macro. This allows to easily extend the language to fit your needs, since the new operators you can implement with macros are indistinguishable from primitive operators. Apart from that, the exact primitive data types provided by a lisp system is rather irrelevant, given a few user level libraries providing the macros needed to define data abstractions you want. And if these libraries don't exist, no problem, you can easily write them yourself. In anycase, in a sizeable lisp program it is expected that you write yourself your own macros to define your own, application specific, language. So, yes, structures don't exist in the bare emacs lisp language. But this doesn't matter, since there is the cl package that provides a defstruct macro. If this package didn't exist, it wouldn't matter either, since you could easily write such a defstruct macro yourself. And in any case it doesn't matter, since in your application you'll be expected to define your own macro to define your own entities. (You may base your macro on defstruct, or you may base it on lower level emacs lisp vectors, or on cons cells, or whatever, it just does not matter). 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/ -- __Pascal Bourguignon__ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-08 16:01 ` Pascal J. Bourguignon @ 2009-11-09 20:43 ` Francis Moreau 0 siblings, 0 replies; 23+ messages in thread From: Francis Moreau @ 2009-11-09 20:43 UTC (permalink / raw) To: help-gnu-emacs pjb@informatimago.com (Pascal J. Bourguignon) writes: [...] > > THE basic concept of all the languages in the lisp family, is that of > the uniform syntax for data and code (symbolic expressions, sexp). > > This allows to easily write programs to transform programs, since > programs are normal lisp data. Hence the notion of macro. > > This allows to easily extend the language to fit your needs, since the > new operators you can implement with macros are indistinguishable from > primitive operators. > > > Apart from that, the exact primitive data types provided by a lisp > system is rather irrelevant, given a few user level libraries > providing the macros needed to define data abstractions you want. And > if these libraries don't exist, no problem, you can easily write them > yourself. In anycase, in a sizeable lisp program it is expected that > you write yourself your own macros to define your own, application > specific, language. > > > So, yes, structures don't exist in the bare emacs lisp language. But > this doesn't matter, since there is the cl package that provides a > defstruct macro. If this package didn't exist, it wouldn't matter > either, since you could easily write such a defstruct macro yourself. > > And in any case it doesn't matter, since in your application you'll be > expected to define your own macro to define your own entities. (You > may base your macro on defstruct, or you may base it on lower level > emacs lisp vectors, or on cons cells, or whatever, it just does not > matter). > > > 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/ Ok I'll take time to read them, but I'm going to shift (again) the time when I'll be able to customize my .emacs ;) -- Francis ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-08 15:17 ` Francis Moreau 2009-11-08 16:01 ` Pascal J. Bourguignon @ 2009-11-08 17:06 ` tomas 1 sibling, 0 replies; 23+ messages in thread From: tomas @ 2009-11-08 17:06 UTC (permalink / raw) To: Francis Moreau; +Cc: help-gnu-emacs -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sun, Nov 08, 2009 at 04:17:02PM +0100, Francis Moreau wrote: > tomas@tuxteam.de writes: > > [...] > > > > > You have been pointed to "defstruct" already. From it info page: > > I realized this is not part of elips but clisp, that's why I missed it. Ah, I see. Indeed, defstruct belongs to "cl-macs.el", an add on (as Pascal pointed out elsewhere in this thread, the cl stands for "Common Lisp", that's where this feature has been taken from). > The weird thing (for now) is that "defstruct" is not very used in the > source code of emacs. Right. This might be confusing for you. As a matter of policy, it has been decided that core Emacs packages don't rely on "cl.el". OTOH, "cl-macs.el" is considered OK, because it's just needed at compile time. But when writing your own programs, you are free, of course :-) Regards - -- tomás -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFK9vquBcgs9XrR2kYRAj0HAJkB9zrQ1PuY+XLVdEfT6lrfbq8y5wCbB2ZQ hhm7qs272eAxF85SOoNisVU= =gzS4 -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: One more question about elisp 2009-11-06 21:05 ` Francis Moreau 2009-11-06 21:13 ` David Kastrup 2009-11-07 1:40 ` LanX @ 2009-11-07 2:50 ` Giorgos Keramidas 2 siblings, 0 replies; 23+ messages in thread From: Giorgos Keramidas @ 2009-11-07 2:50 UTC (permalink / raw) To: help-gnu-emacs On Fri, 06 Nov 2009 22:05:46 +0100, Francis Moreau <francis.moro@gmail.com> wrote: > Xah Lee <xahlee@gmail.com> writes: >> • Elisp Lesson: Hash Table >> http://xahlee.org/emacs/elisp_hash_table.html > > Thanks for the pointer. > > It sounds strange to me (knowing C, python) to use hash tables to > structure data. Python uses `dictionaries' (i.e. hashes) extensively, so it is not a very alien idea to store the named `attributes' of an object in a convenient to use data structure like a hash map :-) ^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2009-11-09 21:14 UTC | newest] Thread overview: 23+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).