perladvent / perldotcom

The source code for Perl.com website
https://www.perl.com
79 stars 81 forks source link

Raku code in "Perl 6 Parameter Parsing" no longer works #267

Closed jubilatious1 closed 4 years ago

jubilatious1 commented 4 years ago

https://www.perl.com/pub/2007/03/01/perl-6-parameter-passing.html/ https://github.com/tpf/perldotcom/blob/master/content/legacy/_pub_2007_03_01_perl-6-parameter-passing.md

CodeNotes

  1. Newton's Method:
user@mbook:~$ raku Newtons_Method.p6  #try original code, error at original code line 3
===SORRY!=== Error while compiling Newtons_Method.p6
Cannot assign a literal of type Int (9) to a variable of type Num. You can declare the variable to be of type Real, or try to coerce the value with 9.Num or Num(9), or just write the value as 9e0
at Newtons_Method.p6:5
------> my Num  $target = ⏏9;

user@mbook:~$ raku Newtons_Method2.p6  #with line 3 modified to read "my Real  $target = 9;"
Type check failed in assignment to $guess; expected Num but got Int (9)
  in block <unit> at Newtons_Method2.p6 line 6

user@mbook:~$ raku Newtons_Method3.p6  #with line 3 modified to read "my Num  $target = 9.Num;"
5
3.4
3.023529411764706
3.00009155413138
user@mbook:~$

user@mbook:~$ raku Newtons_Method4.p6  #with line 3 modified to read "my Num  $target = 9e0;"
5
3.4
3.023529411764706
3.00009155413138
user@mbook:~$

user@mbook:~$ raku --version
This is Rakudo version 2020.06 built on MoarVM version 2020.06
implementing Raku 6.d.
user@mbook:~$
briandfoy commented 4 years ago

Would you like to make a pull request against that article to fix the code?

jubilatious1 commented 4 years ago

@briandfoy I can certainly do that, but for historical purposes I probably won't change the original article. My instinct is to add an addendum to the end of the article, and make sure the original author is given the opportunity to sign off on it.

briandfoy commented 4 years ago

Just change the original article. The source is all in GitHub, and the article is 13 years old.

lizmat commented 4 years ago

FWIW, this has been an error in any released version of Perl 6 or Raku.

jubilatious1 commented 4 years ago

FWIW, this has been an error in any released version of Perl 6 or Raku.

Well, that makes it easy then. Somehow I thought the code worked when it was published--but if it never worked, it should be fixed.

briandfoy commented 4 years ago

Well, in the early days of Pugs all sorts of things that shouldn't have worked might have worked. I doubt anyone is going to go back to find out.

But, my main question to the Raku people is which version of the fix would you like?

jubilatious1 commented 4 years ago

But, my main question to the Raku people is which version of the fix would you like?

I can't speak for anyone else, but giving the reader (presently) working code is desirable.

(and maybe even a TIO link... https://tio.run/#perl6 )

briandfoy commented 4 years ago

I can't speak for anyone else, but giving the reader (presently) working code is desirable.

Would you like 9.Num or 9e0?

jubilatious1 commented 4 years ago

Would you like 9.Num or 9e0?

I defer to @lizmat on that decision.

lizmat commented 4 years ago

9e0

briandfoy commented 4 years ago

I've fixed this in 66ebf51c1d0f0df11560485e5109afeb7281eda4 and it will be part of the next site refresh.