[% setvar title Less line noise - let's get rid of @% %]
Note: these documents may be out of date. Do not use as reference! |
To see what is currently happening visit http://www.perl6.org/
Less line noise - let's get rid of @%
Maintainer: Karl Glazebrook <kgb@pha.jhu.edu> Date: 15 Aug 2000 Last Modified: 28 Aug 2000 Mailing List: perl6-language@perl.org Number: 109 Version: 2 Status: Withdrawn
This RFC proposes that $x
, @x
, and %x
be ditched and
replaced with $x
for everything.
I withdrew it on 28th August as I figured I had lost the argument!
Back in the days of yore, Larry had a dream of a simple
typeless language. Variables were 'things', they could
hold numbers or strings, and manipulated without much
caring. The only important distinctions were whether they
were lists of things or hashes of things for which was
introduced the compact notation of @
and %
. Perl4 was
the anti-object-oriented language in an age when there
were Real Computers and Bill Gates was still trying to
flog BASIC.
Those days are gone. Perl 5 introduced the idea of Objects and now any variable can be one of ten million possible types all of very different behaviours.
Also in modern programming, lists are not longer simple lists, neither are hashes, we have multidimensional arrays, FIFO stacks, LIFO stacks, semi-infinite lists, etc. Basically there are innumerable ways of containing things and they are usually represented by objects.
I argue in this Brave New World the distinction between $x
, @x
and %x
are no longer useful and should be abolished. We might want
to use all kinds of array objects, why should @x be special? Rather
since there are infinitely many kinds of variable let's take the perl6
opportunity to make things simple and just use $x
for everything.
A RFC by Andy Wardley proposes `Highlander Variable Types' (`there can
only be one'). This addresses the same fundamental issues, but retains
@x
and %x
in the interests of backwards compatibility.
My proposal goes further: there should be NO @x
and %x
, only
$x
. This would make for a simplification of the language with
extreme prejudice.
All variables should be $x
. They should behave appropriately
according to their object types and methods. ARRAY objects
and HASH objects would provide methods (inline, optimised
of course) to make $x[42] and $x{Fred} do the right thing.
See the pdl-porters RFC on 'default methods' for elegant
ways to do this.
The only distinction left would be between things which are
variables (prefixed by $
) and not-variables (subroutines and
keywords).
Considerable I expect. :)
Overloading should happen everywhere.
print $x
Ought to use string overloading and be able to print an array or hash depending on type.
Similarly accesses such as $x[42]
or $x{Fred}
should function via
overloaded []
and {}
operators.
$y = $x + 1
Ought to be able to execute appropriate code whether $x is a scalar, a Perl array or a PDL array.
PDL RFC on 'Default Methods' - PDL RFCs coming Real Soon Now
RFC 9: Highlander Variable Types