guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nesting with-imported-modules


From: Ricardo Wurmus
Subject: Re: nesting with-imported-modules
Date: Thu, 20 Feb 2020 10:01:05 +0100
User-agent: mu4e 1.2.0; emacs 26.3

Ludovic Courtès <address@hidden> writes:

> Hello!
>
> Ricardo Wurmus <address@hidden> skribis:
>
>> it seems that it is impossible to nest with-imported-modules.  A gexp
>> that is wrapped in multiple layers of with-imported-modules won’t depend
>> on the list of all mentioned modules but only on the outermost.
>>
>> This is because with-imported-modules sets the current-imported-modules
>> parameter without checking if the parameter already has a value.
>>
>> Should nesting be supported?  It seems useful.
>
> Is it?  :-)
>
> My impression is that one would always write:
>
>   (with-imported-modules … #~(…))
>
> or possibly combining multiple expressions:
>
>   (define e1 (with-imported-modules … #~(…)))
>   (define e2 (with-imported-modules … #~(… #$e1 …)))
>
> in which case modules are appended.
>
> I couldn’t think of a use case where one would literally write:
>
>   (with-imported-modules …
>     (with-imported-modules …
>       #~(…)))


No, I’m not writing this literally, but I have an expression that uses
(guix search-paths), for example.  Then I have another procedure that
takes this expression and wraps it with an expression that uses (gnu
build linux-container).

--8<---------------cut here---------------start------------->8---
(define (containerize exp)
  (with-imported-modules (… (gnu build linux-container) …)
    #~(begin
        (use-modules (gnu build linux-container))
        …
        #$exp)))

(define (generate-exp)
  (define exp
    (with-imported-modules (… (guix search-paths) …)
      #~(begin
          (use-modules (guix search-paths))
          …)))
   (if container? (containerize exp) exp))
--8<---------------cut here---------------end--------------->8---

The observed effect was that only one of the with-imported-modules calls
had any effect on the final expression.

--
Ricardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]