plural and singular syntax in Perl5, PHP and Perl6

A

Andrew

Hi, fellow perlers

Before posting this I spent some time googling the web at large as well as searching this group's archive for posts related to the idea I wish to express, and, on cursory search, have not found any post, to date, which expresses the following -- assertively and emphatically. Yet, I feel (I compute), it DOES need to be said, emphatically:

I absolutely, unequivocally LOVE, support and herald (as in, "Hats off to Larry Wall's genius") the syntactical distinction Perl5 (and older) makes between SINGULARITY and MULTIPLICITY. Syntactically, per se. In other words, EXPLICITLY, by means of two distinct symbols ("$" and "@"). The additional syntax that deals with the INTERPLAY between singular and multiple is equally brilliant:

$array[3]

@array[3,4,5]

(the pre-pended symbols instantly signal (to the human reader) whether we are dealing with a multiplicity version of 'array' or just one of its elements (which is a scalar))

The brilliant play with "@" (plural) and "$" (singular) continues (in termsof language design), with:

@array[@cherry_picked_indexes]

and then, the whopper:

@hash{@list_of_keys} or @hash{qw(yada dooba boom}}

and then the enormously convenient (and code-economical) flexibility of nesting all of the above in a gazillion ways:

@hash{@{$two_dimensional[3]}}

@hash_one{keys %hash_two}

etc, etc, etc!

-----------------

So, the converse of my exuberance over this syntactical excellence of Perl5(as I assess it to be) is my complete bewilderment and puzzlement (puttingit mildly) over PHP's LACK of such distinction (syntactically) between singularity and multiplicity.

in PHP,

$this_could_be_a_scalar

and

$this_could_be_an_array

I believe (correct me if I'm wrong) that in PHP I am left guessing, by context, whether I'm looking at a scalar or an array.

So, I can only bash my head against the wall (note: LOWER-case "wall"), over the notion that not only does PHP's shortcoming (the lack of such succinct syntactical acrobatics as I've tried to suggest above, with the nested arrays and hashes in Perl) has gone COMPLETELY unnoticed (ignored/forgiven/even embraced as solid standard!?), I have learned (again, please correct me if I am wrong) that Perl itself (!!!) -- in its new and radically revised VERSION 6, is tossing out this baby with the bath water -- this gem of a syntax, obliterating the "$" versus "@" distinction, and (as I would put it) is descending to the painfully banal and ambiguous "$" for both scalars and arrays (?!) (that we observe in PHP)

I would also like to add that "singular versus plural" (one versus many) isunequivocally a FUNDAMENTAL dichotomy, NOT JUST in computer programming, but in human (natural) language and human psychology and logical processing/thinking. (Perhaps on a par with "zero versus one", or "existing versus non-existing", etc., but just as fundamental)

The syntactical differentiation has given us clarity and absence of ambiguity.

So there, I've said it. I hope it did NOT come across as a rant, but more as a rallying cry... at least a rallying to acknowledge the value of the "$" and "@" syntax and the fact that losing it would mean losing a whole lot of clever, succinct, and quintessentially Perl coding freedom and flexibility.
 
B

Bjoern Hoehrmann

* Andrew wrote in comp.lang.perl.misc:
So, I can only bash my head against the wall (note: LOWER-case "wall"),
over the notion that not only does PHP's shortcoming (the lack of such
succinct syntactical acrobatics as I've tried to suggest above, with the
nested arrays and hashes in Perl) has gone COMPLETELY unnoticed
(ignored/forgiven/even embraced as solid standard!?), I have learned
(again, please correct me if I am wrong) that Perl itself (!!!) -- in
its new and radically revised VERSION 6, is tossing out this baby with
the bath water -- this gem of a syntax, obliterating the "$" versus "@"
distinction, and (as I would put it) is descending to the painfully
banal and ambiguous "$" for both scalars and arrays (?!) (that we
observe in PHP)

http://feather.perl6.nl/syn/S02.html#Sigils

http://perlcabal.org/syn/Differences.html#Sigils

