From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH 2/2] emacs: Add 'guix-package-from-file' command. Date: Sun, 08 May 2016 20:40:58 +0200 Message-ID: <87d1ow4clh.fsf@gnu.org> References: <1462704662-18972-1-git-send-email-alezost@gmail.com> <1462704662-18972-3-git-send-email-alezost@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azTdc-0001nw-PC for guix-devel@gnu.org; Sun, 08 May 2016 14:41:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1azTdY-0001eW-Cb for guix-devel@gnu.org; Sun, 08 May 2016 14:41:08 -0400 In-Reply-To: <1462704662-18972-3-git-send-email-alezost@gmail.com> (Alex Kost's message of "Sun, 8 May 2016 13:51:02 +0300") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Alex Kost Cc: guix-devel@gnu.org Alex Kost skribis: > * emacs/guix-main.scm (register-package, packages-from-file): New procedu= res. > (%patterns-makers): Add 'from-file' search type. > * emacs/guix-messages.el (guix-messages): Add messages for it. > * emacs/guix-ui-package.el (guix-package-from-file): New command. > (guix-package-info-insert-location): Adjust for 'from-file' type. > * doc/emacs.texi (Emacs Commands): Document it. [...] > +@item M-x guix-package-from-file > +Display package that the code within the specified file evaluates to. > +@xref{Invoking guix package, @code{--install-from-file}}, for an example > +of how a file may look like. s/how a file/what such a file/ > +(define-values (package-by-address > + register-package) > + (let* ((table (delay (fold-packages > + (lambda (package table) > + (vhash-consq (object-address package) > + package table)) > + vlist-null))) > + (table* (lambda () > + (if (promise? table) > + (force table) > + table)))) It may be easier to always make =E2=80=98table=E2=80=99 a promise=E2=80=A6 > + (values > + (lambda (address) > + "Return package by its object ADDRESS." > + (match (vhash-assq address (table*)) > + ((_ . package) package) > + (_ #f))) > + (lambda (package) > + "Register PACKAGE by its 'object-address', so that later > +'package-by-address' can be used to access it." > + (set! table > + (vhash-consq (object-address package) > + package (table*))))))) =E2=80=A6 by wrapping =E2=80=98vhash-consq=E2=80=99 in =E2=80=98delay=E2=80= =99. I think this approach is OK. The rest LGTM! To avoid =E2=80=98set!=E2=80=99 above, the options that come to mind would = be: 1. To not provide M-x guix-package-from-file and instead provide, say, M-x guix-install-package-from-file. That way, we wouldn=E2=80=99t nee= d to remember the package. 2. To thread the state, consisting mainly of lookup tables/procedures, through the state monad, and to change the state in this particular case. Converting to this new style would be quite a bit of work, for just this one special case. Thanks, Ludo=E2=80=99.