develooper Front page | perl.perl6.language.data | Postings from September 2000

Re: RFC 82 (v3) Arrays: Apply operators element-wise in a list context

Thread Previous | Thread Next
From:
Nathan Wiger
Date:
September 9, 2000 13:50
Subject:
Re: RFC 82 (v3) Arrays: Apply operators element-wise in a list context
Message ID:
39BAA07D.6FF2EB1A@wiger.org
Nathan Torkington wrote:
> 
> Actually, the only refinement I'd like to see is that boolean operators
> (==, &&, ||) be excepted from the distributive rule.
> 
> This is to permit:
> 
>   if (@a == @b)         # shallow comparison
> 
> and
> 
>   @a = @b || @c;        # @a=@b or @a=@c;       # ish

Yeah, I agree completely with this sentiment. This is far more useful to
me than having them element-wise.

My main fear is that while this RFC seems really good for math ops, but
seems too array- and PDL-specific. Here are some examples of mixed
contexts; how would these be handled under the RFC?

    @user_data = @empty || $user;
    %files = scalar(get_files()) || @DEFAULT;
    $total = @items + $MIN_VALUE;
    @full_names = @first_names . "Smith";

What I'd like to see is Perl to really DWIM (especially in that last
one). But to do so you have to redo the rules of the RFC:

    Op Type         Default homogenous context     Mixed context
    --------------- ------------------------------
-------------------------- 
    Math ops        element-wise                   forced to scalar
    Boolean ops     whole entity                   forced to list 
    String ops      element-wise                   forced to list

With these rules, the above examples now work as I'd expect (or at least
want) them to:

    @user_data = @empty || $user;             # @user_data =
($user);            
    %files = scalar(get_files()) || @DEFAULT; # %files =
(@DEFAULT);          
    $total = @items + $MIN_VALUE;             # $total = 5 + 2;
    @full_names = @first_names . "Smith";     # @full_names = ("Bob
Smith", "Jim Smith");

True, this opens a whole other can of worms, but I think it's closer to
what people would want to use the ops for, and it's also more usable to
us non-PDLers. Note there's a lot of inherent want()-like behavior built
in there.

-Nate

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