Permalink
Browse files

where is want/wantarray gone?

  • Loading branch information...
moritz committed Aug 30, 2012
1 parent 856e7a1 commit e70c13b187f7b024f92572028d0ef46e6cd180e2
Showing with 19 additions and 0 deletions.
  1. +19 −0 answers.md
View
@@ -209,6 +209,25 @@ as an ordinary object.
A Failure returns False from a `defined` check, and you can exctract
the exception with the `exception` method.
+<span id="want" /><span id="wantarray" />
+### Why is `wantarray` or `want` gone? Can I return different things in different contexts?
+
+Perl has the `wantarry` function that tells you whether it is called in
+void, scalar or list context. Perl 6 has no equivalent construct,
+because context does not flow inwards, i.e. a routine cannot know which
+context it is called in.
+
+One reason is that Perl 6 has multi dispatch, and in a code example like
+
+ multi w(Int $x) { say 'Int' }
+ multi w(Str $x) { say 'Str' }
+ w(f());
+
+there is no way to determine if the caller of sub `f` wants a string or
+an integer, because it is not yet known what the caller is. In general
+this is requires solving the halting problem, which even Perl 6 compiler
+writers have trouble with.
+
<span id="meta" />
## Meta Questions and Advocacy

0 comments on commit e70c13b

Please sign in to comment.