Ticket #142 (new task)

Opened 3 months ago

Last modified 3 months ago

cannot pass arguments to varargs function to another varargs function

Reported by: jon Assigned to: dr2chase
Priority: major Milestone:
Component: interpreter Version:
Keywords: Cc:

Description

Calling foo and bar with the same arguments should yield the same output.

component q
export Executable

bar(x:Any...) = do println i, i <- x end
foo(x:Any...) = bar(x)

run(args:String...) = do
    println "foo"
    foo(1,2)
    println "bar"
    bar(1,2)
end

end

But instead it produces this output:

foo
[0#2](immutable) = [ 1 2 ]
bar
1
2

A similar thing in Java works:

public class x{

    public static void bar( String... f ){
        for ( String z : f ){
            System.out.println( z );
        }
    }

    public static void foo( String... f ){
        bar(f);
    }

    public static void main( String... args ){
        System.out.println( "foo" );
        foo( "1", "2", "3" );
        System.out.println( "bar" );
        bar( "1", "2", "3" );
    }
}

Output:

foo
1
2
3
bar
1
2
3

Is it right for the interpreter to wrap varargs with an array?

Change History

07/02/08 07:23:37 changed by jon

Victor showed me that this behavior is ok but this program definately behaves incorrectly.

component q
export Executable

bar(x:Any...) = do 
    println x
    println i, i <- x
end

foo(x:Any...) = do println x; bar(x...); end

run(args:String...) = do
    println "foo"
    foo(1,2)
    println "bar"
    bar(1,2)
end

end

Output:

foo
[0#2](immutable) = [ 1 2 ]
[0#0](immutable) = []
bar
[0#2](immutable) = [ 1 2 ]
1
2

The bar(x...) in foo() constructs an empty list somehow.