Skip to content

Instantly share code, notes, and snippets.

@anant-sogani
Last active December 16, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anant-sogani/5388608 to your computer and use it in GitHub Desktop.
Save anant-sogani/5388608 to your computer and use it in GitHub Desktop.
p6: Exception Reporting for Sequence operator
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