From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Leake Newsgroups: gmane.emacs.devel Subject: Re: force initialization of a datatype? Date: Fri, 06 Nov 2015 05:56:33 -0600 Message-ID: <86ziyrwdce.fsf@stephe-leake.org> References: <86lhadybig.fsf@stephe-leake.org> <563A59BD.6010909@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1446811066 18724 80.91.229.3 (6 Nov 2015 11:57:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Nov 2015 11:57:46 +0000 (UTC) Cc: emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Nov 06 12:57:36 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Zufe8-0007dh-Sl for ged-emacs-devel@m.gmane.org; Fri, 06 Nov 2015 12:57:33 +0100 Original-Received: from localhost ([::1]:38118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zufe7-0004qg-Sm for ged-emacs-devel@m.gmane.org; Fri, 06 Nov 2015 06:57:31 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zufe3-0004qX-EV for emacs-devel@gnu.org; Fri, 06 Nov 2015 06:57:28 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zufdz-0004fV-Vb for emacs-devel@gnu.org; Fri, 06 Nov 2015 06:57:27 -0500 Original-Received: from gproxy6-pub.mail.unifiedlayer.com ([67.222.39.168]:59900) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1Zufdz-0004eS-Pf for emacs-devel@gnu.org; Fri, 06 Nov 2015 06:57:23 -0500 Original-Received: (qmail 31092 invoked by uid 0); 6 Nov 2015 11:57:15 -0000 Original-Received: from unknown (HELO cmgw3) (10.0.90.84) by gproxy6.mail.unifiedlayer.com with SMTP; 6 Nov 2015 11:57:15 -0000 Original-Received: from host114.hostmonster.com ([74.220.207.114]) by cmgw3 with id eJx31r0152UdiVW01Jx6WQ; Fri, 06 Nov 2015 11:57:12 -0700 X-Authority-Analysis: v=2.1 cv=Caqbutbl c=1 sm=1 tr=0 a=CQdxDb2CKd3SRg4I0/XZPQ==:117 a=CQdxDb2CKd3SRg4I0/XZPQ==:17 a=DsvgjBjRAAAA:8 a=f5113yIGAAAA:8 a=9i_RQKNPAAAA:8 a=hEr_IkYJT6EA:10 a=x_XPkuGwIRMA:10 a=qtqOOiqGOCEA:10 a=vaJtXVxTAAAA:8 a=mDV3o1hIAAAA:8 a=V5f-QR6cfl8v2RFE6o8A:9 a=Hpb-6Wn6hP8A:10 Original-Received: from [76.218.37.33] (port=58121 helo=TAKVER2) by host114.hostmonster.com with esmtpa (Exim 4.84) (envelope-from ) id 1Zufdh-0002t3-Vi; Fri, 06 Nov 2015 04:57:06 -0700 In-Reply-To: <563A59BD.6010909@yandex.ru> (Dmitry Gutov's message of "Wed, 4 Nov 2015 21:17:17 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (windows-nt) X-Identified-User: {2442:host114.hostmonster.com:stephele:stephe-leake.org} {sentby:smtp auth 76.218.37.33 authed with stephen_leake@stephe-leake.org} X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 67.222.39.168 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:193406 Archived-At: Dmitry Gutov writes: > On 11/04/2015 06:28 PM, Stephen Leake wrote: > >> (defun make-path-iterator () >> (let ((result (vector 'cl-struct-path-iterator ))) >> >> )) >> >> This code compiles and runs correctly, but I'm wondering if it is >> acceptable style. Is there a better way to accomplish this for >> cl-defstruct? > > Using `vector' looks wrong. I'm not too familiar with constructor > syntax, but you can process each slot value before an instance gets > constructed. See the example with &aux in > http://www.gnu.org/software/emacs/manual/html_node/cl/Structures.html, > or package-desc-from-define in package.el. Thanks for the pointers. > I'm not sure whether you can use a keyword argument with the same name > as the slot, and convert the passed in value. That's something to try. This works: (cl-defstruct (path-iterator (:constructor nil) (:constructor make-path-iterator (user-path &aux (path (path-iter-to-truename user-path)))) (:conc-name path-iter-) (:copier nil)) path ;; user-path converted to absolute directory file truenames. (defun path-iter-to-truename (path) ...) However, `xref-find-definitions' doesn't find `make-path-iterator', and there's no place to put a doc string for `make-path-iterator'. I'll see if I can fix `xref-find-definitions'. -- -- Stephe