develooper Front page | perl.perl6.language | Postings from June 2005

Idea for making @, %, $ optional

Thread Next
Millsa Erlas
June 3, 2005 01:21
Idea for making @, %, $ optional
Message ID:
I have thought of an interesting idea that may allow Perl 6 to make the
$, @, and % optional on many uses of variables. This involves simply 
extending the function namespace to include all kinds of structures, and 
thus the function namespace does not require symbols, they are optional.

The intention here is not to eliminate $, @, % and friends, just make 
them optional! I believe people should be able to make the choice as to 
which way to do things, we should give the programmer as much freedom 
and as any many ways to do things as possible, not constrain them but 
empower and free them from restrictions.

Also, a goal I have tried to follow here is to implement this feature 
without affecting the existing usage grammar and rules of the Perl 6 
language at all. This is a good goal i believe, my intention is just for 
this to be an additional extension to Perl 6, not change its existing 
grammar and parsing rules at all, just expand upon it. Perl 6 is a great 
language and I like what has done so far. This is not an attempt to 
change what has already been defined, but rather provide an additional 

These are just some initial ideas, they may be able to be improved upon, 
or benefit from refinement.


sub hello {
print "hello!\n";

array hello=("1", "2", 3");

#in Array context:
@array=&array; #or
@array=array array;

#in Scalar context:
$element=array[1]; #or
$element=scalar array[1];

hash hash1=(hello=>"hello1", hello2=>"hello2");

#In hash context=
%hash2=&hash1; # or
%hash2=hash hash1;

#scalar context
$hello=hash{hello}; # or
$hello=scalar hello{hello};


scalar hello="hello";

#Scalar context

$hello=hello; # or
$hello=scalar hello;

#Make reference
scalar ref=\&hash; #or
scalar ref=mkref &hash; #or
scalar ref=mkref hash hash;


#Every ampersand after the initial one attempts to deference the
# one level of referncing:
# THis would unwrap a reference in a reference

# Dereference a reference in a hash

# A deref keyword for convenience:
%hash=deref ref; #or
%hash=hash scalar ref; #or
%hash=hash hash ref;

This is just an initial sketch, it may need or benefit from refinement.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About