plural and singular syntax in Perl5, PHP and Perl6

Discussion in 'Perl Misc' started by Andrew, Dec 31, 2012.

  1. Andrew

    Andrew Guest

    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.
     
    Andrew, Dec 31, 2012
    #1
    1. Advertising

  2. * 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 · mailto: · 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/
     
    Bjoern Hoehrmann, Jan 1, 2013
    #2
    1. Advertising

  3. 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'?).
     
    Rainer Weikusat, Jan 2, 2013
    #3
  4. Andrew

    Andrew Guest

    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.
     
    Andrew, Jan 22, 2013
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VisionSet
    Replies:
    17
    Views:
    1,032
    Roedy Green
    Feb 24, 2006
  2. Simon Strandgaard

    [ann] regexp-engine-0.8, perl5 + some perl6

    Simon Strandgaard, Apr 22, 2004, in forum: Ruby
    Replies:
    5
    Views:
    157
    Simon Strandgaard
    Apr 22, 2004
  3. Mark Dodwell

    #plural? or #singular?

    Mark Dodwell, May 23, 2008, in forum: Ruby
    Replies:
    20
    Views:
    391
    Robert Dober
    May 26, 2008
  4. kj
    Replies:
    1
    Views:
    123
    John Bokma
    Mar 27, 2005
  5. Perl6, Perl5, and CPAN

    , May 2, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    133
    Michele Dondi
    May 3, 2007
Loading...

Share This Page