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

Re: decision operator

Thread Previous
From:
Moritz Lenz
Date:
March 24, 2009 16:35
Subject:
Re: decision operator
Message ID:
49C96E1D.6030501@faui2k3.org
Moritz Lenz wrote:
> Ruud H.G. van Tol wrote:
>> I wonder if there is place for a "decision operator".
>> (search terms: FPGA, evolvable hardware, Xilinx, PLB, LUT, NESW)
>> 
>> 
>> dop:| 0 1 2 3 4 5 6 7 8 9 A B C D E F
>> ----+--------------------------------
>> 0 0 | 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
>> 0 1 | 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
>> 1 0 | 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
>> 1 1 | 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
>> 
>> 
>> So for two boolean inputs,
>> "&" is an alias of dop(1),
>> "|" is an alias of dop(0x07),
>> "^" is an alias of dop(0b0110).
>> 
>> (1,0).dop(7) returns 1 because (1 | 0) == 1
>> 
>> (4,3).dop(7) returns 7 because (4 | 3) == 7
>> 
>> ("A","F").dop(7) returns "G" because ("A" | "F") eq "G"
>> 
>> (1,1,1).dop(0b01101001) returns 1 because (1^1^1) == 1
> 
> This looks like a perfect place for a (possibly user defined) operator
> with an attribute, something like

s/attribute/adverb/ actually

> 1 ~~ 0 :dop(7)

... and maybe not with the smartmatch operator, because it's already
taken, and jnthn++ reminded me that named parameters don't participate
in dispatch.

Cheers,
Moritz

Thread Previous


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