help-guix
[Top][All Lists]
Advanced

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

Re: How do I make a manifest file that installs a specific version of a


From: Ludovic Courtès
Subject: Re: How do I make a manifest file that installs a specific version of a dependency?
Date: Mon, 13 Mar 2017 10:20:03 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Chris Marusich <address@hidden> skribis:

> Just for fun, I tried running some commands in a REPL.  I wanted to find
> out why the "list" procedure was being used here.  What I saw was this:
>
> scheme@(guile-user)> (specification->package+output "address@hidden:jdk")
> $6 = #<package address@hidden gnu/packages/java.scm:347 39a6000>
> $7 = "jdk"
> scheme@(guile-user)> (list (specification->package+output 
> "address@hidden:jdk"))
> $8 = (#<package address@hidden gnu/packages/java.scm:347 39a6000>)
> scheme@(guile-user)> (map (compose list specification->package+output) 
> '("address@hidden:jdk"))
> $9 = ((#<package address@hidden gnu/packages/java.scm:347 39a6000> "jdk"))
> scheme@(guile-user)>
>
> Why does the string "jdk" appear in $9 but not in $8?  It looks like the
> list procedure ignored the second value (the "jdk" string) when
> producing $8, but not when producing $9.  Is that true?  Why?

‘specification->package+output’ returns two values; in Scheme that
really means returning two values, and this is completely different from
returning a two-element list or anything like that (info "(guile)
Multiple Values").

Guile automatically truncates multiple-value returns: if a procedure
returns, say, two values but its continuation expects only one, then the
second return value is dismissed.  Like this:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (values 1 2)
$2 = 1
$3 = 2    ;the REPL lists all the return values
scheme@(guile-user)> (list (values 1 2))
$4 = (1)  ;continuation of the ‘values’ form expects one value
--8<---------------cut here---------------end--------------->8---

‘call-with-values’ is the primitive that allows you to retrieve all the
return values:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (call-with-values (lambda () (values 1 2))
                       list)  ;continuation expects any number of values
$5 = (1 2)
scheme@(guile-user)> (call-with-values (lambda () (values 1 2))
                       (lambda (a b)  ;continuation expects two values
                         (list b a)))
$6 = (2 1)
--8<---------------cut here---------------end--------------->8---

I must say that this is more complicated than I’d like in the case of
‘specification->package+output’.

HTH!

Ludo’.



reply via email to

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