From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Elisp printer Date: Tue, 07 Mar 2017 23:39:55 -0500 Message-ID: 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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1488948358 27048 195.159.176.226 (8 Mar 2017 04:45:58 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 8 Mar 2017 04:45:58 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Mar 08 05:45:54 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 1clTU0-0006Tp-Us for ged-emacs-devel@m.gmane.org; Wed, 08 Mar 2017 05:45:53 +0100 Original-Received: from localhost ([::1]:54046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clTU7-0002gi-5W for ged-emacs-devel@m.gmane.org; Tue, 07 Mar 2017 23:45:59 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clTTU-0002gT-Ql for emacs-devel@gnu.org; Tue, 07 Mar 2017 23:45:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clTTR-0002OJ-L2 for emacs-devel@gnu.org; Tue, 07 Mar 2017 23:45:20 -0500 Original-Received: from [195.159.176.226] (port=34491 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1clTTR-0002O0-Dj for emacs-devel@gnu.org; Tue, 07 Mar 2017 23:45:17 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1clTTF-00023q-MQ for emacs-devel@gnu.org; Wed, 08 Mar 2017 05:45:05 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 53 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:x/Kac6kiF0QM2GtgTrojcu286C8= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 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:212829 Archived-At: > I was wondering about this a while ago and thinking that maybe it could > be done without C changes by repurposing the extra arguments to > make-byte-code. The idea here would be to let cl-defsubst take a new > :type argument other than 'vector or 'list, meaning "use > make-byte-code"; and set the :initial-offset to skip over the stuff > necessary for the bytecode. Yes, that can be done fairly easily. But that doesn't give you callable functions: it just gives you structs represented by those special "compiled-function" vectors. E.g. thunk.el creates its thunks with: (defmacro thunk-delay (&rest body) "Delay the evaluation of BODY." (declare (debug t)) (let ((forced (make-symbol "forced")) (val (make-symbol "val"))) `(let (,forced ,val) (lambda (&optional check) (if check ,forced (unless ,forced (setf ,val (progn ,@body)) (setf ,forced t)) ,val))))) so we'd need some way to specify both the function's body and its "struct" at the same time. What I was thinking of was something like (callable-defstruct thunk val forced) (defmacro thunk-delay (&rest body) "Delay the evaluation of BODY." (declare (debug t)) `(make-thunk (&optional check) (if check forced (unless forced (setq val (progn ,@body)) (setq forced t)) val))) The idea would be that `forced` and `val` would be fields of the "callable-struct" and would be accessible directly from the body of the function (as well as from the outside via thunk-val and thunk-forced accessors). That would require changes to the byte-compiler (mostly in cconv.el) but it can probably be made to work without significant changes at the C level. Stefan