Syntactic Confectionery Delight | |
PerlMonks |
Re: Some Insights from a Traveler Between Languagesby tlm (Prior) |
on Apr 23, 2005 at 19:55 UTC ( [id://450789]=note: print w/replies, xml ) | Need Help?? |
Recently there was an exchange on some of the points you raise. Even though tye and merlyn make very good points to the contrary in the thread I just cited, I still think that Perl should 1) provide a list operator as counterpart to scalar, 2) revoke the rule that "a list cannot exist in a scalar context" (after all, it is possible for a scalar to exist in a list context); and 3) define the value of a list in a scalar context as the length of the list. The latter would not prevent a function from responding idiosyncratically in scalar context; e.g.: tye pointed out in the thread cited above that most uses of this list function would be to get the number of items a function would return in list context, and therefore that it would be better to call it count instead. I agree that most uses of list would be for counting, but I still think that it should be called list. My reason for this is largely formal. Perl imposes no restrictions on how a programmer (or even perl itself) may exploit context information. For example, Perl does not proscribe functions that have side effects only when called in a list context. Since Perl allows programmers complete freedom in how they exploit context information, it is only fair that it also provide ways for programmers, who routinely use code written by others, to control the context in which functions evaluate without having to resort to tricks like =()=. (Before I get thoroughly roasted for all this heresy I'm quick to add that the I am aware that any formal merits of the scheme above may not be sufficient to warrant the refactoring of perl that would be required to implement it.) As a bonus, I think it would be easier to teach context rules, and Perl gurus like tye and merlyn would not have to spend so much time getting blockheads like me to understand that "lists can't exist in scalar context." the lowliest monk
In Section
Meditations
|
|