help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Something like an array (list) of a class


From: thierry . volpiatto
Subject: Re: Something like an array (list) of a class
Date: Sun, 12 Apr 2009 10:03:11 +0200
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.92 (gnu/linux)

Decebal <address@hidden> writes:

> On Apr 11, 10:08 am, address@hidden wrote:
>> > I would like to make some datadriven functionality. Is there a way to
>> > make sure a list is filled with a certain type of data. I would like
>> > to make sure that every element of my list contains: a type, a
>> > description, a functionname and room to store a string. Is this
>> > possible?
>>
>> Maybe that help?
>> ,----
>> | ELISP> (setq B '(2 "some text" message nil))
>> | (2 "some text" message nil)
>> |
>> | ELISP> (if (and (find-if 'numberp B)
>> |                 (find-if 'stringp B)
>> |                 (find-if 'functionp B)
>> |                 (null (car (last B))))
>> |            t
>> |            nil)
>> | t
>> `----
>
> Partly. This is an 'object' and not a list of objects. But I
> understand correctly that it is not possible to define real objects?
> What I would like is something like (C++ code):
>
> class Object {
>     String type;
>     String description;
>     String functionname;
>     String displayString;
> }
>
> std::vector <Object> objectVector;
>
> When given a certain type I then need to retreive the 'object' from
> the list to use.

There is no class in elisp but you have defstruct (be sure to require 'cl)

,----
| ELISP> (defstruct Object type description functionname displaystring)
| Object
| ELISP> (defvar test-obj (make-Object :type 1 :description "test" 
:functionname 'message :displaystring nil))
| test-obj
| ELISP> (Object-type test-obj)
| 1
| ELISP> (Object-functionname test-obj)
| message
| ELISP> (Object-description test-obj)
| "test"
`----


-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France





reply via email to

[Prev in Thread] Current Thread [Next in Thread]