something wrong with argument binding in function calls

1 view
Skip to first unread message

Abhijit Mahabal

unread,
Mar 2, 2005, 12:21:56 PM3/2/05
to perl6-c...@perl.org
the file examples/hanoi.p6 should work correctly, but does not.
Something is going wrong in the recursion.

=========================
[amahabal@satchel trunk]$ ./pugs examples/hanoi.p6
ndisks = 3
AS
AS
SS
AB
SS
SB
SB
=========================

A modified version that also prints out what arguments the function saw
spews this out:

=========================
[amahabal@satchel trunk]$ ./pugs ../../b2.p6 3
ndisks = 3
Called for 3 discs with A B S
Called for 2 discs with A S S
Called for 1 discs with A S S
Called for 0 discs with A S S
Disk 1 from A to S
Called for 0 discs with S S S
......
=========================

So something is wrong somewhere. Could it be that the function is
treating its variables not as "my" but something else? That is my guess,
but that something else is not the perl5 "local" or the perl5 "our"
because they would not produce this particular error.

I plan to explore this more later today.

--abhijit

Abhijit Mahabal

unread,
Mar 2, 2005, 1:13:52 PM3/2/05
to perl6-c...@perl.org
A simpler buggy version:
====================
sub g($x, $y){
say "$x $y";
h($y, $x);
}

sub h($x, $y){
say "$x $y";
}

g(10, 15);
=====================
This prints:
10 15
15 15


--abhijit

Jonathan Scott Duff

unread,
Mar 2, 2005, 2:18:27 PM3/2/05
to Abhijit Mahabal, perl6-c...@perl.org
On Wed, Mar 02, 2005 at 12:21:56PM -0500, Abhijit Mahabal wrote:
> the file examples/hanoi.p6 should work correctly, but does not.
> Something is going wrong in the recursion.
[ *poof* ]

>
> I plan to explore this more later today.

Great! I'd checked that example in knowing that there was a problem, but
I haven't had the time to track it down. Perhaps your simpler exposition
of the problem could be the basis of a good test.

-Scott
--
Jonathan Scott Duff
du...@pobox.com

Reply all
Reply to author
Forward
0 new messages