Re: Fisher-Yates shuffle
On Fri, Apr 12, 2002 at 02:14:36PM -0700, Erik Steven Harrison wrote: -- On Fri, 12 Apr 2002 18:27:11 abigail wrote: On Fri, Apr 12, 2002 at 04:42:07PM +0100, Piers Cawley wrote: [EMAIL PROTECTED] writes: Why isn't if %foo {key} {print Hello 1} equivalent with the perl5 syntax: if (%foo) {key} {print Hello 1} Which keyword is it expecting? Keyword /els(e|if)/, or end of line, or semicolon. Sorry badly phrased on my part. The closing brace of {key} only ends the statement if it As i understand it (Tell me if I'm wrong) This %hash {key}; will not work, because space between the hashname and the brace was no longer allowed. This allows for Will not work is not correct. %hash {key} is parsed as an expression followed by a block. Whether that will work depends on the context. 'if' for instance is followed by an expression and a block..., so if %hash {key} *will* work, except it does something totally different than one might expect. if %hash{key} { ... } and also if $scalar { ... }. The only other white space rule is that white space after the closing brace of a closure, when that closure is the last argument of a user defined sub get's treated as a semicolon if there is nothing else on that line. This allows custom iterators to parse (or appear to parse) like builtins. myforeach @arry, %hash, $scalar { ... } #No semicolon required! What problems does this seem to cause - I don't see anything wrong. I don't see how (except in the case of closure as last argument) how it matters one way or another what kind white space appears between tokens. What am I missing? What you are missing is the new white space rule: \s+{ } shall be always be a block. Hence the difference between %hash {foo} and %hash{foo}. Abigail
Re: Fisher-Yates shuffle
- Original Message - From: [EMAIL PROTECTED] On Fri, Apr 12, 2002 at 04:42:07PM +0100, Piers Cawley wrote: [EMAIL PROTECTED] writes: Why isn't if %foo {key} {print Hello 1} equivalent with the perl5 syntax: if (%foo) {key} {print Hello 1} Which keyword is it expecting? Keyword /els(e|if)/, or end of line, or semicolon. Sorry badly phrased on my part. The closing brace of {key} only ends the statement if it is followed by /\s*$/, or a semicolon. You've got to be kidding. That makes the whitespace rules even more insane; your program can behave quite differently wether there's a space, a newline, or nothing between two tokens. Wonderful! People who tend to use -e all the time (like me) will love it. (Not!) Pasting code into IRC will be so much more fun. I don't think it's all that insane, Perl has history with implied semicolons. Perl today: A semicolon is required after every statement, except before a closing curly or end of file. Perl 6: A semicolon is also required after every block, except when the closing curly is on a line of its own, or it precedes another closing curly or end of file. As far as whitespace, you can get around that if%foo{key}-{printHello} # - and \s{ are kinda equivalent if%foo-{key};{printHello} Using - like that would be evil. We should put it in the test suite now... Ashley Winters
Re: Fisher-Yates shuffle
On Sat, Apr 13, 2002 at 12:51:06AM -0700, Ashley Winters wrote: Perl today: A semicolon is required after every statement, except before a closing curly or end of file. Perl 6: A semicolon is also required after every block, except when the closing curly is on a line of its own, or it precedes another closing curly or end of file. This is incorrect according to the examples in the apocalypse: if 1 { ...; break; } die panic: shouldn't see this; The apocalypse implies that the new rule applies to expression blocks--as opposed, I think, to statement blocks. As far as I understand these terms, if always takes statement blocks, so this rule does not apply. Who can clear up the confusion? Andrew
Re: Fisher-Yates shuffle
[EMAIL PROTECTED] writes: On Fri, Apr 12, 2002 at 04:00:37PM +0100, Piers Cawley wrote: X-posting to perl6-language [EMAIL PROTECTED] writes: As for cleanness, this is my interpretation of how perl6 is going to work: %foo = (); if %foo {key} {print Hello 1} %foo = (); if %foo{key} {print Hello 2} %foo = (); if %foo{key}{print Hello 3} Case 1 will print Hello 1; this is a block after the if statement. No, it will be a syntax error. The first closing brace does not end the statement, probably something like Block seen when keyword expected. Now I am confused. In perl6, we can leave off the the parenthesis around a condition, and I hope that it isn't required to have an 'elsif' or 'else' block. Why isn't if %foo {key} {print Hello 1} equivalent with the perl5 syntax: if (%foo) {key} {print Hello 1} Which keyword is it expecting? Keyword /els(e|if)/, or end of line, or semicolon. Sorry badly phrased on my part. The closing brace of {key} only ends the statement if it is followed by /\s*$/, or a semicolon. -- Piers It is a truth universally acknowledged that a language in possession of a rich syntax must be in need of a rewrite. -- Jane Austen?
Re: Fisher-Yates shuffle
On Fri, Apr 12, 2002 at 04:00:37PM +0100, Piers Cawley wrote: X-posting to perl6-language [EMAIL PROTECTED] writes: As for cleanness, this is my interpretation of how perl6 is going to work: %foo = (); if %foo {key} {print Hello 1} %foo = (); if %foo{key} {print Hello 2} %foo = (); if %foo{key}{print Hello 3} Case 1 will print Hello 1; this is a block after the if statement. No, it will be a syntax error. The first closing brace does not end the statement, probably something like Block seen when keyword expected. Now I am confused. In perl6, we can leave off the the parenthesis around a condition, and I hope that it isn't required to have an 'elsif' or 'else' block. Why isn't if %foo {key} {print Hello 1} equivalent with the perl5 syntax: if (%foo) {key} {print Hello 1} Which keyword is it expecting? Case 2 will not print anything. The print is in the 'then' part of the if. Correct. Case 3 will be a syntax error - an if statement with a condition, but not block. It won't be a syntax error *yet*. If there's a block immediately following then that will be treated as the 'then' block. If it's the end of file, or a nonblock, then it'll be a syntax error. Did the code show anything following it? No? Well, then assume it isn't there. ;-) Next time I'll show this to someone, I'll add a semicolon. Abigail
Re: Fisher-Yates shuffle
On Fri, Apr 12, 2002 at 04:42:07PM +0100, Piers Cawley wrote: [EMAIL PROTECTED] writes: Why isn't if %foo {key} {print Hello 1} equivalent with the perl5 syntax: if (%foo) {key} {print Hello 1} Which keyword is it expecting? Keyword /els(e|if)/, or end of line, or semicolon. Sorry badly phrased on my part. The closing brace of {key} only ends the statement if it is followed by /\s*$/, or a semicolon. You've got to be kidding. That makes the whitespace rules even more insane; your program can behave quite differently wether there's a space, a newline, or nothing between two tokens. Wonderful! People who tend to use -e all the time (like me) will love it. (Not!) Pasting code into IRC will be so much more fun. I'll treasure my perl5 sources. Abigail
Re: Fisher-Yates shuffle
On Fri, Apr 12, 2002 at 04:42:07PM +0100, Piers Cawley wrote: [EMAIL PROTECTED] writes: Why isn't if %foo {key} {print Hello 1} equivalent with the perl5 syntax: if (%foo) {key} {print Hello 1} Which keyword is it expecting? Keyword /els(e|if)/, or end of line, or semicolon. Sorry badly phrased on my part. The closing brace of {key} only ends the statement if it is followed by /\s*$/, or a semicolon. Hold on--why end of line? That should only make a difference if } is the only thing on the line... Luke
Re: Fisher-Yates shuffle
-- On Fri, 12 Apr 2002 18:27:11 abigail wrote: On Fri, Apr 12, 2002 at 04:42:07PM +0100, Piers Cawley wrote: [EMAIL PROTECTED] writes: Why isn't if %foo {key} {print Hello 1} equivalent with the perl5 syntax: if (%foo) {key} {print Hello 1} Which keyword is it expecting? Keyword /els(e|if)/, or end of line, or semicolon. Sorry badly phrased on my part. The closing brace of {key} only ends the statement if it As i understand it (Tell me if I'm wrong) This %hash {key}; will not work, because space between the hashname and the brace was no longer allowed. This allows for if %hash{key} { ... } and also if $scalar { ... }. The only other white space rule is that white space after the closing brace of a closure, when that closure is the last argument of a user defined sub get's treated as a semicolon if there is nothing else on that line. This allows custom iterators to parse (or appear to parse) like builtins. myforeach @arry, %hash, $scalar { ... } #No semicolon required! What problems does this seem to cause - I don't see anything wrong. I don't see how (except in the case of closure as last argument) how it matters one way or another what kind white space appears between tokens. What am I missing? -Erik Is your boss reading your email? Probably Keep your messages private by using Lycos Mail. Sign up today at http://mail.lycos.com
Re: Fisher-Yates shuffle
[EMAIL PROTECTED] writes: On Fri, Apr 12, 2002 at 04:42:07PM +0100, Piers Cawley wrote: [EMAIL PROTECTED] writes: Why isn't if %foo {key} {print Hello 1} equivalent with the perl5 syntax: if (%foo) {key} {print Hello 1} Which keyword is it expecting? Keyword /els(e|if)/, or end of line, or semicolon. Sorry badly phrased on my part. The closing brace of {key} only ends the statement if it is followed by /\s*$/, or a semicolon. You've got to be kidding. That makes the whitespace rules even more insane; your program can behave quite differently wether there's a space, a newline, or nothing between two tokens. Wonderful! People who tend to use -e all the time (like me) will love it. (Not!) Pasting code into IRC will be so much more fun. So use a semicolon. Or disambiguate with parentheses. Or try and convince Larry that he's wrong about this. Or use the perl5 syntax rules that will be understood by default. -- Piers It is a truth universally acknowledged that a language in possession of a rich syntax must be in need of a rewrite. -- Jane Austen?