From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Lars Brinkhoff Newsgroups: gmane.emacs.devel Subject: Re: User-defined record types Date: Tue, 14 Mar 2017 14:25:50 +0100 Organization: nocrew Message-ID: <86o9x40z35.fsf@molnjunk.nocrew.org> References: <87pokampa4.fsf@ericabrahamsen.net> <8760m2mmlq.fsf@ericabrahamsen.net> <87lguq5r87.fsf@ericabrahamsen.net> <878tp0i74g.fsf@users.sourceforge.net> <87efyg6y0i.fsf_-_@drachen> <87zigwz9wx.fsf@tromey.com> <86bmtbd45s.fsf@molnjunk.nocrew.org> <86bmt42nk2.fsf_-_@molnjunk.nocrew.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1489502481 22837 195.159.176.226 (14 Mar 2017 14:41:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 14 Mar 2017 14:41:21 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cc: tom@tromey.com, emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 14 15:41:16 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cnndN-0004p1-8e for ged-emacs-devel@m.gmane.org; Tue, 14 Mar 2017 15:41:09 +0100 Original-Received: from localhost ([::1]:59827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnndT-00007s-Cr for ged-emacs-devel@m.gmane.org; Tue, 14 Mar 2017 10:41:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57235) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnmSi-00041l-DH for emacs-devel@gnu.org; Tue, 14 Mar 2017 09:26:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnmSf-0005QP-0p for emacs-devel@gnu.org; Tue, 14 Mar 2017 09:26:04 -0400 Original-Received: from molnjunk.nocrew.org ([178.18.91.250]:47802) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnmSe-0005Cu-PU for emacs-devel@gnu.org; Tue, 14 Mar 2017 09:26:00 -0400 Original-Received: from lars by molnjunk.nocrew.org with local (Exim 4.76) (envelope-from ) id 1cnmSU-0002oc-CK; Tue, 14 Mar 2017 14:25:50 +0100 In-Reply-To: (Stefan Monnier's message of "Tue, 14 Mar 2017 09:13:45 -0400") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 178.18.91.250 X-Mailman-Approved-At: Tue, 14 Mar 2017 10:39:06 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:213019 Archived-At: Stefan Monnier wrote: >> diff --git a/src/data.c b/src/data.c >> index ae8dd97..eceb752 100644 >> --- a/src/data.c >> +++ b/src/data.c >> @@ -267,6 +267,7 @@ static void swap_in_symval_forwarding (struct >> Lisp_Symbol *, >> case PVEC_MUTEX: return Qmutex; >> case PVEC_CONDVAR: return Qcondition_variable; >> case PVEC_TERMINAL: return Qterminal; >> + case PVEC_RECORD: return AREF (object, 0); >> /* "Impossible" cases. */ >> case PVEC_XWIDGET: >> case PVEC_OTHER: > > `type-of` is expected to return a symbol. So the above code implies > that `record` objects should have a symbol their slot 0 and that this > symbol should be the record's type name. Right. Fmake_record does check that slot 0 is initialized to a symbol. > Currently EIEIO and `cl-defstruct` indeed puts a symbol in slot 0 but > this symbol is not exactly the struct type, so returning AREF (object, > 0) wouldn't return quite the right value. I don't understand everything about cl-defstruct, and even less about Emacs flavor of generic functions or EIEIO. I have a patch which demostrates how to make cl-defstruct create record instances if you explicitly ask for it. It does put the type name in slot 0. If you pass (:named foo) to cl-defstruct, foo will be put in list or vector slot 0, so I suppose that should work for records too. If you don't use the :named option, it seems there will be no type information in the instances.