From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: Something like an array (list) of a class Date: Sun, 12 Apr 2009 09:15:21 -0700 Message-ID: <001401c9bb89$e18f0510$0200a8c0@us.oracle.com> References: <665d0b7a-3230-4123-b9f4-2a645f44dd1c@a7g2000yqk.googlegroups.com><9fe617de-13d8-4dbc-82f8-3cc575008e48@o18g2000vbi.googlegroups.com> <87tz4ub8ow.fsf@tux.homenetwork> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1239552956 13282 80.91.229.12 (12 Apr 2009 16:15:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 12 Apr 2009 16:15:56 +0000 (UTC) To: , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Apr 12 18:17:15 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 1Lt2Ml-0002RT-VC for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Apr 2009 18:17:08 +0200 Original-Received: from localhost ([127.0.0.1]:51222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lt2LN-0000Qm-DK for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Apr 2009 12:15:41 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lt2L0-0000Qh-3r for help-gnu-emacs@gnu.org; Sun, 12 Apr 2009 12:15:18 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lt2Ku-0000QQ-9l for help-gnu-emacs@gnu.org; Sun, 12 Apr 2009 12:15:16 -0400 Original-Received: from [199.232.76.173] (port=58500 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lt2Ku-0000QN-4G for help-gnu-emacs@gnu.org; Sun, 12 Apr 2009 12:15:12 -0400 Original-Received: from acsinet11.oracle.com ([141.146.126.233]:34599) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lt2Kt-0007nt-LZ for help-gnu-emacs@gnu.org; Sun, 12 Apr 2009 12:15:11 -0400 Original-Received: from rgminet15.oracle.com (rcsinet15.oracle.com [148.87.113.117]) by acsinet11.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n3CGGLQ7026181 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 12 Apr 2009 16:16:22 GMT Original-Received: from acsmt706.oracle.com (acsmt706.oracle.com [141.146.40.84]) by rgminet15.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n3CGF9GO021913; Sun, 12 Apr 2009 16:15:10 GMT Original-Received: from dradamslap1 (/98.210.250.59) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 12 Apr 2009 09:15:01 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <87tz4ub8ow.fsf@tux.homenetwork> Thread-Index: Acm7RigA2pq0j8b/T5qDiL+0wN20cwAOFovQ X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350 X-Source-IP: acsmt706.oracle.com [141.146.40.84] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A010202.49E21387.00AF:SCFMA4539814,ss=1,fgs=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) 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:63692 Archived-At: > >> > I would like to make some datadriven functionality. Is=20 > >> > 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? > >> > >> ,---- > >> | ELISP> (setq B '(2 "some text" message nil)) > >> | (2 "some text" message nil) > >> | > >> | ELISP> (if (and (find-if 'numberp B) > >> | =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (find-if 'stringp B) > >> | =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (find-if 'functionp B) > >> | =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (null (car (last B)))) > >> | =A0 =A0 =A0 =A0 =A0 =A0t > >> | =A0 =A0 =A0 =A0 =A0 =A0nil) > >> | 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 objectVector; > > > > When given a certain type I then need to retreive the 'object' from > > the list to use. >=20 > There is no class in elisp but you have defstruct (be sure to=20 > require 'cl) >=20 > ,---- > | ELISP> (defstruct Object type description functionname=20 > | displaystring) > | Object > | ELISP> (defvar test-obj (make-Object :type 1 :description=20 > | "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" > `---- Various books and Web sites about Lisp show you how to implement objects = in Lisp, depending on what you mean by "object" (abstract data type? = mutable object? classes? inheritance?...). In addition to Common Lisp's `defstruct', there is the Common Lisp = Object System (CLOS), but Emacs Lisp support for it is wanting. (From the Elisp = manual: "Some features are too complex or bulky relative to their benefit to Emacs = Lisp programmers. CLOS and Common Lisp streams are fine examples of this = group.") One thing you might also consider (again, depending on what you = need/want), is that Emacs Lisp does provide a type-checking mechanism - in the context = of Customize. This is often overlooked or under-exploited. Customize = options can be complex structures whose parts are well typed, and compile-time and = runtime type-checking are available. In addition, you can define initialization = and set/put methods/triggers. Whether you want to use options for your data structures in general is = another question. You would be exploiting the type-definition and type-checking = features of Customize without necessarily wanting to create user-visible options. = But this type manipulation is an existing and powerful Emacs-Lisp feature = that you can use in ways other than those originally intended.