From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Ekstrand Newsgroups: gmane.emacs.help Subject: Re: complex data structure in elisp Date: Tue, 25 Aug 2009 11:01:34 -0500 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1251219042 27261 80.91.229.12 (25 Aug 2009 16:50:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 25 Aug 2009 16:50:42 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Aug 25 18:50:35 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 1MfzEA-0007Sy-8F for geh-help-gnu-emacs@m.gmane.org; Tue, 25 Aug 2009 18:50:34 +0200 Original-Received: from localhost ([127.0.0.1]:47530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfzE9-0000zN-Nv for geh-help-gnu-emacs@m.gmane.org; Tue, 25 Aug 2009 12:50:33 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!feeds.phibee-telecom.net!de-l.enfer-du-nord.net!cs.uu.nl!news.stack.nl!aioe.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 48 Original-NNTP-Posting-Host: cDd5BCWgtxyoDtkX4ZvaNg.user.aioe.org Original-X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.7.9 Cancel-Lock: sha1:OobXvCdHN9h1f6iESJM6l2CbiP0= User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) Original-Xref: news.stanford.edu gnu.emacs.help:172373 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:67521 Archived-At: Dirk80 wrote: > Hi, > > sorry for this beginner question. But I'm very interested how you would > represent the data structure of my example in elisp. > > Here my example: > I want to implement a vocabulary trainer in elisp. > > I have units. A unit is consisting of lessons and lessons are consistng of > sublessons. One sublesson is consisting of vocabularies. A vocabulary is > consisting of an audio-file, picture file and a text. > > Here how I would do it in C: > > For your list structures, just use Lisp lists (or, if you need random access, arrays). You can learn more about them in the Emacs Lisp intro and reference manual. For your other structures, such as Vocabulary, I'd recommend defstruct. It's a macro from Common Lisp, made available in Emacs Lisp via the `cl' package, which allows you to define structures with accessors, etc. For example, your Vocabulary struct: (defstruct vocabulary audio-file picture-file text) You can then do: ;; Make a new vocabulary entry (make-vocabulary :audio-file "snd.au" :picture-file "pic.jpg" :text "Hi!") ;; Retrieve the vocab text from vocab object vobj (vocabulary-text vobj) ;; Check if x is a vocabulary object (vocabulary-p x) ;; Set the audio file (setf (vocabulary-audio-file vobj) "othersnd.au") Look in the CL info document for more on structures. You could also use eieio, an Emacs object system similar to the Common Lisp Object System, but it's more complex and isn't included with Emacs by default, so I wouldn't suggest using it unless you need its additional functionality. - Michael