guile-user
[Top][All Lists]
Advanced

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

Re: question about values


From: Massimiliano Gubinelli
Subject: Re: question about values
Date: Wed, 18 Mar 2020 12:06:40 +0100

Let me precise my concerns.

I know I can do 

(begin
 (initialization-code)
 (let ((vals (call-with-values (lambda () (bar)) (lambda vals vals))))
  (finalization)
  (apply values vals)))

this is the hack I'm using now in my code. But my question is: does it incur 
performance penalties (it will be a macro, so used also in many other context 
where bar returns only a single value)

Is there no better way to have multiple values interact in a composable way 
with macros???

Max


> On 18. Mar 2020, at 10:55, Massimiliano Gubinelli <address@hidden> wrote:
> 
> Thanks Taylan,
> 
>> On 18. Mar 2020, at 07:12, Taylan Kammer <address@hidden> wrote:
>> 
>> On 18.03.2020 00:50, Massimiliano Gubinelli wrote:
>>> (let ((a (values "a" "b" "c"))) a)
>> 
>> The result of (values x y z) is not a kind of object that contains three 
>> values (like a list or vector).  It's three separate values that would need 
>> to be put into three separate variables.  But you're only naming one 
>> variable (a).  So strictly speaking the code is "wrong".
>> 
>> In Guile 1.8, multiple values were actually put into some special kind of 
>> object (which was not very efficient) so code like that still somehow worked 
>> even thought it's technically wrong.
>> 
>> Starting from Guile 2.0, providing multiple values in a context where only 
>> one is expected causes the extra values to be ignored.
>> 
>> 
> 
> I understand the point but then it comes to the problem how to handle this in 
> macros. For example if bar is a proceduce which returns multiple values and I 
> have a macro "my-macro" which wraps the call with some initialization and 
> finalization code and I write
> 
> (my-macro (bar))
> 
> how to write this macro without knowing if bar is returning multiple values 
> or not? For example I would like the code above to expand into
> 
> (begin
> (initialization-code)
> (let ((ret (bar))) 
>  (finalization-code) 
>  ret))
> 
> 
> But this does not work as shown by the example above. How to implement this 
> macro correctly?
> 
> best
> Max
> 
> 
>> Happy to answer further questions about this.  Multiple-values can be a 
>> tricky concept to grasp because most other programming languages don't have 
>> it.
>> 
>> - Taylan



reply via email to

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