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

Idea for making @, %, $ optional

Thread Next
From:
Millsa Erlas
Date:
June 3, 2005 01:21
Subject:
Idea for making @, %, $ optional
Message ID:
20050602222319.27465.qmail@lists.develooper.com
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 
usage.

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

**Subroutines

sub hello {
print "hello!\n";
}

#**Arrays
#Define
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];

#**Hashs
#Define
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};

#**Scalars

#Define
scalar hello="hello";

#Scalar context

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

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

#Dereference:

#Every ampersand after the initial one attempts to deference the
# one level of referncing:
%hash=&&ref;
# THis would unwrap a reference in a reference
%hash=&&&ref;

# Dereference a reference in a hash
%hash=&&hash{ref};

#or
# 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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About