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

Re^3: C-style for loop

by JavaFan (Canon)
on Nov 17, 2008 at 17:41 UTC ( #724090=note: print w/ replies, xml ) Need Help??


in reply to Re^2: C-style for loop
in thread C-style for loop

I would go as far as claiming that what's in the parens itself in that case is yet another minilanguage (very closely related to Perl itself: it consists of exactly three Perl statements!) that does not fit in other parts of Perl's syntax, and thus a very special case: of course Perl 6 knows better and gives it an entirely different name which IIRC is C<loop> and not by chance takes one letter more wrt "for" since that's for huffmanization and in fact it is thought to be on a much sparser basis to begin with.
A couple of points.
  • I won't deny Perl 6 gives it a different name, but the Perl 5 parser already knows the 'loop' construct. perly.y has a token 'loop' under which all loop, including the bare block and 4 (!) 'for' constructs. (for my $v (), for $v (), for (), are all parsed separately).
  • The C-style for loop doesn't have three statements inside the parens, it has three expressions - each of which may be empty.
  • Each of the expressions is a different kind of expression (first introduces a scope, second is a boolean expression, third may introduce a scope), but they do fit in other parts of Perls syntax. Of course, you are right in the sense that 'for (;;)' is the only place that requires exactly three expressions.
  • I don't understand the huffmanization remark. Huffmanization means you're minimizing the length of the average program, using tokens that are never a prefix of another token. Making little used tokens longer makes sense, but only if you either the freed up token for something that's used more often, or if the freed token is a prefix of some other token that cannot be replaced. So, what keyword starting with 'for' is used in Perl6? Surely you aren't saying in Perl6 'format' is going to be used more often than 'loop'? ;-)


Comment on Re^3: C-style for loop
Re^4: C-style for loop
by blazar (Canon) on Nov 18, 2008 at 13:59 UTC
    I won't deny Perl 6 gives it a different name, but the Perl 5 parser already knows the 'loop' construct. perly.y has a token 'loop' under which all loop, including the bare block and 4 (!) 'for' constructs.

    I personally believe I lost you: do you mean that C<loop> is a Perl 5 reserved keyword with some semantics associated to it? It may well be, but I've never seen it in use. Can you give an actual example of usage shedding some light on the issue?

    I (also) personally believe that somehow your phrase is unfinished: "all loop" seems the subject of something... but there's a verb missing.

    Each of the expressions is a different kind of expression (first introduces a scope, second is a boolean expression, third may introduce a scope), but they do fit in other parts of Perls syntax. Of course, you are right in the sense that 'for (;;)' is the only place that requires exactly three expressions.

    Fair enough... both on the fact that they are expressions and that they do fit in other parts of Perl's syntax. Just as a minor point: is it true that the third may introduce a scope too? I knew that only variables declared with my in the initialization section were lexically scoped to the block following the parens...

    I don't understand the huffmanization remark. [ ...]

    I probably used the term improperly, then, based on what I heard: basically it all boils down to having a bare C<for> consisting of three characters for the supposedly more often used Perl-style (and only!) "for" loop and a C<loop> consisting of four characters for the supposedly less often used kind of loop that we now</c> call C-style "for" loop. Two beasts different enough from each other to warrant a totally different name altoghether in Perl 6.

    --
    If you can't understand the incipit, then please check the IPB Campaign.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-09-02 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (32 votes), past polls