Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^4: Generate the perl sequence 1, 11, 111, ....

by TimToady (Parson)
on Oct 14, 2008 at 23:39 UTC ( #717117=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Generate the perl sequence 1, 11, 111, ....
in thread Generate the perl sequence 1, 11, 111, ....

1. I don't know if it's the same reason why that particular symbol was chosen, but I find the appearance of [\ ] to be extremely representative of the "take partial results" thingie since it looks much like a triangle which is maximally evident here, given that the output "is also a triangle" but has more general sense with common reduction situations one may naturally feel psychologically at ease with, charachterized by "results that grow." (Sorry for the sloppy parliance, which I believe to be appropriate here, though.)
Indeed, language design is "sloppy", which is why almost nothing goes into the design unless there are multiple good reasons for it. But yes, the triangular visual metaphor was certainly one of the reasons for picking the backslash. Another reason is simply that very few infix operators (read "zero" in standard Perl 6) begin with backslash. Another visual or psychological consideration is that a more complicated result should be represented by a "larger" operator. A very minor consideration is that backslash tends to "escape" things into their "meta" equivalent, though what exactly is being "escaped" here is not at all clear. As for the use of square brackets on both this and the unbackslashed forms, that is justified by the cultural association with list constructors and subscripts that come from the earliest days of Perl (not to mention the fact that many functional programming languages denote lists using square brackets). And in the backslashed form, it needs something with a vertical feel on the left representing the "left margin", or we lose much of the triangular feeling, so square brackets work nicely together with backslash that way. It all adds up to an almost overwhelming feeling of necessity--which is why the language designer must also guard against adding up too many apples and then comparing them to orangutans.
2. I also wonder if the same behaviour can be obtained by means of a suitable adverb (i.e. whether one such adverb is provided!) acting on [ ]... well if adverbs do apply to meta-operators at all, that is, which I ignore altogher;
I personally believe that adverbs are more usefully applied to the base operator, and currently such adverbs must really go outside the metaoperator since metaoperators are designed to be parsed as tokens, which don't like spaces or other complicated syntax inside, or it becomes impossible to follow the longest token rule. If we consider [min] to be a single token, then what will the lexer make of something like: [min :cmp{ $^a leg $^b }]? So currently I consider metoperators to be transparent to adverbs. (And again, there are other considerations--multiplicative factors on the number of meta-modified lexemes tends to result in an explosion of possibilities for the DFA matcher that is feebly trying to figure out the next token without using up gigabytes of stack and heap.)
3. last and perhaps most importantly, given that [\ ] returns the list of partial reductions, shouldn't it for completeness also include the 0-th one? Namely, the neutral element for the bynary operation passed to it, if any. (I already can feel that the "if any" bit could prompt for a negative answer, yet I feel that a positive one would be mathematically more appropriate.)
Funny thing, I was just thinking about that myself. As usual, I can argue it all three ways:
  • Completeness demands that we return the 0th element, and consistency demands that we do so even for operations that have no neutral element, which should therefore return undef for the 0th result. The user can always throw it away.
  • The whole point of definedness is to tell you when something is defined, so rely on that to decide whether to return the neutral element. Nobody is going to go around comparing two such lists to see if they're the same, since they're potentially infinite, and even if they did, they'd want to normalize out any initial undefined element on the assumption that different ways of specifying the same sequence might or might not produce such an element.
  • Look, you two idiots, the current behavior is the sanest, insofar as, if the user really wants the stupid neutral element to come out first, all they have to do is supply it as the first argument!
So maybe we should decide this in the next PerlMonks poll. :)


Comment on Re^4: Generate the perl sequence 1, 11, 111, ....
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://717117]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2014-09-22 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (180 votes), past polls