Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

The "whatever" context

已查看 0 次
跳至第一个未读帖子

Yuval Kogman

未读,
2006年4月9日 07:43:162006/4/9
收件人 perl6-l...@perl.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 <nothi...@woobling.org>
http://nothingmuch.woobling.org 0xEBD27418

Larry Wall

未读,
2006年4月10日 16:25:352006/4/10
收件人 perl6-l...@perl.org
On Sun, Apr 09, 2006 at 02:43:16PM +0300, Yuval Kogman wrote:
: 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

I think that's already "whatever context". $x contains the resulting array.
It's only if you later say +$x that you'll get the number of elems.

Larry

Yuval Kogman

未读,
2006年4月10日 17:28:182006/4/10
收件人 perl6-l...@perl.org
On Mon, Apr 10, 2006 at 14:25:35 -0700, Larry Wall wrote:

> : my $x = grep { ... } @list; # returns count
>
> I think that's already "whatever context". $x contains the resulting array.
> It's only if you later say +$x that you'll get the number of elems.

Just for grep or for any function?

If just grep that means that grep simply doesn't use want.

If it's any function, then it means that all are constants are
"list" or "whatever", and all we really have are coercers.

0 个新帖子