From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: Mysterious error while refactoring guix/scripts/system.scm Date: Fri, 30 Sep 2016 22:36:29 +0200 Message-ID: <87eg41jfaq.fsf@gnu.org> References: <87wpjxhx7z.fsf@gmail.com> <87poppq85f.fsf@igalia.com> <8737md3x5a.fsf@gmail.com> <87k2ezzi5c.fsf@gnu.org> <87zimxdqfo.fsf@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]:39989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq4Xw-00007F-U7 for guix-devel@gnu.org; Fri, 30 Sep 2016 16:36:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bq4Xq-0002v2-TJ for guix-devel@gnu.org; Fri, 30 Sep 2016 16:36:39 -0400 In-Reply-To: <87zimxdqfo.fsf@gmail.com> (Chris Marusich's message of "Sat, 24 Sep 2016 12:54:19 -0700") 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: Chris Marusich Cc: guix-devel@gnu.org Hello, Chris Marusich skribis: > 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? Essentially, to write a procedure that needs to access the store, you need to write a =E2=80=9Cmonadic procedure=E2=80=9D=E2=80=94i.e., a procedu= re that returns a value in the =E2=80=9Cstore monad=E2=80=9D instead of a =E2=80=9Cnormal val= ue.=E2=80=9D To do that, you would write: (define (switch-to-system-generation =E2=80=A6) (with-monad %store-monad (return 'some-value))) ;return this symbol as a monadic value or: (define (switch-to-system-generation =E2=80=A6) (some-monadic-procedure x y z)) ;tail-call a monadic procedure The caller of a monadic procedure must be prepared to =E2=80=9Cunpack=E2=80= =9D its value, using the monadic =E2=80=9Cbind=E2=80=9D operator. The =E2=80=98mle= t=E2=80=99 form does exactly that: (define (the-caller =E2=80=A6) (mlet %store-monad ((result (switch-to-system-generation =E2=80=A6))) =E2=80=A6)) At the bottom, there must be somewhere a call to =E2=80=98run-with-store=E2= =80=99 to =E2=80=9Crun=E2=80=9D the monadic value in the monad (info "(guix) The Stor= e Monad"). This call is already in =E2=80=98process-action=E2=80=99 in (guix scripts s= ystem). > 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. =E2=80=98grub-configuration-file=E2=80=99 is a monadic procedure. Thus, to= =E2=80=9Cunpack=E2=80=9D its return value, you need to bind it, for instance with =E2=80=98mlet=E2=80=99: (mlet %store-monad ((file (grub-configuration-file =E2=80=A6))) =E2=80=A6) or: (with-monad %store-monad (>>=3D (grub-configuration-file =E2=80=A6) (lambda (file) =E2=80=A6))) HTH! Ludo=E2=80=99.