Hash: SHA1

On 7/31/10 11:17 , Mark J. Reed wrote:
> What if you say 'when test($_)'?  Or just 'when &test'?  How do you
> smart match on a function: call the func with the target as argument
> and use the return value, or call it without any argument and compare
> the return value to the target?  Does arity matter?  Or whether the
> function is declared to return a Boolean value/called in a Boolean
> context?

As I understand the spec:

  given <expr>  sets $_ to <expr>
  when test()   calls test with no argument
  when test($_) calls test with the topic
  when &test    uses the function object &test

It seems like this leaves $_ in an odd place, no longer really a "topic",
just a sort of shorthand which is sometimes implied (see for example ".foo"
as calling method foo() of $_) and sometimes not (given/when).

"when" as currently specced seems like it's just a synonym for "if".
Overgeneralization seems to have left $_ and "when" in a rather muddy spot.
 I feel like if the point of given/when is an overly general case statement
(as it currently seems to be), then using $_ is a Huffmanization waste
(surely $^a is good enough?) and confuses what $_ is supposed to mean, and
if the point is to be a general case statement then "when <expr> <block>"
should smartmatch <expr> against $_ instead of evaluating it with $_
available as a shorthand/topic.  Thus the confusion in the message that
started this thread:  most people expect the latter behavior, but are
getting the former which feels like a Huffmanization failure in addition to
confusing the question of implicit vs. explicit topicalization/$_.  (Am I
making any sense here?  I know what I'm trying to say, but am unsure that I
am describing it sensibly.)

- -- 
brandon s. allbery     [linux,solaris,freebsd,perl]      allb...@kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university      KF8NH
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/


Reply via email to