From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: thierry.volpiatto@gmail.com Newsgroups: gmane.emacs.help Subject: Re: Something like an array (list) of a class Date: Sun, 12 Apr 2009 19:15:49 +0200 Message-ID: <878wm5sshm.fsf@tux.homenetwork> References: <665d0b7a-3230-4123-b9f4-2a645f44dd1c@a7g2000yqk.googlegroups.com> <9fe617de-13d8-4dbc-82f8-3cc575008e48@o18g2000vbi.googlegroups.com> <87tz4ub8ow.fsf@tux.homenetwork> <001401c9bb89$e18f0510$0200a8c0@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1239556997 27310 80.91.229.12 (12 Apr 2009 17:23:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 12 Apr 2009 17:23:17 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "Drew Adams" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Apr 12 19:24:36 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 1Lt3Q3-00071m-G1 for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Apr 2009 19:24:35 +0200 Original-Received: from localhost ([127.0.0.1]:57249 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lt3Oe-0001R7-Fn for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Apr 2009 13:23:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lt3OH-0001R2-5d for help-gnu-emacs@gnu.org; Sun, 12 Apr 2009 13:22:45 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lt3OF-0001Qq-Lp for help-gnu-emacs@gnu.org; Sun, 12 Apr 2009 13:22:43 -0400 Original-Received: from [199.232.76.173] (port=42685 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lt3OF-0001Qn-HK for help-gnu-emacs@gnu.org; Sun, 12 Apr 2009 13:22:43 -0400 Original-Received: from fg-out-1718.google.com ([72.14.220.156]:46959) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Lt3OF-0001Ay-0w for help-gnu-emacs@gnu.org; Sun, 12 Apr 2009 13:22:43 -0400 Original-Received: by fg-out-1718.google.com with SMTP id l27so249949fgb.7 for ; Sun, 12 Apr 2009 10:22:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:references :face:date:in-reply-to:message-id:user-agent:mime-version :content-type:content-transfer-encoding; bh=wQnU1w0+CP2Dpd+H1mcy3cU5ura3ilf+iXJ1hV3z4R8=; b=cv0CevPvGeHm+0pFSxH5m2XoUUbYaPV1OQpwZaVHEU7OxufvLeeTnS8fxbktTajOa5 QA46T4hwbdmVdpB6MQfNnuRGNWsWa1n/umem7hPFdyskixIiRfl3MD5fzFxZj07ZdNXq TOQjGE7QnC0sWZbLHgcme9pbcAH+4ywVPLEa0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:face:date:in-reply-to:message-id :user-agent:mime-version:content-type:content-transfer-encoding; b=Lk+FTMKXOxtTSTEuuOasyIZhZ+yHeUkyTT2IBuvrv119DOaQH6eh/qgQjIeE9xgZog /d9hdkLHsefJgNLWYr8nVd22XiZHqiJzq1br063DWGkTuxO/KQIwJS+/s9EGXv5cfoRF UbpLVzLh2FSzpq7g7622ekWJiaHfzLfdDtBL8= Original-Received: by 10.86.82.16 with SMTP id f16mr4130283fgb.26.1239556961250; Sun, 12 Apr 2009 10:22:41 -0700 (PDT) Original-Received: from tux.homenetwork (207.211.85-79.rev.gaoland.net [79.85.211.207]) by mx.google.com with ESMTPS id 4sm5610226fge.18.2009.04.12.10.22.38 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 12 Apr 2009 10:22:40 -0700 (PDT) Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEUHAwNfJRBVTESlTym0 RB/OwKFivhZqAAAACXBIWXMAAAsSAAALEgHS3X78AAAACXZwQWcAAAAwAAAAMADO7oxXAAABeElE QVQ4y3VTW47CMAyMwwUyTfYfUvG/wfC/ET4B0t7/KmsHurRgXFVVPRm/xglhsRj2+npW98G3+Amp tS5BXxl3SqzcXGRuEyf7n5lPA9jXetNPRhE7EJkzfz8YWnIgBSwW95TK4H79/t4GINKNADWj4PgA DiJX/ZxFDzDXeb4oYMw7kNUvyMzcaj3ioICG4hCKEShkPpwQ49Q05nnkGAQLDFDdExjm0qpowBYA Wi61bDlFU1GW0WbY2dSJYX5ZD2S0AiZL+rPyE19TpMzP2IvNWly+NkuWNgD4pO2oL73IQXoSyVX2 NHna7tgadWRXoCdvf2guqEcvGHqZwE520iRD0/QCYiiTE+U21w1Qxvg6iSp9fbIiDCnSAelDkCVF Vn+HekqXzRybwJ40xF4DMRG6SWGK9G1lYzHSxLYEm05GWbpJCB6A9tb9A3BGn2XdwJbS/WuInj74 4QNF8sVFdP3vl+5tgYp4Ev7fyrfFMkXgElDgV4uV/w8TWEeLCIGJ/AAAACV0RVh0Y3JlYXRlLWRh dGUAMjAwOC0wNS0zMVQyMDoxNDoyMiswMDowMAS7YjIAAAARdEVYdGpwZWc6Y29sb3JzcGFjZQAy LHVVnwAAACB0RVh0anBlZzpzYW1wbGluZy1mYWN0b3IAMngyLDF4MSwxeDFJ+qa0AAAAJXRFWHRt b2RpZnktZGF0ZQAyMDA3LTEwLTI4VDE2OjA4OjQ4KzAwOjAw44nspgAAAABJRU5ErkJggg== In-Reply-To: <001401c9bb89$e18f0510$0200a8c0@us.oracle.com> (Drew Adams's message of "Sun, 12 Apr 2009 09:15:21 -0700") User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.92 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:63696 Archived-At: Hi Drew, "Drew Adams" writes: >> >> > 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) >> >> | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (find-if 's= tringp B) >> >> | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (find-if 'f= unctionp B) >> >> | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (null (car = (last B)))) >> >> | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0t >> >> | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=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 runti= me > type-checking are available. In addition, you can define initialization a= nd > set/put methods/triggers. > > Whether you want to use options for your data structures in general is an= other > question. You would be exploiting the type-definition and type-checking f= eatures > of Customize without necessarily wanting to create user-visible options. = But > this type manipulation is an existing and powerful Emacs-Lisp feature tha= t you > can use in ways other than those originally intended. > Very interesting, did you already use this kind of mechanism in some of your programs ? --=20 A + Thierry Volpiatto Location: Saint-Cyr-Sur-Mer - France