Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > plural and singular syntax in Perl5, PHP and Perl6

Reply
Thread Tools

plural and singular syntax in Perl5, PHP and Perl6

 
 
Andrew
Guest
Posts: n/a
 
      12-31-2012
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.
 
Reply With Quote
 
 
 
 
Bjoern Hoehrmann
Guest
Posts: n/a
 
      01-01-2013
* 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.
--
Björn Höhrmann · private.php?do=newpm&u= · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
 
Reply With Quote
 
 
 
 
Rainer Weikusat
Guest
Posts: n/a
 
      01-02-2013
Bjoern Hoehrmann <> writes:
> * 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'?).
 
Reply With Quote
 
Andrew
Guest
Posts: n/a
 
      01-22-2013
On Tuesday, January 15, 2013 5:38:37 PM UTC-5, Mladen Gogala wrote:
> On Sun, 13 Jan 2013 20:44:45 -0800, David Harmon wrote:
>
>
>
> > 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Training Institute In Delhi, Live Projects on PHP. Short TermPHP Courses, PHP Scripts, PHP Training with Live Projects. Rajive Narain Java 0 09-18-2009 10:47 AM
#plural? or #singular? Mark Dodwell Ruby 20 05-26-2008 11:14 AM
Singular value decomposition in Java Patricia Shanahan Java 1 06-04-2007 08:58 PM
Where to get a C program for Singular Value Decomposition (SVD) eyh5@ece.cornell.edu C Programming 2 11-06-2006 10:29 PM
Singular and Plural Classes - conventions VisionSet Java 17 02-24-2006 08:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57