Chris Marusich <cmmarus...@gmail.com> 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 "icedtea@2.6.9:jdk") > $6 = #<package icedtea@2.6.9 gnu/packages/java.scm:347 39a6000> > $7 = "jdk" > scheme@(guile-user)> (list (specification->package+output > "icedtea@2.6.9:jdk")) > $8 = (#<package icedtea@2.6.9 gnu/packages/java.scm:347 39a6000>) > scheme@(guile-user)> (map (compose list specification->package+output) > '("icedtea@2.6.9:jdk")) > $9 = ((#<package icedtea@2.6.9 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’.