From: nobu@... Date: 2017-12-12T10:04:58+00:00 Subject: [ruby-core:84201] [Ruby trunk Feature#11256] anonymous block forwarding Issue #11256 has been updated by nobu (Nobuyoshi Nakada). Current patch. ```diff diff --git a/parse.y b/parse.y index 1026d5c896..2a98016002 100644 --- a/parse.y +++ b/parse.y @@ -347,6 +347,8 @@ static int parser_yyerror(struct parser_params*, const char*); #define lambda_beginning_p() (lpar_beg && lpar_beg == paren_nest) +#define ANON_BLOCK_ID '&' + static enum yytokentype yylex(YYSTYPE*, YYLTYPE*, struct parser_params*); #ifndef RIPPER @@ -2560,6 +2562,18 @@ block_arg : tAMPER arg_value $$ = $2; %*/ } + | tAMPER + { + /*%%%*/ + if (!local_id(ANON_BLOCK_ID)) { + compile_error(PARSER_ARG "no anonymous block parameter"); + } + $$ = NEW_BLOCK_PASS(new_lvar(ANON_BLOCK_ID, &@1)); + $$->nd_loc = @$; + /*% + $$ = Qnil; + %*/ + } ; opt_block_arg : ',' block_arg @@ -4913,6 +4927,15 @@ f_block_arg : blkarg_mark tIDENTIFIER $$ = dispatch1(blockarg, $2); %*/ } + | blkarg_mark + { + /*%%%*/ + $$ = ANON_BLOCK_ID; + arg_var($$); + /*% + $$ = dispatch1(blockarg, Qnil); + %*/ + } ; opt_f_block_arg : ',' f_block_arg ``` ---------------------------------------- Feature #11256: anonymous block forwarding https://bugs.ruby-lang.org/issues/11256#change-68318 * Author: bughit (bug hit) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- since capturing a block into a proc is slow: foo(&block) and creating chains of blocks is kind of ugly and ultimately also inefficient: foo{yield} why not allow block forwarding without capturing: foo(&) foo(1, 2, &) -- https://bugs.ruby-lang.org/ Unsubscribe: