develooper Front page | perl.perl6.users | Postings from September 2018

Re: Rat

Thread Previous | Thread Next
Curt Tilmes
September 17, 2018 02:37
Re: Rat
Message ID:
Rat is a type (a 'class').

It is also a method on class Numeric.  You can take anything Numeric, and
call .Rat() on it to get an equivalent Rat (well, within $epsilon)

You can't, for example, say
my Rat $x = pi;
Since pi is not rational -- it won't fit in that box.
You can, however, ask pi to turn itself into a Rat (or something pretty
close), then it will fit.
my Rat $x = pi.Rat;

On Sun, Sep 16, 2018 at 10:29 PM ToddAndMargo <> wrote:

> Hi All,
> What in the world are they trying to say here?
>      (Numeric) method Rat
>      method Rat(Numeric:D: Real $epsilon = 1.0e-6 --> Rat:D)
>      If this Numeric is equivalent to a Real, return a Rat which
>      is within $epsilon of that Real's value. Fail
>      with X::Numeric::Real otherwise.
> And is this why I can not find a type "Rat"?  Because
> it is a method?
> Then why does
>      $ p6 'my Real $x; $x = 3.1415; dd $x;'
>      Rat $x = 3.1415
> say it is a type "Rat"?
> Yours in confusion,
> -T

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About