develooper Front page | perl.bootstrap | Postings from July 2000

Re: List for Perl 6 syntax? (Re: What about many many mailing lists?)

From:
Andy Wardley
Date:
July 25, 2000 12:11
Subject:
Re: List for Perl 6 syntax? (Re: What about many many mailing lists?)
Message ID:
200007251909.UAA04641@bandanna.cre.canon.co.uk
>     By `simplify', do you mean a smaller-footprint lexer, fewer grammar
> rules, something in terms of user/developer experience?  What's the problem
> that you wish to solve?  I'd like to discourage you from launching an
> umbrella mailing list for several unrelated solutions that all happen to
> solve problems in the category of `complex syntax'.

Good point.  I guess the best thing I can do is to post the pre-RFC 
of the point I had in mind.  I realise this list isn't the right place
for it, but I'm in something of a catch-22 situation.

Nevertheless, here's the idea, appended below.  Can I suggest that 
comments on this particular idea are mailed to me and I'll summarise 
back to the list or appropriate arena as it becomes available.  I'm 
generally clad in asbestos, but please try to be constructive wherever
possible.

The other issue that would be relevant to such a list (that has already
appeared here) is the introduction of the dot operator.  No doubt there
are all sorts of other ideas (both sensible and whacky) for changes in the 
basic syntax or structure of the language.  I'd like to see a forum where
these can be proposed and thrashed in or out, rather than have everyone
send Larry their ideas and have him waste time wading through the crap
to find the sweetcorn.  

A


Scalars, Arrays and Hashes
--------------------------

At present, a single variable name can be used to reference a scalar
($foo), an array (@foo), a hash (%hash), a sub-routine (&foo), an I/O
handle and output format, all stored in the not-so-friendly typeglob.
Let's pretend that I/O and formats will be moved elsewhere, and ignore
sub-routines for now, leaving us with the basic scalar, array and
list types.  

Rather than allow $foo, @foo and %foo to reference difference
variables, we could restrict them to just one, $foo.  $foo then
contains a scalar value, a reference to a hash array or a reference to
a list.  '@foo' becomes shorthand for the existing construct '@$foo'
(where $foo is a list ref) and '%foo' becomes shorthand for the
'%$foo' construct (ditto hash ref).  Similarly, we can remove the need
for '->' by treating '$foo[$n]' and '$foo{$k}' as the equivalent Perl5
constructs '$foo->[$n]' and '$foo->{$k}'

Let's look at some examples.

    # regular scalar
    $foo = 'bar';
    print $bar;

    # regular list ref, but use '@foo' to return contents
    $foo = [ 3, 6, 9 ];
    print @foo;			    # 3, 6, 9

    # ditto for hash ref
    $foo = { foo => 12, bar => 24 };
    print %foo;			    # foo, 12, bar, 24

    # assign to @foo to create and initialise contents of $foo list ref
    @foo = ( 3, 6, 9 );
    print ref($foo);		    # ARRAY
    print $foo[0];		    # 3

    # ditto hash ref
    %foo = ( foo => 12, bar => 24 );
    print ref($foo);		    # HASH
    print $foo{bar};		    # 24

    # list slice
    $foo = [ 2, 3, 5, 7, 11, 13 ];
    print @foo[0..2];		    # 2, 3, 5

    # hash slice
    $bar = { x => 10, y => 20, z => 30 };
    print @bar{ qw( x y ) };	    # 10, 20

    # hash slice returning keys and values
    print %bar{ qw( x y ) };	    # x, 10, y, 20

On the surface, nothing actually changes in the syntax.  The only real
gotcha is that you could no longer rely on $foo, @foo and %foo being 
different values.  

The rationale is perhaps best taken from Camel II (p 37):

  "This means that $foo and @foo are two different variables.  It also
   means that $foo[1] is an element of @foo not a part of $foo.  This
   may seem a bit weird, but that's okay because it is weird."

This is intended to make things a little less weird without changing 
any of the fundamental types or basic syntax.  






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