On Monday 15 July 2002 07:52 am, Brent Dax wrote:
> Ashley Winters:
> # > You've got a point. There's an easy way to say "I want a sub":
> # >
> # > my $sub = -> { ... }
> # >
> # > But I can't think of a similarly punctuation-intensive way
> # to say "I
> # > want a hash." (someone please step in and correct me).
> #
> # I nominate:
> #
> # $() == scalar()
> # %() == hash()
> # @() == array()
> #
> # For the above function:
> #
> # $hashref = %(function_returning_list_which_needs_to_be_hashified());
> #
> # That would make %() a hash constructor, just like {}.
>
> IIRC, $() and @() are already being used to denote scalar and array
> context. Of course, an array or hash in scalar context would probably
> referencify.
But we don't need @() for array context, we have @{} for that.
@{foo()} would pass foo() a 'want' value of 'ARRAY', would it not? In fact,
the block in @{} as a whole has a 'want' value of 'ARRAY', and that
wantedness propagates to whatever statements return a value from the block.
So, I still want to use @() as a smart array constructor. If you pass an array
reference to @(), it would dereference. If you passed a list, it would
construct a reference. Perhaps it could even copy an array if it's passed one
directly...
my @copy = [ *@orig ]; # before
my @copy = @( @orig ); # after
Or not. That's weird.
Ashley Winters
--
When you do the community's rewrite, try to remember most of us are idiots.