Perl 5 implementation #4
Conversation
|
Oh gosh... Perl. I don't even know who can review this. |
| } | ||
| # everytime shift is called inside a function without array passed to shift operator | ||
| # it returns next argument | ||
| # note that shift is an operator, so it thinks of things next to it as of its arguments |
| sub inc1 { | ||
| return 1 + shift; | ||
| } | ||
| # everytime shift is called inside a function without array passed to shift operator |
aqrln
Jun 9, 2017
Contributor
I believe it is better to have these comments above the corresponding functions, not below them.
| print inc2(2); # returns 3 | ||
| print inc3(2); # returns 2 (look in comments near function definition) | ||
| print sum(1, 2); # returns 3 | ||
| #print sum(1, 2, 3); # produces an error. Uncomment and try it! |
|
|
||
| use strict; | ||
| # in original repo this file is named "context" | ||
| # i take the responsibility to rename it to "scopes" |
aqrln
Jun 9, 2017
Contributor
+1 on this. Mind sending a PR to change it throughout the whole repo? I'd be in support for it.
|
|
||
| my @cities = ("Athens", "Roma", "London", "Beijing", "Kiev", "Riga"); | ||
|
|
||
| my $f = sub {return scalar @_;}; |
aqrln
Jun 9, 2017
Contributor
I find it more readable to have extra surrounding spaces inside the braces, but feel free to ignore this comment if the current style is idiomatic in Perl.
| @@ -0,0 +1,4 @@ | |||
| #!/usr/bin/perl | |||
|
|
|||
| print "Actually, perl cant introspect functions :(\n"; | |||
aqrln
Jun 9, 2017
•
Contributor
So... I'd say we don't need this file at all, right?
This comment is still unaddressed.
| use Data::Dumper; | ||
| # spread operator is not needed in perl | ||
| # because only way for us to get our params is through array | ||
| # but i'll show how to iterate through params |
aqrln
Jun 9, 2017
•
Contributor
Maybe you should change the filename in this case.
This comment is still unaddressed.
| return $a + $b; | ||
| } | ||
|
|
||
| # declarement of package is between package statements. |
|
|
||
| use strict; | ||
| use Data::Dumper; | ||
| # i take the responsibility to rename this chapter too |
aqrln
Jun 9, 2017
Contributor
Don't worry about renaming. These files are not meant to copy the extract structure of the JavaScript samples. To the contrary, I find it detrimental that most people are doing exactly that thing instead of writing pieces of idiomatic code in a given language from scratch.
|
I hope now it's ready. |
| use strict; | ||
| use v5.10; | ||
|
|
||
| # everytime shift is called inside a function without array passed to shift operator |
|
|
||
| # everytime shift is called inside a function without array passed to shift operator | ||
| # it returns next argument | ||
| # note that shift is an operator, so it thinks of things next to it as of its arguments |
| @@ -0,0 +1,4 @@ | |||
| #!/usr/bin/perl | |||
|
|
|||
| print "Actually, perl cant introspect functions :(\n"; | |||
aqrln
Jun 9, 2017
•
Contributor
So... I'd say we don't need this file at all, right?
This comment is still unaddressed.
| #!/usr/bin/perl | ||
|
|
||
| print "Actually, perl cant introspect functions :(\n"; | ||
|
|
aqrln
Jun 9, 2017
•
Contributor
A superfluous empty line. The text files in Unix are supposed to have one empty line at the end, not two of them :)
This comment is still unaddressed.
| use Data::Dumper; | ||
| # spread operator is not needed in perl | ||
| # because only way for us to get our params is through array | ||
| # but i'll show how to iterate through params |
aqrln
Jun 9, 2017
•
Contributor
Maybe you should change the filename in this case.
This comment is still unaddressed.
| # it returns next argument | ||
| # note that shift is an operator, so it thinks of things next to it as of its arguments | ||
| # note that shift is a fucntion that awaits arguments |
| @@ -1,4 +0,0 @@ | |||
| #!/usr/bin/perl | |||
aqrln
Jun 10, 2017
Contributor
Can you please update the names of the other files so that there are no gaps in the ordering?
495ce31
to
90728b6
516d3a6
to
a2f04c4
there is always more than one way to do it.
Somewhere perl lacks functionality, so i try to propose (readable) analogues.