Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Thanks, ikegami, for drawing me in the right direction. After another hard time thinking and reading I've got clearer sight. Apparently, in my understanding the list concept is too much of a "data unit" in its own right. It is not easy for me to revise that after 15 years of (partly intense) Perl development. But I will put it in order:

There are scalars, and there are aggregates of scalars (arrays and hashes). Whereas these are referred to as data types, lists do not form a data type at all. Lists are a purely syntactic concept, simply in no different from, say, an addition except the fact that the operator is a comma, not a plus sign. The comma discards, in scalar context, the left operand and evaluates to the right one. This behaviour I guess is only reasoned by consistency with similar constructs and because C does it and because throwing an exception would be lame, even ridiculous.
"List context" refers to the ability of the right side of an assignment, or of an operator respectively, to accept more than one value at once, so the commata will just pass all their operands in sequence. And that is all to it.

Almost, indeed. A list, as said to think of it as one or more commata with their operands in a chain, is often flattened. This means, any contained aggregates are deaggregated to their parts. So, if at all, a better name of such an operator would not be list but deaggregate, flatten or scalars_in and it would be applied in certain situations they are not flattened. (By the way, a third use case has come to my mind, it is merely theoretical as well, and taking into account Perl could do without for so long and considering its age and exhausted extensibility, three use cases still are far from enough ...)

sub modify3scalars (\$\$\$) { ... } my @three = qw(values aggregated in_array); modify3scalars(scalars_in @three); # modify3scalars($three[0], $three[1], $three[2]); # But alas! scalars_in %hash - in what order?

Perl 6 provides a pipe symbol to put in front of arrays in order to make signatures of them, hasn't it? Long time no revisit its synopses and try Rakudo &co.


In reply to Re^4: There's scalar(), but no list(). Perl could need one for rare but reasonable use by flowdy
in thread There's scalar(), but no list(). Perl could need one for rare but reasonable use by flowdy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-16 05:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found