On 2020-01-20 08:32, Peter Pentchev wrote:
On Sun, Jan 19, 2020 at 08:25:15PM -0800, ToddAndMargo via perl6-users wrote:
One last question on htis.  What does

multi sub prefix:<+^>(Any --> Int:D)

Mean.  Prefix means before.  +^(Any) get
me a participation trophy, so I do not
understand.


:'(

INQUIRING MINDS WANT TO KNOW! (That is
a joke referencing a tabloid commercial.)

The <> characters surround the name of the operator, so the operator is
named "+^". This means that you would use it on $foo as:

     $something = +^$foo;

The part in the parentheses is a description of what arguments this
function (the operator that we are now describing in terms of functions)
will take and what type it will return. The part before the --> sign is
what arguments it takes - in this case it takes a single argument that
must be of the Any type or one of its subtypes, so pretty much anything
(yeah, yeah, I know) in Raku may be used as an argument to this
operator. The part after the --> sign describes the type of the value
that the function (the +^ operator) will return - it says that the
returned value will be an integer and that it will always have a
definite value, it will not be an undefined value.

So this means that whatever you have in a variable $foo, you may write
+^$foo and you will get an integer.

G'luck,
Peter


Hi Peter,

Thank you!

I guess there is no way to keep that from screwing with my
variable definition if it --> Int:D

$ p6 'my UInt $x =  +^0b1001; '
Type check failed in assignment to $x; expected UInt but got Int (-10)
  in block <unit> at -e line 1

Ordinarily, I like this feature, but there
are times it is a pain in the ...

Work arounds:

$ p6 'my byte $x =  +^0b1001; say $x.base(2)'
11110110

$ p6 'constant WORD := uint16; my WORD $x =  +^0b1001; say $x.base(2)'
1111111111110110


-T

Reply via email to