[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/2] emacs: Add 'guix-package-from-file' command.
From: |
Ludovic Courtès |
Subject: |
Re: [PATCH 2/2] emacs: Add 'guix-package-from-file' command. |
Date: |
Sun, 08 May 2016 20:40:58 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Alex Kost <address@hidden> skribis:
> * emacs/guix-main.scm (register-package, packages-from-file): New procedures.
> (%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.
[...]
> address@hidden M-x guix-package-from-file
> +Display package that the code within the specified file evaluates to.
> address@hidden 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 ‘table’ a promise…
> + (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*)))))))
… by wrapping ‘vhash-consq’ in ‘delay’.
I think this approach is OK.
The rest LGTM!
To avoid ‘set!’ 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’t need 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’.