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

&& or defined and && bug #313

Closed
p6rt opened this issue Sep 13, 2008 · 8 comments
Closed

&& or defined and && bug #313

p6rt opened this issue Sep 13, 2008 · 8 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Sep 13, 2008

Migrated from rt.perl.org#58830 (status was 'resolved')

Searchable as RT58830$

@p6rt
Copy link
Author

p6rt commented Sep 13, 2008

From @ilyabelikin

Hi,
look like bug (in r31017)​:

my $k = 'bar';
my %s;
say defined $k; # 1
say defined %s{$k}; # 0
say defined $k and defined %s{$k}; # 1 (!) must be 0
say 1 && 0; # 0

Ilya
Vladivostok.pm

@p6rt
Copy link
Author

p6rt commented Sep 14, 2008

From @bacek

Hello.

This is parsing bug.

"say defined $a and defined %b{$a}" parsed as "(say defined $a) and
defined %b{$a}"

--
Bacek.

@p6rt
Copy link
Author

p6rt commented Sep 14, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Sep 14, 2008

From @masak

Ilya (>)​:

look like bug (in r31017)​:

my $k = 'bar';
my %s;
say defined $k; # 1
say defined %s{$k}; # 0
say defined $k and defined %s{$k}; # 1 (!) must be 0
say 1 && 0; # 0

No, this is intended. "and" has very loose precedence, even looser
than the "say" call. The crucial statement is thus parsed like this​:

(say defined $k) and defined %s{$k};

...which would output 1 but return 0.

To learn more about operator precedence, see

<http://perlcabal.org/syn/S03.html#Operator_precedence>

Also check out the excellent "perldoc perlop" for Perl 5 for more
examples of this.

<http://perldoc.perl.org/perlop.html>

// Carl

@p6rt
Copy link
Author

p6rt commented Sep 14, 2008

From @ilyabelikin

Hi,
thank you. Do we have ticket for this parsing bug?
I have serched for it, bot do not find.

2008/9/14 via RT Ilya Belikin <perl6-bugs-followup@​perl.org>​:

# New Ticket Created by Ilya Belikin
# Please include the string​: [perl #​58830]
# in the subject line of all future correspondence about this issue.
# <URL​: http://rt.perl.org/rt3/Ticket/Display.html?id=58830 >

Hi,
look like bug (in r31017)​:

my $k = 'bar';
my %s;
say defined $k; # 1
say defined %s{$k}; # 0
say defined $k and defined %s{$k}; # 1 (!) must be 0
say 1 && 0; # 0

Ilya
Vladivostok.pm

@p6rt
Copy link
Author

p6rt commented Sep 14, 2008

From @bacek

Ilya Belikin wrote​:

Hi,
look like bug (in r31017)​:

my $k = 'bar';
my %s;
say defined $k; # 1
say defined %s{$k}; # 0
say defined $k and defined %s{$k}; # 1 (!) must be 0
say 1 && 0; # 0

I replyed in ticket, but it doesn't hit mailinglist. This is bug in
parsing. "say defined $k and defined %s{$k};" parsed as "(say defined
$k) and defined %s{$k};"

--
Bacek

@p6rt
Copy link
Author

p6rt commented Sep 14, 2008

From @pmichaud

On Sun, Sep 14, 2008 at 09​:13​:33PM +1000, Vasily Chekalkin wrote​:

Ilya Belikin wrote​:

Hi,
look like bug (in r31017)​:

my $k = 'bar';
my %s;
say defined $k; # 1
say defined %s{$k}; # 0
say defined $k and defined %s{$k}; # 1 (!) must be 0
say 1 && 0; # 0

I replyed in ticket, but it doesn't hit mailinglist. This is bug in
parsing. "say defined $k and defined %s{$k};" parsed as "(say defined
$k) and defined %s{$k};"

As Carl correctly noted, Rakudo has the parsing for infix​:<and> correct --
infix​:<and> has looser precedence than listops (including 'say'), so
Rakudo is doing the right thing here.

The intended version is likely​:

  say defined $k && defined %s{$k};

However, as of r31017 Rakudo did not have 'defined' as a named
unary, so parsed this version as

  say( defined( $k && defined( %s{$k} ) ) );

which is also not what is wanted. In r31116 I've changed 'defined'
to be a named unary, and we now get the desired output​:

  $ cat x
  my $k = 'bar';
  my %s;
  say defined $k; # 1
  say defined %s{$k}; # 0
  say defined $k and defined %s{$k}; # 1
  say defined $k && defined %s{$k}; # 0
  $ ./parrot perl6.pbc x
  1
  0
  1
  0

We probably need to test that 'defined' is a named unary in t/spec.

Closing ticket, thanks.

Pm

@p6rt p6rt closed this as completed Sep 14, 2008
@p6rt
Copy link
Author

p6rt commented Sep 14, 2008

@pmichaud - Status changed from 'open' to 'resolved'

@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