5 ms·
Actually, he prefers the old syntax. The new syntax is there because he got swayed by practical considerations. For instance, back in July 2000, there was thi
by marvy 11y ago
Actually, he prefers the old syntax. The new syntax is there because he got swayed by practical considerations. For instance, back in July 2000, there was this:
https://www.python.org/dev/peps/pep-0214/ https://www.python.org/dev/peps/pep-0214/
Where he basically said "Maybe print should be a function, but... nah".
Two years later, he says he regrets it:
http://legacy.python.org/doc/essays/ppt/regrets/PythonRegrets.pdf http://legacy.python.org/doc/essays/ppt/regrets/PythonRegret...
And the benefits are explained here:
https://www.python.org/dev/peps/pep-3105/ https://www.python.org/dev/peps/pep-3105/
- lisper 11y agoCould have had the best of both worlds by giving the print function a different name from the print statement (e.g. printf for the function). Then the print statement could have been deprecated gracefully. (And then the print function could have been renamed print if anyone really cared at that point.)
- eru 11y agoOr alternatively they could have remove the mandatory parentheses around function calls, and kept the old syntax and made print a function. (Sorry, trolling. ML-style function call syntax would clash a lot with other parts of Python.)
- marvy 11y agoI don't know ML, but I really do wish Python had this feature. The only problem I see is that this makes it hard to refer to a function without calling it (see below). How does ML solve this? def g(): return 5 assert g() == 5 assert g != 5 Without parenthesis, how can the language distinguish the last two lines? How does ML do it? Would the same trick work in Python? I know Ruby has optional parenthesis, but functions aren't quite as first class there as they are in Python, which is why the have Proc and whatnot.
- cheepin 11y agoYour example, g actually takes the unit tuple, and returns 5. In ML, in general, you have to disambiguate with parentheses sometimes, but the compiler is very strict about types, so it's usually pretty easy to tell where they need to be. Look here: http://try.ocamlpro.com/ http://try.ocamlpro.com/ Try this code: let g() = 5 g() == 5 g != 5 First line defines the function. Second line should evaluate to true. Third line doesn't type check because a function is not the same type as a literal.
- eru 11y agoExactly. My favourite ML-style language is Haskell, and there we almost never want to call a function with the unit-tuple as an argument. Haskell does differentiate between IO-actions and functions. Here is an example: main = do let printFive = print 5 print 1 printFive print 6 printFive Will print 1 5 6 5 The type systems helps enormously keeping things straight here, but the basic concept would work in a non-statically typed language, too.
- marvy 11y ago> the basic concept would work in a non-statically typed language, too How? How do I compare. say, two functions for equality, without comparing the return value instead?
- eru 11y agoOh, I should have been more explicit: The decoupling of function calling and IO actions can work in non-statically typed languages, too. Your question concerns a different topic. To give something like an answer: that problem can only occur with `functions' of zero arguments. Haskell sidesteps the issue by requiring all functions to have exactly one argument.
- marvy 11y agoOkay, that's cheating. Or rather, that's fine for them, but is no help in porting this idea to Python, which definitely has functions of zero arguments, and they aren't even that rare. (Although comparing functions for equality is rare, but it should at least be possible.)