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

Whatever-priming and thunking doesn't mix #3008

Open
p6rt opened this issue Dec 26, 2012 · 6 comments
Open

Whatever-priming and thunking doesn't mix #3008

p6rt opened this issue Dec 26, 2012 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Dec 26, 2012

Migrated from rt.perl.org#116208 (status was 'open')

Searchable as RT116208$

@p6rt
Copy link
Author

p6rt commented Dec 26, 2012

From @moritz

22​:07 < hoelzro> r​: my $divisor = 2; say(* != $divisor && * %% $divisor);
22​:07 <+p6eval> rakudo c8de2e​: OUTPUT«===SORRY!===␤Error while compiling
block​: Error while compiling op call​: Error while compiling block :
Error while compiling op call​: Error while compiling op if​: if block
expects an argument, but there's no immediate block to take it␤»

22​:15 < Ayiko> r​: say ((* < 5 and * > 5)(4,6))
22​:15 <+p6eval> rakudo c8de2e​: OUTPUT«===SORRY!===␤Error while compiling
block : Error while compiling op call​: Error while compiling block :
Error while compiling op call​: Error while compiling op call​: Error
while compiling op if​: if block expects an argument, but there's no
immediate block to take i…

I guess the mixture of whatever-priming and short-circuiting operators
doesn't work out well.

@p6rt
Copy link
Author

p6rt commented Aug 5, 2015

From @coke

On Wed Dec 26 13​:20​:23 2012, moritz wrote​:

22​:07 < hoelzro> r​: my $divisor = 2; say(* != $divisor && * %% $divisor);
22​:07 <+p6eval> rakudo c8de2e​: OUTPUT«===SORRY!===␤Error while compiling
block​: Error while compiling op call​: Error while compiling block :
Error while compiling op call​: Error while compiling op if​: if block
expects an argument, but there's no immediate block to take it␤»

22​:15 < Ayiko> r​: say ((* < 5 and * > 5)(4,6))
22​:15 <+p6eval> rakudo c8de2e​: OUTPUT«===SORRY!===␤Error while compiling
block : Error while compiling op call​: Error while compiling block :
Error while compiling op call​: Error while compiling op call​: Error
while compiling op if​: if block expects an argument, but there's no
immediate block to take i…

I guess the mixture of whatever-priming and short-circuiting operators
doesn't work out well.

These seems fine these days, at least on moar​:

20​:11 < [Coke]> r​: say ((* < 5 and * > 5)(4,6))
20​:11 <+camelia> rakudo-jvm 2f7ab3​: ( no output )
20​:11 <+camelia> ..rakudo-moar 2f7ab3​: OUTPUT«Too many positionals passed;
  expected 1 argument but got 2␤ in block <unit> at
  /tmp/tmpfile​:1␤␤»

Since the whatever code there has a single parameter, the *, we can't pass two in.

20​:11 < [Coke]> r​: my $divisor = 2; say(* != $divisor && * %% $divisor);
20​:11 <+camelia> rakudo-{moar,jvm} 2f7ab3​: OUTPUT«WhateverCode.new␤»

Closable (for moar at least) with tests.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Aug 5, 2015

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

@p6rt
Copy link
Author

p6rt commented Aug 16, 2015

From @usev6

bartolin_ m​: say (* < 7 and * > 5)(6)
camelia rakudo-moar ad062f​: OUTPUT«True␤»
bartolin_ is that supposed to be the same as 'say (6 < 7 and 6 > 5)'?
  m​: say (6 < 7 and 6 > 5)
camelia rakudo-moar ad062f​: OUTPUT«True␤»
bartolin_ m​: say (* < 7 and * > 5)(7)
camelia rakudo-moar ad062f​: OUTPUT«True␤»
FROGGS m​: say (* < 7 and 7 > 5)(7)
camelia rakudo-moar ab73b0​: OUTPUT«Cannot find method 'postcircumfix​:<( )>'␤ in block <unit> at /tmp/TTAXdxnzeL​:1␤␤»
FROGGS ?
  ahh
  the 'and' is not part of the code that is invoked via (7)
  say (* < 7 and * > 5)(7) turns into m​: say (WhateverCode and * > 5)(7), so the 7 is passed to the code after the 'and'
bartolin_ ahh, that explains it.
  it's from RT #​116208
bartolin_ ... which doesn't look quite right (closable) to me
FROGGS aye

AFAIU whatever-priming still does not work correctly with short-circuiting operators. Shouldn't the example code only run with 2 arguments -- like the following?

$ perl6 -e 'say ((* + 4) / (* - 4))(6)'
Too few positionals passed; expected 2 arguments but got 1
  in block <unit> at -e​:1

$ perl6 -e 'say ((* + 4) / (* - 4))(6,6)'
5

1 similar comment
@p6rt
Copy link
Author

p6rt commented Aug 16, 2015

From @usev6

bartolin_ m​: say (* < 7 and * > 5)(6)
camelia rakudo-moar ad062f​: OUTPUT«True␤»
bartolin_ is that supposed to be the same as 'say (6 < 7 and 6 > 5)'?
  m​: say (6 < 7 and 6 > 5)
camelia rakudo-moar ad062f​: OUTPUT«True␤»
bartolin_ m​: say (* < 7 and * > 5)(7)
camelia rakudo-moar ad062f​: OUTPUT«True␤»
FROGGS m​: say (* < 7 and 7 > 5)(7)
camelia rakudo-moar ab73b0​: OUTPUT«Cannot find method 'postcircumfix​:<( )>'␤ in block <unit> at /tmp/TTAXdxnzeL​:1␤␤»
FROGGS ?
  ahh
  the 'and' is not part of the code that is invoked via (7)
  say (* < 7 and * > 5)(7) turns into m​: say (WhateverCode and * > 5)(7), so the 7 is passed to the code after the 'and'
bartolin_ ahh, that explains it.
  it's from RT #​116208
bartolin_ ... which doesn't look quite right (closable) to me
FROGGS aye

AFAIU whatever-priming still does not work correctly with short-circuiting operators. Shouldn't the example code only run with 2 arguments -- like the following?

$ perl6 -e 'say ((* + 4) / (* - 4))(6)'
Too few positionals passed; expected 2 arguments but got 1
  in block <unit> at -e​:1

$ perl6 -e 'say ((* + 4) / (* - 4))(6,6)'
5

@p6rt
Copy link
Author

p6rt commented Sep 1, 2016

From @smls

S02 <https://design.perl6.org/S02.html#line_1063> states​:

  For any unary or binary operator (specifically, any prefix,
  postfix, and infix operator), if the operator has not
  specifically requested (via signature matching) to handle *
  itself, the compiler is required to translate directly to an
  appropriately primed closure at compile time. We call this
  autopriming. Most of the built-in numeric operators fall into
  this category.

Then further down, it lists these operators as ones that *don't* participate in autopriming​:

  xx
  ~~
  ..
  ...
  =

It doesn't mention `|| && // and or` in that list.
But then again it also doesn't mention that the comma operator stops auto-priming, nor does it claim the list to be complete.

Interestingly, the Z and X operators do autoprime in Rakudo even though they have much looser precedence than the comma​:

  say ( 1, 2, 3 Z * )(<a b c>); # ((1 a) (2 b) (3 c))

Is there a reason for `|| && // and or` not to do the same (other than that they'd loose their short-circuiting behavior)?

I think this needs a @​LARRY decision, and possibly an investigation into what would break if this was changed.

@p6rt p6rt added the at_larry 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