[#16611] lambda, ->, haskell, and so on — Dave Thomas <dave@...>

This is one of those e-mails that I know from the start to be futile, =20=

148 messages 2008/05/01
[#16661] Re: lambda, ->, haskell, and so on — Paul Brannan <pbrannan@...> 2008/05/05

On Thu, May 01, 2008 at 12:26:47PM +0900, Dave Thomas wrote:

[#16662] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/05

Hi --

[#16663] Re: lambda, ->, haskell, and so on — ts <decoux@...> 2008/05/05

David A. Black wrote:

[#16664] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/05

Hi --

[#16682] Re: lambda, ->, haskell, and so on — ara howard <ara.t.howard@...> 2008/05/08

[#16684] Re: lambda, ->, haskell, and so on — Michael Neumann <mneumann@...> 2008/05/08

ara howard wrote:

[#16687] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/08

Hi --

[#16691] Re: lambda, ->, haskell, and so on — "ara.t.howard" <ara.t.howard@...> 2008/05/08

[#16692] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/08

Hi --

[#16695] Re: lambda, ->, haskell, and so on — "ara.t.howard" <ara.t.howard@...> 2008/05/08

[#16705] Re: lambda, ->, haskell, and so on — Evan Phoenix <evan@...> 2008/05/11

Not to throw the whole thread into a tizzy again, but why again is:

[#16708] Re: lambda, ->, haskell, and so on — Nobuyoshi Nakada <nobu@...> 2008/05/11

Hi,

[#16720] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/11

Hi,

[#16721] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/12

Hi --

[#16722] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/12

Hi,

[#16723] Re: lambda, ->, haskell, and so on — Evan Phoenix <evan@...> 2008/05/12

[#16724] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/12

Hi,

[#16726] Re: lambda, ->, haskell, and so on — Nathan Weizenbaum <nex342@...> 2008/05/12

What about "fn" or "fun", for "function"?

[#16728] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/12

Hi,

[#16731] Re: lambda, ->, haskell, and so on — Evan Phoenix <evan@...> 2008/05/12

[#16732] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/12

Hi,

[#16759] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/13

Hi --

[#16766] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/14

Hi,

[#16784] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/18

Hi --

[#16795] Re: lambda, ->, haskell, and so on — Nate_Wiger@... 2008/05/19

On Wed, 14 May 2008, David A. Black wrote:

[#16797] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/19

Hi,

[#16798] Re: lambda, ->, haskell, and so on — "Christopher Gill" <gilltots@...> 2008/05/19

how about an uppercase lambda (instead of the usual lowercase one)

[#16802] Re: lambda, ->, haskell, and so on — "Suraj N. Kurapati" <sunaku@...> 2008/05/20

Christopher Gill wrote:

[#16843] Re: lambda, ->, haskell, and so on — "Suraj N. Kurapati" <sunaku@...> 2008/05/22

Suraj N. Kurapati wrote:

[#16846] Re: lambda, ->, haskell, and so on — "Berger, Daniel" <Daniel.Berger@...> 2008/05/22

=20

[#16854] Re: lambda, ->, haskell, and so on — "=?ISO-8859-2?Q?Rados=B3aw_Bu=B3at?=" <radek.bulat@...> 2008/05/22

T24gVGh1LCBNYXkgMjIsIDIwMDggYXQgNTozNyBQTSwgQmVyZ2VyLCBEYW5pZWwgPERhbmllbC5C

[#16857] Re: lambda, ->, haskell, and so on — "Jeremy McAnally" <jeremymcanally@...> 2008/05/23

RXZlbiB0aG91Z2ggSSBzZWUgdGhlIHVzZWZ1bG5lc3MsIHRoYXQncyBqdXN0IHVnbHkuCgotLUpl

[#16874] Re: lambda, ->, haskell, and so on — Nate_Wiger@... 2008/05/23

"Jeremy McAnally" <jeremymcanally@gmail.com> wrote on 05/22/2008 05:35:01=20

[#16875] Re: lambda, ->, haskell, and so on — "Nikolai Weibull" <now@...> 2008/05/23

2008/5/23 <Nate_Wiger@playstation.sony.com>:

[#16886] lambda with normal block syntax — "Eric Mahurin" <eric.mahurin@...>

This patch is an independent but related one to my previous one. It can be

64 messages 2008/05/25
[#16895] Re: [PATCH] lambda with normal block syntax — Nobuyoshi Nakada <nobu@...> 2008/05/26

Hi,

[#16900] Re: [PATCH] lambda with normal block syntax — "Eric Mahurin" <eric.mahurin@...> 2008/05/26

On Sun, May 25, 2008 at 8:19 PM, Nobuyoshi Nakada <nobu@ruby-lang.org>

[#16901] Re: [PATCH] lambda with normal block syntax — Yukihiro Matsumoto <matz@...> 2008/05/26

Hi,

[#16902] Re: [PATCH] lambda with normal block syntax — "Suraj N. Kurapati" <sunaku@...> 2008/05/26

Hi,

[#16903] Re: [PATCH] lambda with normal block syntax — Yukihiro Matsumoto <matz@...> 2008/05/26

Hi,

[#16904] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/26

[#16905] Re: [PATCH] lambda with normal block syntax — Yukihiro Matsumoto <matz@...> 2008/05/26

Hi,

[#16907] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/26

[#16912] Re: [PATCH] lambda with normal block syntax — Yukihiro Matsumoto <matz@...> 2008/05/26

Hi,

[#16920] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/26

If I may, here are two entries from the ChangeLog file:

[#16922] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/26

[#16927] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/26

Dave Thomas wrote:

[#16928] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/26

[#16929] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/26

Dave Thomas wrote:

[#16931] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/27

[#16946] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/27

Dave Thomas wrote:

[#16947] Re: [PATCH] lambda with normal block syntax — James Gray <james@...> 2008/05/27

On May 27, 2008, at 12:33 PM, David Flanagan wrote:

[#16949] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/27

James Gray wrote:

[PATCH] lambda with normal block syntax

From: "Eric Mahurin" <eric.mahurin@...>
Date: 2008-05-25 07:30:42 UTC
List: ruby-core #16886
This patch is an independent but related one to my previous one.  It can be
combined to allow for normal block syntax lambdas with default arguments.
This patch allows you to make lambda's more concisely by simply removing the
"lambda":

plus = { |a,b| a+b }  # |'s are required to disambiguate with a Hash
plus[1, 2] # => 3

f = do 42 end   # || not required
f[] # => 42

def my_while(cond)
    yield while cond[]
end
i=10
my_while({ || (i-=1).nonzero?}) { p i }

9
8
7
6
5
4
3
2
1


I wasn't able to get rid of some reduce/reduce conflict warnings (at
yacc/compile time).  They are come from the do/end, not the {}.  I tried
putting in some %prec attributes to help, but didn't get anywhere.  A yacc
expert may have better luck.  It looks like the default precedence is
correct though.  I assume the problem occurs between the first argument of a
no parens call arg list and a block for that call.  It looks to treat it as
a block in this case (instead of a lambda for the first argument), which
will maintain compatibility?

Here would be a ChangeLog entry:

* parse.y (primary) : allow for a <block_lambda>.  The <block_lambda>
grammar is almost identical to a normal block except |'s are required in the
{} form (to disambiguate from a Hash).  The semantics are equivalent to
preceding the block with "lambda".
* sample/test.rb : tests for the above.


Index: sample/test.rb
===================================================================
--- sample/test.rb    (revision 16585)
+++ sample/test.rb    (working copy)
@@ -1027,6 +1027,20 @@
 call_argument_test(false, lambda{|a,|})
 call_argument_test(false, lambda{|a,|}, 1,2)

+call_argument_test(true, {||})
+call_argument_test(false, {||}, 1)
+call_argument_test(true, {|a,|}, 1)
+call_argument_test(false, {|a,|})
+call_argument_test(false, {|a,|}, 1,2)
+
+call_argument_test(true, do end)
+call_argument_test(false, do end, 1)
+call_argument_test(true, do || end)
+call_argument_test(false, do || end, 1)
+call_argument_test(true, do |a,| end, 1)
+call_argument_test(false, do |a,| end)
+call_argument_test(false, do |a,| end, 1,2)
+
 call_argument_test(true, Proc.new{||})
 call_argument_test(true, Proc.new{||}, 1)
 call_argument_test(true, Proc.new{|a,|}, 1)
Index: parse.y
===================================================================
--- parse.y    (revision 16585)
+++ parse.y    (working copy)
@@ -670,6 +670,7 @@
 %type <node> assoc_list assocs assoc undef_list backref string_dvar for_var
 %type <node> block_param opt_block_param block_param_def f_opt
 %type <node> bv_decls opt_bv_decl bvar
+%type <node> block_lambda
 %type <node> lambda f_larglist lambda_body
 %type <node> brace_block cmd_brace_block do_block lhs none fitem
 %type <node> mlhs mlhs_head mlhs_basic mlhs_item mlhs_node mlhs_post
mlhs_inner
@@ -2641,6 +2642,10 @@
             $$ = dispatch1(hash, escape_Qundef($2));
             %*/
             }
+                | block_lambda
+            {
+            $$ = $1;
+            }
         | keyword_return
             {
             /*%%%*/
@@ -3327,6 +3332,56 @@
             }
         ;

+block_lambda    : tLBRACE
+            {
+            /*%%%*/
+            dyna_push();
+            $<num>$ = ruby_sourceline;
+            /*%
+                    %*/
+            }
+                  block_param_def compstmt '}'
+            {
+            /*%%%*/
+                        $$ = NEW_ITER($3, $4);
+            nd_set_line($$, $<num>2);
+            dyna_pop();
+            $$->nd_iter = NEW_FCALL(rb_intern("lambda"), 0);
+            fixpos($$->nd_iter, $$);
+            /*%
+            $$ = method_arg(
+                            dispatch1(fcall, rb_intern("lambda")),
+                            arg_new());
+            $$ = method_add_block($$,
+                            dispatch2(brace_block, escape_Qundef($3), $4));
+            %*/
+            }
+        | keyword_do_block
+            {
+            /*%%%*/
+            dyna_push();
+            $<num>$ = ruby_sourceline;
+            /*%
+                    %*/
+            }
+                  opt_block_param compstmt keyword_end
+            {
+            /*%%%*/
+                        $$ = NEW_ITER($3, $4);
+            nd_set_line($$, $<num>2);
+            dyna_pop();
+            $$->nd_iter = NEW_FCALL(rb_intern("lambda"), 0);
+            fixpos($$->nd_iter, $$);
+            /*%
+            $$ = method_arg(
+                            dispatch1(fcall, rb_intern("lambda")),
+                            arg_new());
+            $$ = method_add_block($$,
+                            dispatch2(do_block, escape_Qundef($3), $4));
+            %*/
+            }
+                ;
+
 f_larglist    : '(' f_args opt_bv_decl rparen
             {
             /*%%%*/

In This Thread

Prev Next