From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chris Marusich Subject: Re: Mysterious error while refactoring guix/scripts/system.scm Date: Sat, 24 Sep 2016 12:54:19 -0700 Message-ID: <87zimxdqfo.fsf@gmail.com> References: <87wpjxhx7z.fsf@gmail.com> <87poppq85f.fsf@igalia.com> <8737md3x5a.fsf@gmail.com> <87k2ezzi5c.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnt2u-000163-4k for guix-devel@gnu.org; Sat, 24 Sep 2016 15:55:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bnt2q-00075G-Sr for guix-devel@gnu.org; Sat, 24 Sep 2016 15:55:36 -0400 In-Reply-To: <87k2ezzi5c.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Mon, 29 Aug 2016 17:53:03 +0200") 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: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Ludo=E2=80=99, Thank you for getting back to me! ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Hi Chris, and sorry for the delay! > > Chris Marusich skribis: > >> Backtrace: >> In ice-9/boot-9.scm: >> 157: 15 [catch #t # ...] >> In unknown file: >> ?: 14 [apply-smob/1 #] >> In ice-9/boot-9.scm: >> 63: 13 [call-with-prompt prompt0 ...] >> In ice-9/eval.scm: >> 432: 12 [eval # #] >> In ice-9/boot-9.scm: >> 2401: 11 [save-module-excursion #] >> 4050: 10 [#] >> 1724: 9 [%start-stack load-stack ...] >> 1729: 8 [#] >> In unknown file: >> ?: 7 [primitive-load "/root/guix/scripts/guix"] >> In guix/ui.scm: >> 1209: 6 [run-guix-command system "list-generations"] >> In ice-9/boot-9.scm: >> 157: 5 [catch srfi-34 # ...] >> 157: 4 [catch system-error ...] >> In guix/scripts/system.scm: >> 884: 3 [#] >> 818: 2 [process-command list-generations () ...] >> In guix/store.scm: >> 1182: 1 [run-with-store # ...] >> In unknown file: >> ?: 0 [# #] >> >> ERROR: In procedure #: >> ERROR: Wrong type to apply: # > > This means that we=E2=80=99re trying to invoke #, but > # is not a procedure. > > Note that this is from within =E2=80=98run-to-store=E2=80=99, which is th= e procedure to > =E2=80=9Crun=E2=80=9D a monadic value. So in effect, what happened is eq= uivalent to: > > > scheme@(guile-user)> ,use(guix monads) > scheme@(guile-user)> ,use(guix store) > scheme@(guile-user)> (with-store s > (run-with-store s *unspecified*)) > ERROR: In procedure #: > ERROR: Wrong type to apply: # > > > The bug here is in fact a type error: =E2=80=98run-with-store=E2=80=99 ex= pect a monadic > value, but what we have here is a regular value. > > To =E2=80=9Cfix=E2=80=9D it, we need: > > > scheme@(guile-user)> (with-store s > (run-with-store s > (with-monad %store-monad (return *unspecified*)))) > > > =E2=80=A6 where =E2=80=98return=E2=80=99 procedure a monadic value from a= normal value. > > In your case, =E2=80=98list-generations=E2=80=99 is not a monadic procedu= re (a procedure > that returns a monadic value), so in this patch: > > (run-with-store store > =E2=80=A6 > (list-generations)) > > =E2=80=A6 triggers this very type error. I see. I've read the sections in the manual about gexps, and I've peeked at the gexp code. I thought that basically I could use run-with-store to run any Guile code I want, but I seem to be missing something. I will try experimenting with monads and the store to learn more and hopefully avoid surprises like this going forward. > I imagine this may be more than you wanted to learn. ;-) > Monads in a dynamically typed setting are kinda annoying because of > this. I appreciate the info. Hopefully I will fully understand it soon. >> (define (process-command command args opts) >> "Process COMMAND, one of the 'guix system' sub-commands. ARGS is its >> argument list and OPTS is the option alist." >> - (case command >> - ((list-generations) >> - ;; List generations. No need to connect to the daemon, etc. >> - (let ((pattern (match args >> - (() "") >> - ((pattern) pattern) >> - (x (leave (_ "wrong number of arguments~%")))))) >> - (list-generations pattern))) >> - (else >> - (process-action command args opts)))) >> + (with-store store >> + (set-build-options-from-command-line store opts) >> + >> + (run-with-store store >> + (mbegin %store-monad >> + (set-guile-for-build (default-guile)) >> + (case command >> + ((list-generations) >> + (let ((pattern (match args >> + (() "") >> + ((pattern) pattern) >> + (x (leave (_ "wrong number of arguments~%")= ))))) >> + (list-generations pattern))) >> + (else >> + (process-action command args opts)))) >> + #:system (assoc-ref opts 'system)))) > > As the comment above suggests, the idea here was to avoid connecting to > the daemon for operations that do not need it, such as > =E2=80=98list-generations=E2=80=99. I think we should preserve this prop= erty. The reason I wanted to perform this refactoring in the first place is because I'd like to add a new procedure to guix/scripts/system.scm called 'switch-to-system-generation'. Because this new procedure calls other procedures which seem to require access to the store, I thought I would need to call 'switch-to-system-generation' via 'run-with-store'. Am I just confused? In particular, 'switch-to-system-generation' will eventually call the existing procedure 'grub-configuration-file' (defined in gnu/system/grub.scm). As I understand it, 'grub-configuration-file' returns a derivation that builds a GRUB configuration file. This existing 'grub-configuration-file' procedure does a lot with the store and gexps. I thought that if I didn't use 'run-with-store' to run 'switch-to-system-generation', it wouldn't work because 'grub-configuration-file' wouldn't work. > Thanks for your work! I=E2=80=99m sorry this is more painful than I thou= ght. > :-/ > > Ludo=E2=80=99. I'm happy to help. I just wish I understood these monads better. And I wish I had more time to work on it! Anyway, I'll keep at it. =2D-=20 Chris --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJX5tnxAAoJEN1AmhXYIkadtVUQAJWVWC9XLhEBtRqRaRvQRxrj 3Q74sMExm6oiDb3QijJjRXtgGdTaBOVDvKw4Ac/LhvS+5FV4E/oyfpa6ec9E+JIH Ii3/hevD+NuUPtoVQyEgiPz2TdfBGNfb3uAei1OFHRp5UvpMf7p/4Ooux3eNZZE/ 6UIHwubvVKkfWNrp5WWTPyzNlHbxgIcM9sB9/5PU1qNo3nHDcLjfobZQs3d47Mbh zZYVJBONLBYuQOnIbNp/UcDnDPvhLAYWARaAnHwt1/v15Bt3zTKB/QQ/U/KjDQkv RMQdLlE+deOSFkWOB7LNVokBYTJ0lx9p1k4eX3nHk7hiaYay+REFg43Ru7Wijx0H kLTb4bnMtGu9JWAJNoBQeY/7qlD0vlwSGyR07wTP1iL1/8ftylp0BwghGJym/Hsp bbyV6HfPXXxOT7c1HApWKk6XhL42MLCehr5kAoglNxvVAeoQ5XbckDJCMRJsoUzr zx9hUO0eHJeBpXLeLFYcG59Hjd0Za8GSyf1YNsagDbq2l17TtrOJHf7i9neIZYsW Jt4rge0SkQmzu5cgRTVO1kaSUJoRtHFN1+iyLpgyKlQe11W+1yZDqn2cRWldo+36 aRSADRN25l7veidzkTMcNfm1YSHgleW3fMuOUtYMKLPt12yt328C/0RKl/rz0r51 pB6yk1xTxgoiaLTSHmuZ =5Gcz -----END PGP SIGNATURE----- --=-=-=--