List Info

Thread: Re: lambda with normal block syntax




Re: lambda with normal block syntax
user name
2008-05-26 11:01:24
Hi,

In message "Re: [PATCH] lambda with normal block
syntax"
    on Tue, 27 May 2008 00:45:24 +0900, "Meinrad
Recheis" <meinrad.recheisgmail.com> writes:

|order is important.
|
|x => 2*x
|
|reads without confusion as: "x transforms into 2 times
x".

Indeed order is important.

  x -> x * 2

reads as "member x of reference x times 2" for C
programmers. 
I mean infix -> operator would cause more confusion.  And
of course,
infix => operator destroys the current Ruby syntax.

|while in ruby it would be -> x { 2*x } which reminds me
of the bad
|readability of prefix notation compared to infix notation
|i.e: + 1 2 versus 1 + 2

You should read

  twotimes = -> x {2 * x}

as "twotimes is 2 times x where x is not yet
assigned", here -> works
as incomplete left to right assignment operator.  So,

  twotimes.(4)

becomes "4 -> x {2 * x}" by natural
substitution.  I hope you see
"2 times x where x is 4" in your brain.

							matz.


Re: lambda with normal block syntax
user name
2008-05-26 11:11:14
On May 26, 2008, at 11:01 AM, Yukihiro Matsumoto wrote:

>
> You should read
>
>  twotimes = -> x {2 * x}
>
> as "twotimes is 2 times x where x is not yet
assigned", here -> works
> as incomplete left to right assignment operator.  So,

I think we're all comfortable with the concept--it's just
the notation.

The juxtaposition of = and -> just doesn't sit well with
most of us.

   twotimes = x { 2 * x }

reads better to me, as does

   twotimes = fn x -> { 2 * x }

as does

   twotimes = λ x -> { 2 * x }

and

   twotimes = lambda {|x| 2 * x }


In fact, given a change that allows block arguments to be
like method  
arguments, then maybe no other change is needed. We can
always alias  
lambda to something shorter, and then everyone is happy

   n_times = λ { |n=2|   λ {|val| n*val}}

   twotimes = n_times[2]
   twotimes[3]



Dave




[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )