develooper Front page | perl.perl6.language | Postings from March 2005

Re: nothing

Thread Previous | Thread Next
From:
Rod Adams
Date:
March 21, 2005 11:17
Subject:
Re: nothing
Message ID:
423F1DAD.2040801@rodadams.net
Larry Wall wrote:

>On Sun, Mar 20, 2005 at 09:08:08PM -0600, Rod Adams wrote:
>
>: I propose creating a no-op function "nothing" that can be used 
>: here or anywhere else you specifically wish to do nothing at all.
>: 
>:  given $this {
>:    when Even  { nothing };
>:    when Prime { ... };
>:    default    { ... };
>:  }
>
>We use <null> in rules, and Ada used "null" as a keyword, so I'd probably
>prefer that if there are no serious objections and if nobody has a better
>idea.
>  
>
It's potentially confusing for the database crowd, where the word "null" 
is pretty much a synonym for a Perl "undef". Being part of that crowd, 
"null" is invariably locked into my head as a value. It works in the 
Rule sense of <null>, since you're looking for the value which is nothing.

I also think a huffman level of 7 makes more sense than 4, so I still 
prefer "nothing".

That being said, I'm sure people could learn the difference if they 
needed to.

>
>: As a side question, I assume that there's a predicate form of "when", 
>: but it's not mentioned.
>: 
>:  given $this {
>:    nothing when Even;
>: 
>:    when Prime { ... };
>: 
>:    default    { ... };
>:  }
>
>It's mentioned somewhere, I forget where, but its semantics are
>currently defined such that it would not bypass the other cases.
>It's possible that's a Surprise, but we were invisioning it as a
>mechanism for adding extra tests against the topic when you don't
>want to break out.
>
"possible" surprise? Every other conditional holds its semantics whether 
in predicate or subjective form, so why should it be surprising when 
"when" changes it's semantics?

If you want to test against the topic without breaking out, you still 
have "if" and "$_" at your disposal, which should always be clear what 
you're doing.


>  And we wanted to encourage people to use the
>"comb structure" when they really are dealing with exclusive options.
>  
>
What's wrong with

  given somefunc() {
    die "error"        when 0;
    print_status       when 1;
    prompt_options     when 2;
    die "impossible";
  }

as an alternative to the comb in the cases where all the commands are 
short? That seems cleaner to me than:

  given somefunc() {
    when 0  { die "error"      };
    when 1  { print_status     };
    when 2  { prompt_options   };
    default { die "impossible" };
  }

No, the former doesn't look a lot like the classical switch statement, 
but this is the land of TMTOWTDI.

-- Rod Adams





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