unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alex Kost <alezost@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guix-devel@gnu.org
Subject: Re: [PATCH 2/2] emacs: Add 'guix-package-from-file' command.
Date: Mon, 09 May 2016 11:25:05 +0300	[thread overview]
Message-ID: <87zirzocym.fsf@gmail.com> (raw)
In-Reply-To: 87d1ow4clh.fsf@gnu.org

[-- Attachment #1: Type: text/plain, Size: 3430 bytes --]

Ludovic Courtès (2016-05-08 21:40 +0300) wrote:

> Alex Kost <alezost@gmail.com> 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.
>
> [...]
>
>> +@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/

Fixed.

>> +(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…

I don't like this 'table*' procedure (especially its name), and I would
like to get rid of it, but I couldn't make your suggestion work…

>> +    (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 tried it, but I got an error I don't know what to do with:

  Throw to key `vm-error' with args `(vm-run "VM: Stack overflow" ())'.

I attach the file that illustrates this problem.  Here is the recipe to
reproduce it using geiser:

1. M-x run-guile
2. Open the attached file
3. Evaluate it: C-c C-b

And the last expression leads to an error (at least for me).  Is there
some problem with combining force/delay or did I do something wrong?

> 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.

I don't like this solution.  With "M-x guix-package-from-file" you get a
full-featured *Guix Package Info* buffer, where you can not only install
the package, but download its source, look at its license, inputs,
etc. (and soon it will be possible just to build it without installing).

>   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.

Ouch, this looks scary to me, so I stay on the current solution, but
thanks for the pointers!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: from-file-delay-bug.scm --]
[-- Type: text/x-scheme, Size: 943 bytes --]

(use-modules
 (ice-9 vlist)
 (ice-9 match)
 (gnu packages)
 (gnu packages curl))

(define-values (package-by-address
                register-package)
  (let ((table (delay (fold-packages
                       (lambda (package table)
                         (vhash-consq (object-address package)
                                      package table))
                       vlist-null))))
    (values
     (lambda (address)
       "Return package by its object ADDRESS."
       (match (vhash-assq address (force 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
             (delay (vhash-consq (object-address package)
                                 package (force table))))))))

(register-package curl)

;; This expressions errors:
(package-by-address (object-address curl))

  reply	other threads:[~2016-05-09  8:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-08 10:51 [PATCH 0/2] emacs: Add "M-x guix-package-from-file Alex Kost
2016-05-08 10:51 ` [PATCH 1/2] emacs: main: Remove top-level package tables Alex Kost
2016-05-08 16:54   ` Ludovic Courtès
2016-05-08 10:51 ` [PATCH 2/2] emacs: Add 'guix-package-from-file' command Alex Kost
2016-05-08 18:40   ` Ludovic Courtès
2016-05-09  8:25     ` Alex Kost [this message]
2016-05-09 20:29       ` Ludovic Courtès
2016-05-10  9:09         ` Alex Kost

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zirzocym.fsf@gmail.com \
    --to=alezost@gmail.com \
    --cc=guix-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).