This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Multiple values


If one wants to pass around multiple values from function to function,
does Kawa actually make it more efficient to use 'values' and 'let-values'
for this than to pack the values into lists and then unpack again?

Two disadvantages of 'values' and its helpers that occur to me are that:

1) You can't declare the return types expected, so you lose on type
security. Since a multiple-value is just a product type, one could imagine
a return-type specification such as

  (define (sum-and-difference (x <int>) (y <int>)) <int> * <int>
    (values (+ x y) (- x y))
  )

but we don't have this.

(Since you _can_ pack values into lists, which are product types anyway,
one might ask how it benefits the semantics of Scheme to have 'values' as
well, which does the same thing in a different way but without any extra
type security.)

2) They don't work with the list recursion functions such as 'fold'. I'm
using 'fold' a lot, often in situations where the function that it applies
to each element has to return more than one value:

  (fold (lambda (this-element accumulation) 
          (BigFn this-element accumulation)
        )
        empty-accumulation
        elements
  ) 

and I want the accumulation and the result of BigFn to consist of several
values. I presume that making BigFn return via a 'values' and then doing a
'let-values' on the accumulation argument to the lambda function would not
work - or would it?

Jocelyn Paine
http://www.ifs.org.uk/~popx/
+44 (0)7768 534 091 




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]