Front page | perl.perl6.language |
Postings from April 2006
The "whatever" context
Thread Next
From:
Yuval Kogman
Date:
April 9, 2006 04:44
Subject:
The "whatever" context
Message ID:
20060409114316.GH24271@woobling.org
Hi...
I think that Perl 6 should have a "whatever" context, which is
essentially:
I want either array or scalar or whatever... You choose
so that functions like grep can return an array in "whatever"
context. This is best demonstrated using an example:
my $x = grep { ... } @list; # returns count
my $x = whatever grep { ... } @list; # the "natural" context for
# grep is array, no matter what the context really is
The usefulness of such a construct is two fold:
a. creating large anonymous structures with nested references or
scalar values without having to think (== good for when you are
evaluating a fucntion ref and you don't know what it is, but you
want the "natural" value to be returned).
b. writing eval bots and interactive shells:
(whatever eval $expr).perl;
;-)
--
Yuval Kogman <nothingmuch@woobling.org>
http://nothingmuch.woobling.org 0xEBD27418
Thread Next
-
The "whatever" context
by Yuval Kogman