[chuck-users] wishlist for the new year

Hans Aberg haberg at math.su.se
Mon Jan 11 15:30:49 EST 2010


This may in fact cause problems in ChucK with its heavy overloading of  
the Chuck operator not => but perhaps with the new <=.

One would expect
   1 => foo => bar;
to bind to the left, as
   (1 => foo) => bar;
This will then also work with input streams (not yet implemented in  
ChucK):
   chin => foo => bar;
should mean: first foo(chin), and pass the return value to bar.

Now reverse this, using <=. If it works like an ordinary assignment,  
one should write
   bar <= foo <= 1;
and here => should (by common expectation) be binding right:
   bar <= (foo <= 1);
First pass 1 to foo, and the result to bar.

But for output streams, it should bind to the left:
   chout <= foo <= bar;
   (chout <= foo) <= bar;
First pass chout to foo, and the pass the result to bar.

On streams, there is no semantic difference between => and <=; they  
are just used as eye-candy to show the difference between input and  
output.

But for assignments, there is a difference in binding to the left and  
to the right.

   Hans


On 11 Jan 2010, at 19:19, mike clemow wrote:

> No, you're not misunderstanding anything!  I got a little  
> confused...  you can do two things with chaining in chuck.  one is a  
> double-assignment (which is what I thought was happening):
>
> 1 => int i => int j;
>
> the other is passing args to functions:
>
> fun int foo(int i)
> {
>    return i+1;
> }
>
> 1 => foo;  // returns 2
>
> but, if we did like you suggested:
>
> fun void bar(int b)
> {
>    <<< "hi", b >>>;
> }
>
> then this:
>
> 1 => foo => bar;
>
> will print "hi 2".  but what i was missing was the fact that 1 =>  
> foo returns 2 and passes that to bar.  which is different from the  
> double assignment.  if foo didn't return an int, the above wouldn't  
> be possible.
>
> for instance, if foo was changed to this:
>
> fun void foo(int i)
> {
>     //return i+1;
>     <<< i >>>;
> }
>
> then the line
>
> 1 => foo => bar;
>
> would fail with this error:
>
> [Untitled 2]:line(12): argument type(s) do not match:
> [Untitled 2]:line(12): ... for function 'bar(...)' ...
> [Untitled 2]:line(12): ...(please check the argument types)



More information about the chuck-users mailing list