Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Redefining operator '>'. #6391

Open
p6rt opened this issue Jul 12, 2017 · 1 comment
Open

- Redefining operator '>'. #6391

p6rt opened this issue Jul 12, 2017 · 1 comment
Labels

Comments

@p6rt
Copy link

p6rt commented Jul 12, 2017

Migrated from rt.perl.org#131742 (status was 'new')

Searchable as RT131742$

@p6rt
Copy link
Author

p6rt commented Jul 12, 2017

From andynparker@googlemail.com

Hi,

I have found some unexpected behaviour when attempting to redefine the
operator '>'.

First attempt, which works, but redefines 'gt' (however, as this is
defined for string comparisons I would prefer to use '>').

Code is​:

multi infix​:«gt»( Fpa​:D $left, Fpa​:D $right --> Bool) is
equiv(&infix​:<gt>) { etc etc }

and called by​:

my $xx = Fpa.fpaNew();
my $yy = Fpa.fpaNew();
$xx F=  '+1133.100000000000000000';
$yy F=  '+1133.900000000000000000'; # F+ $testValue;
say $xx.WHAT;
say $yy.WHAT;
if $xx gt $yy { say "OK! It is a \c[PENGUIN];" } else { say "It is not
a \c[PENGUIN]"; }

gives result​:

perl6-m ./FPArithTest2.pm6
(Fpa)
(Fpa)
It is not a 🐧

So far, as expected.

Now I amend code to use '>' operator​:

multi infix​:«>»( Fpa​:D $left, Fpa​:D $right --> Bool) is
equiv(&infix​:<gt>) { .... etc etc }

and called by 

my $xx = Fpa.fpaNew();
my $yy = Fpa.fpaNew();
$xx F=  '+1133.100000000000000000';
$yy F=  '+1133.900000000000000000'; 
say $xx.WHAT;
say $yy.WHAT;
if $xx > $yy { say "OK! It is a \c[PENGUIN];" } else { say "It is not a
\c[PENGUIN]"; }

now gives result​:

perl6-m ./FPArithTest2.pm6

(Fpa)
(Fpa)
Cannot resolve caller Real(FPArith​:<0.0.1>​::EXPORT​::DEFAULT​::Fpa​: );
none of these signatures match​:
    (Mu​:U \v​: *%_)
  in block <unit> at ./FPArithTest2.pm6 line 15

which I cannot understand as the $xx.WHAT and $yy.WHAT show both are
Fpa type objects, so should match the 'multi infix​:«>»( Fpa​:D ...,
Fpa​:D .. ) definitions in the multi. (Well, that is my intention.)
The difference between the first (working) example and the second is
just the name of the operator.

OK, so now I try to use 'F>' as this may be a more obvious API​:

Here is the API​:

multi infix​:«F>»( Fpa​:D $left, Fpa​:D $right --> Bool) is
equiv(&infix​:<gt>) { ... etc etc }

and the invoking test​:
my $xx = Fpa.fpaNew();
my $yy = Fpa.fpaNew();
$xx F=  '+1133.100000000000000000';
$yy F=  '+1133.900000000000000000'; 
say $xx.WHAT;
say $yy.WHAT;
if $xx F> $yy { say "OK! It is a \c[PENGUIN];" } else { say "It is not
a \c[PENGUIN]"; }

Which gives result​:

perl6-m ./FPArithTest2.pm6
===SORRY!=== Error while compiling
/home/aparker/Documents/FixedPointArithmetic/./FPArithTest2.pm6
Missing block
at /home/aparker/Documents/FixedPointArithmetic/./FPArithTest2.pm6​:15
------> if $xx⏏ F> $yy { say "OK! It is a \c[PENGUIN];"
    expecting any of​:
        block or pointy block
        infix
        infix stopper

Are these results bugs or I am doing some wrong here?

Regards,

Andrew N Parker

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant