Last active
December 16, 2015 05:59
-
-
Save anant-sogani/5388608 to your computer and use it in GitHub Desktop.
p6: Exception Reporting for Sequence operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I am trying to understand how exception reporting (for operator infix:<...>) works | |
under different invocations of the perl6 compiler. | |
Case-1: REPL | |
--------------------- | |
bash$ perl6 | |
> my @a = 1, 2, 8 ... * | |
Unable to deduce sequence | |
> | |
Case-2: Command-Line | |
--------------------------------- | |
bash$ perl6 -e "my @a = 1, 2, 8 ... *" | |
bash$ | |
Case-3: File | |
------------- | |
bash$ cat test.p6 | |
my @a = 1, 2, 8 ... *; | |
bash$ perl6 test.p6 | |
bash$ | |
Observation: Only REPL reports the exception. | |
Now, let's add some sort of de-reference. | |
Case-1: REPL | |
--------------------- | |
bash$ perl6 | |
> my @a = 1, 2, 8 ... * | |
Unable to deduce sequence | |
> say @a | |
> | |
Case-2: Command-Line | |
--------------------------------- | |
bash$ perl6 -e "my @a = 1, 2, 8 ... *; say @a" | |
Unable to deduce sequence | |
in method sink at src/gen/CORE.setting:10527 | |
in block at src/gen/CORE.setting:12592 | |
in sub coro at src/gen/CORE.setting:5740 | |
in method reify at src/gen/CORE.setting:5722 | |
in method reify at src/gen/CORE.setting:5492 | |
in method reify at src/gen/CORE.setting:5492 | |
in method reify at src/gen/CORE.setting:5492 | |
in method reify at src/gen/CORE.setting:5492 | |
in method reify at src/gen/CORE.setting:5492 | |
in method gimme at src/gen/CORE.setting:5882 | |
in method join at src/gen/CORE.setting:1293 | |
in method Str at src/gen/CORE.setting:5793 | |
in method gist at src/gen/CORE.setting:6099 | |
in sub say at src/gen/CORE.setting:7602 | |
in block at -e:1 | |
bash$ | |
Case-3: File | |
------------- | |
bash$ cat test.p6 | |
my @a = 1, 2, 8 ... *; | |
say @a; | |
bash$ perl6 test.p6 | |
Unable to deduce sequence | |
in method sink at src/gen/CORE.setting:10527 | |
in block at src/gen/CORE.setting:12592 | |
in sub coro at src/gen/CORE.setting:5740 | |
in method reify at src/gen/CORE.setting:5722 | |
in method reify at src/gen/CORE.setting:5492 | |
in method reify at src/gen/CORE.setting:5492 | |
in method reify at src/gen/CORE.setting:5492 | |
in method reify at src/gen/CORE.setting:5492 | |
in method reify at src/gen/CORE.setting:5492 | |
in method gimme at src/gen/CORE.setting:5882 | |
in method join at src/gen/CORE.setting:1293 | |
in method Str at src/gen/CORE.setting:5793 | |
in method gist at src/gen/CORE.setting:6099 | |
in sub say at src/gen/CORE.setting:7602 | |
in block at test.p6:2 | |
bash$ | |
Observation: -e and file mode report the exception only on de-reference. | |
They also add back trace. | |
REPL reports the exception as usual, but no back trace for the de-reference. | |
This creates the exception: | |
https://github.com/rakudo/rakudo/blob/nom/src/core/operators.pm#L168 | |
But what triggers different behavior? | |
timotimo++ explained on #perl6, and this is what I understood: | |
1. General theory first. Lists are lazy; they are evaluated only on de-reference. | |
So, if the evaluation were to produce an exception, it would only be at the moment of | |
the first de-reference. | |
my @a = 1, 2, 8 ... *; # does NOT produce the exception. | |
say @a; # does | |
2. The REPL prints out the value of the last expression in the line read by it. | |
https://github.com/perl6/nqp/blob/master/src/HLL/Compiler.pm#L238 | |
> my @a = 1, 2, 8 ... * # Line has only 1 expression. | |
The print triggers the de-reference. ("say <value>") ... TODO ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment