function as command problem (old from WIKI)
"Mark Hahn" <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
Mark Hahn wrote: The function as command feature was an approved feature until Serge ran into this gotcha. Now it is back on the consideration list and unless someone comes to it defense, it will be rejected. This means the print command will no longer be available in Prothon. You will only be able to use the print function and you will always have to type the parens as in print(a, b). Removing this command feature will also solve the double print problem in the console. Serge Wrote: I have also tripped over function as a command feature, notice the different results. Prothon result was unexpected Prothon 0.1 Interactive Console, Build 678, Jun 29 2004 (Ctrl-D to exit) >> print (8 + 1) + 8 9 9 8 >> Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print (8 + 1) + 8 17 >>> Mark Hahn Replied: This isn't really a function-as-command confusion. It is a print-as-"not-command" confusion. :-) You need to get used to print being a function and add a lot of parens. Paul Prescod Replied: I think that this is a straightforward bug: > > Prothon 0.1 Interactive Console, Build 678, Jun 29 2004 (Ctrl-D to exit) >>>> print (8 + 1) + 8 > 9 > 9 > 8 Everything on the line of the command should be part of the command. The only ambiguous case is when everything on the line is a single parenthesized expression. Maybe differentiating these cases takes too much lookahead in which case we could just say that parens in commands are purely groupers and never fuction as param delimeters. This isn't really a function-as-command confusion. It is a print-as-"not-command" confusion. You need to get used to print being a function and add a lot of parens. Recall that the goal of print as command is to avoid adding a lot of parens! Mark Hahn Replied: The print (8 + 1) is not a command, it is a function! Anytime a function attribute is followed by parens it is a function, period. How could it possibly be otherwise? All this talk of commands is superfluous. The function-as-command rule is: "You may put a function on a line by itself and leave out the parens". In this case the parens were not left out so it is not a command. Mark Hahn replied again: I guess we could change the definition of a command to be anytime a function attribute with the command_ flag is the first token on a line. I'll have to give this some thought. I think it would be impossible to parse. Paul Prescod: The current behaviour is an unexpected side-effect of the command behaviour. In my opinion it's a big enough problem to make me rethink my support for the feature. Mark Hahn: I now understand that it is impossible to parse as a command. Now I know why God created keywords. I'll put it back on the list for consideration instead of being an done deal. Mark: I found another ambiguity. print -1 gives "Function not found Error, Function $sub_ not found."