develooper Front page | perl.perl5.porters | Postings from December 2017

Re: Revisiting smart match

Thread Previous | Thread Next
From:
Rocco Caputo
Date:
December 23, 2017 19:44
Subject:
Re: Revisiting smart match
Message ID:
86A03330-F4BF-4D36-A4BC-CA7DFE5CE5A6@pobox.com
> On Dec 20, 2017, at 09:34, Rocco Caputo <rcaputo@pobox.com> wrote:
> 
> But for now, it fails because the required postfix forms read poorly:
> 
> when SUBJECT {
>   do { ... } matches MATCHER;
>   do { ... } passes CONDITION;
> }


Today I think this works:

given ($subject) {
  as ($_->foo == $value) { ... }
  do { ... } as $_->foo == $value;

  when ($matcher) { ... }
  do { ... } when $matcher;
}

Notes:

In plain English, "when" is used in exactly this sort of situation.  For example:

  Rocco, eat when hungry, and sleep when tired.
  Rocco: When hungry, eat. When tired, sleep.

As long as the solutions don't collide, the conditional and matching forms can be treated as separate problems.

The conditional form is easier to solve since it explicitly includes the $_ pronoun.

Postfix matching form is the hardest subproblem.  Without the $_ pronoun it's easy to confuse the conditional block with the subject.  If this can be solved, the rest should be easier.

-- 
Rocco Caputo <rcaputo@pobox.com>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About