On 09/08/2019 12:50:14, Steven D'Aprano wrote:
On Thu, Aug 08, 2019 at 04:28:28PM -0700, Barry Warsaw wrote:
I find it difficult to imagine a more meaningful distinction than that
between syntax and semantics.
The distinction between syntax and semantics can sometimes be blurred.
Certainly in spoken languages.  What about program code?

Should x/0 be a SyntaxError? It too is "disallowed", and we have to
change our code.
No, because x might be an instance of a class (extended numbers?) that allows division by zero.

Should None[x] be a SyntaxError? It too is "disallowed", and we have to
change our code.


It's allowable syntax with defined runtime semantics: raise a TypeError if x exists, and a NameError if it isn't.  Conceivably some programmer might find a use for it. But since it always raises an exception, it would probably be more helpful in the long run if it *were* a SyntaxError.  It *isn't*, because (I assume) detecting this and similar
idioms, e.g.    {}[0]   , would complicate the parser/compiler too much.

Your examples show, I claim, that even in program code the distinction between
syntax and semantics is not always obvious.

I suggest the only watertight definition of a syntax error is something which raises an exception at compile time.  Obviously this can depend not only on the code,
but also on the compiler.

Rob Cliffe
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/FKZSJS2JZ3DXENYOI3AFPGDH3TOH5C5U/

Reply via email to