Skip to content
A scene from Ireland

Syntax

Having recently read up on python, I quite like it's syntax. It is clean and not noisy. However I do have some problems with it.

Firstly, I don't like back-slash line continuation. I actually hate, loathe, and despise it. It is ugly and error prone (e.g. an invisible space after the back-slash completely changes it's meaning).

The implicit line continuation using braketing is much more palatable. The only problem here is that no particular indentation is required on subsequent lines. I would suggests that subsequent lines must be indented at least as much as the inner most open bracket that hasn't been closed. This means that long expressions need to be breaketed to be wrapped on multi-lines, but that is not a big problem.

The use of a hanging comma in several contexts is quite elegant, particularly the hanging comma at the end of a print command disabling output of an end-of-line character.

However the usage of a hanging comma in tuple creation is unfortunate. A tuple with 2 or more elements is a , b [,..] however a tuple with no elements is () and a tuple with one element is a , (note the hanging comma). The reason for this needs is that a tuple is defined as being a comma separated list, and there is no place for commas when there are zero or more elements.

It is worth noting that comma separated lists in python are not always tuples. the comma separated list on the left of an assignment is not a tuple, at least not a tuple that can be manipulated as a first-class-citizen. Similarly the comma separated list of formal parameters to a function is not tuple.

It would probably be best to identify a tuple using a unique form of bracketing, just a braces identify a dictionary and square brackets identify a list.

While python (presumably) needs different brackets for dictionaries and lists due to its lack of static typing, my language would not. A list of zero or more items inside square brackets would be precisely that - a fixed list of items. It would have no identity within the language, but is simply a syntactic way to represent a group. If the group is given where a list is needed, it would be given an identity as a list. If the group is given where a particular struct is needed, the group is given an identity to match that structure.

Thus square brakets are used to enclose lists, and in particular a single element inside brakets is a list with single element, where as a single element inside parentheses is just hat element.

Another syntax which is good for indication lists in the colon as an infix operator. Thus a : b is a list of two elements, a : b : c is a list of three elements, so a: might be a list with one element and : is an empty list. I wonder if this is any better than the hanging comma. Possible the singleton list could be :a.

Multiple colons could allow more depth for a list, so :: :a:b :: :c:d would be a list containing two sublists, each of two elements. Going beyond 2 colons would not enhance readability.

It would be nice to allow a syntax like a , b:3 , c:4:5 which would create a list of lists. This could be used for passing values with formatting information to a print function. The example should produce [[a], [b , 3], [c, 4, 5]] however doing that would been that the fact that a is a singleton list is not obvious from it's immediate context, but only from neighbouring contexts.

If the formal parameter in this case called for a list of (open) lists of printable, width=0, precision=0, and if this type were not printable then there would be no ambiguity in parsing the actual arguments into the formal and filling in the defaults.

Obviously we need a section on formal parameters.