Paste: rvalue/lvalue overloading

Author: kssreeram
Mode: factor
Date: Thu, 17 Jun 2010 03:12:31
Plain Text |
// the 'wrap' procedure takes multiple values as input
// and returns an equal number of values.
// for each argument,
// the return value is a pointer to the argument if the argument is a lvalue
// and a copy of the argument if the argument is a rvalue
// but it doesn't work because clay does not support
// rvalue/lvalue overloading for varargs.

procedure wrap;
overload wrap(rvalue first, = first, ...wrap(;
overload wrap(lvalue first, = &first, ...wrap(;
overload wrap() = ;

main() {
    var x = 10;

    // call 'wrap' and put it's results in a tuple
    var a = (...wrap(10, x, 10, x));


    // expected output:
    // Tuple[Int32, Pointer[Int32], Int32, Pointer[Int32]]

    // received output:
    // Tuple[Int32, Pointer[Int32], Pointer[Int32], Pointer[Int32]]

New Annotation