|
From: | Johan Andersson |
Subject: | Re: How to describe something in Lisp? |
Date: | Tue, 3 Feb 2009 17:44:47 +0100 |
Andreas Politz <politza@fh-trier.de> writes:>> [...]
> Johan Andersson wrote:
>> Hi!
>> As a Java and Ruby programmer I sometimes find it hard to code
>> Lisp. Right
>> now I'm working on a minor mode for which the structure would obvious for me
>> in Java or Ruby, but in Lisp is a riddle.
>> I will not describe the mode itself, but give a description of the
>> problem.
>> Say I want to store a list of people in a file. And for each person, also
>> some information on them in the format:
>> name|age|married|sex
>> Each time I start the mode, that file should be parsed in to some
>> datastructure (which kind of is the problem). And on save, the file would be
>> updated. For me it's obvious to represent a person with a class:
>> I read something about object orientation in lisp, but I have never> [...]
>> seen this be used in Emacs. So my question is basically: What is the best
>> way to model something in lisp, that you in an object oriented language
>> would model with a class.
>> Thanks!
>
> (defstruct person
There is also EIEIO which is an implementation of CLOS, the Common
Lisp Object System, adapted for emacs.
You can find it part of http://cedet.sourceforge.net/
Then you can define your objects:
(require 'eieio)
(defclass person
((name :type string :initarg :name :accessor name)
(birthdate :type date :initarg :birthdate :accessor birthdate))
(status :type marital-status :initarg :martial-status :accessor martial-status)
(sex :type (member :male :female) :initarg :sex :accessor sex))
(defmethod age ((p person))
(date- (now) (birthdate p)))
...
--
__Pascal Bourguignon__
[Prev in Thread] | Current Thread | [Next in Thread] |