Note that the sigil for fetching a single element has changed from
$ to @; perhaps a better way to think of it is that the sigil of a
variable is now a part of its name, so it never changes in
subscripting. This also applies to hashes.

So the situation is not quite as you put it.
 
R

Rainer Weikusat

Bjoern Hoehrmann said:
* Andrew wrote in comp.lang.perl.misc:
[...]
I have learned
(again, please correct me if I am wrong) that Perl itself (!!!) -- in
its new and radically revised VERSION 6, is tossing out this baby with
the bath water -- this gem of a syntax, obliterating the "$" versus "@"
distinction, and (as I would put it) is descending to the painfully
banal and ambiguous "$" for both scalars and arrays (?!) (that we
observe in PHP)

http://feather.perl6.nl/syn/S02.html#Sigils

http://perlcabal.org/syn/Differences.html#Sigils

Note that the sigil for fetching a single element has changed from
$ to @; perhaps a better way to think of it is that the sigil of a
variable is now a part of its name, so it never changes in
subscripting. This also applies to hashes.

So the situation is not quite as you put it.

Eh ... sorry, but it is exactly as he puts it: The original idea that
$ is roughly the same as a 'singular article' while @ is a plural one,
has been replaced by the more 'conventional' ('conventional' here
supposed to mean 'more like what other language designers also did'
and absolutely not 'conventional' as 'what people usually do' since
'people' usually don't) concept that namespaces of differently-typed
variables are separate (I don't really have an opinion in favor of one
versus the other approach[*]).

[*] OTOH, Perl6 is about throwing away the baby (who would want an
ugly kid like that, anyway) while trying to keep the bathwater (can't
OUR [ugly] kid become just as popular with the help of something like
'also deemed to be useful by superficial association'?).
 
A

Andrew

They will say something like a simple variable has a $ in front and an
array has @. Then comes $foos[$i]; foos is an array, so where is its @
sign? It's often a long wait for a clear answer to that.

That is precisely the syntactic/semantic "algorithm" (if you will) of "%" and "@" !

The sigil "%" is used to refer to associative array container as a whole, but a "$" prepended to the same variable name instead, with curly braces assubscript, is one, singular reference (to a singular or plural value)

The sigil "@" (without its subscript, square bracket [....]) is, similarly,used to refer the entire array, but with the "$" instead of "@" one gets areference to a singular (scalar) value of that array.

Thus, both the associative array and the list, in Perl5, are each a syntactical/semantic SET. A set of (two) symbols, working together: [ "%" and "$"], and [ "@" and "$" ]. So, "%" shouldn't be seen as fixed and permanent,but one working in conjunction with "$", which syntactically replaces it whenever a singularity it contains is referred to.

With the associative array, you actually have A SET of (all) THREE sigils working together semantically/syntactically ( [ "%", "$", and "@" ] ):

%pets=qw(John dog Jane cat Bobby gerbil Laura monkey Mike cobra Betty falcon Sally dog Sheila rabbit Chuck dog Jeremy horse);

print join(', ', @pets{qw(Bobby Betty Jane)}), "\n";

or...

@slackers=qw(Mike Bobby Laura Sheila);

print join(', ', @pets{@slackers}), "\n";

or, using plural subscripting for both hash and array, one nested in the other:

print "The pets of the first and last slackers: ", join(', ', @pets{@slackers[0,$#slackers]}), "\n";

It seems to me that the above is brilliant language design, which allows for efficient (economical), beautiful code.

And my examples are just the surface of all that's possible, in terms of the coding power this interplay between the (distinct) plural and singular syntax grants. (Again: when you get to multi-dimensional arrays, multi-dimensional hashes and multi-dimensional array/hash hybrids, this sigil interplay in Perl5 is INVALUABLE, and probably unrivaled by any other language out there! (correct me if I'm wrong))

Also, again, conceptually, the notion of "singular" versus "plural" is FUNDAMENTAL to human psychology and reason. It is healthy and profitable to meticulously address and sort out logic related to it. This Perl syntax FORCES one to fully wrap one's mind around what's going on, conceptually... which is a good thing, in the end.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top