From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 14615 invoked from network); 9 Jul 2021 14:34:11 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 9 Jul 2021 14:34:11 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 1ess; Fri Jul 9 10:28:26 -0400 2021 Received: from abbatoir.myfiosgateway.com (pool-74-108-56-225.nycmny.fios.verizon.net [74.108.56.225]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 16a4e819 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Fri, 9 Jul 2021 07:21:26 -0700 (PDT) Message-ID: <968C3349B9F65B001E188F845EBD631C@eigenstate.org> To: 9front@9front.org Date: Fri, 09 Jul 2021 10:21:25 -0400 From: ori@eigenstate.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: shared proxy-aware template API just-in-time table Subject: Re: [9front] Re: commit 2f8a59f4b5bfe028c022855acc19666d69eed909 Reply-To: 9front@9front.org Precedence: bulk Quoth Anthony Martin : > > rc: add subshell-function syntax > > > > fn foo @{bar} is now equivalent to > > fn foo {@{bar}}. As a side effect, > > this disallows creating functions > > named after keywords without first > > quoting them. > > Respectfully, this is just wrong. @ is a > unary operator. Repurposing it to define > a new special kind of function is a bit > much. > > What does this buy you over being explicit > at the call site? > > fn foo { bar } > > @foo > > One color of function is enough. What's > next? > > fn foo !{ bar } > > to mean that foo always negates the exit > status of its body? > > The new quoting requirement for functions > named after keywords seems fine, on the > other hand. But is it worth the backwards > incompatibility? > > Thanks, > Anthony > You know, that's an interesting point. We can make the language more regular by simply removing the special case around function bodies, and making them behave the same as if, while, etc. It costs us this syntax: fn list of functions { ... } and requires us to be explicit: fn (list of functions) { ... } but on the other hand, things like fn foo echo hi fn foo @{echo hi} fn foo !bar fn foo !{bar} etc all work, just as they would in the body of any other statement.= AND it simplifies the code. It'd take some care moving forward with this, but it looks like there aren't very many places this is used; I've found one in our source tree, in ircrc: --- //.git/fs/object/2f8a59f4b5bfe028c022855acc19666d69eed909/tree//rc/bin/ircrc +++ /rc/bin/ircrc @@ -16,7 +16,7 @@ exit 'hang up' } -fn sigint sigterm { +fn (sigint sigterm) { if (! ~ $#netdir 0) echo QUIT : Leaving... > $netdir/data } --- //.git/fs/object/2f8a59f4b5bfe028c022855acc19666d69eed909/tree/sys/src/cmd/rc/syn.y +++ sys/src/cmd/rc/syn.y @@ -2,7 +2,7 @@ %term WORD REDIR DUP PIPE SUB %term SIMPLE ARGLIST WORDS BRACE PAREN PCMD PIPEFD /* not used in syntax */ /* operator priorities -- lowest first */ -%left IF WHILE FOR SWITCH ')' NOT +%left IF WHILE FOR SWITCH ')' NOT FN %left ANDAND OROR %left BANG SUBSHELL %left PIPE @@ -17,7 +17,7 @@ struct tree *tree; }; %type line paren brace body cmdsa cmdsan assign epilog redir -%type cmd simple first word comword keyword words comwords +%type cmd simple first word comword keyword words %type NOT FOR IN WHILE IF TWIDDLE BANG SUBSHELL SWITCH FN %type WORD REDIR DUP PIPE %% @@ -68,10 +68,7 @@ | assign cmd %prec BANG {$$=mung3($1, $1->child[0], $1->child[1], $2);} | BANG cmd {$$=mung1($1, $2);} | SUBSHELL cmd {$$=mung1($1, $2);} -| FN comwords brace {$$=tree2(FN, $2, $3);} -| FN comwords SUBSHELL brace - {$$=tree2(FN, $2, mung1($3, $4));} -| FN comwords {$$=tree1(FN, $2);} +| FN word cmd {$$=tree2(FN, $2, $3);} simple: first | simple word {$$=tree2(ARGLIST, $1, $2);} | simple redir {$$=tree2(ARGLIST, $1, $2);} @@ -92,5 +89,3 @@ keyword: FOR|IN|WHILE|IF|NOT|TWIDDLE|BANG|SUBSHELL|SWITCH|FN words: {$$=(struct tree*)0;} | words word {$$=tree2(WORDS, $1, $2);} -comwords: {$$=(struct tree*)0;} -| comwords comword {$$=tree2(WORDS, $1, $2);}