Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
the : syntax then indent
#1
is there any case in python where a statement ends in : and the next line does not have to be indented or there is a valid indent where the previous line did not end with a : character? i am curious because it seems to me that these two things are a redundant means to begin a deeper level block. i've been thinking about making my own parser of a special code and pondering if i need both in the syntax, or if it is a useful redundancy to have in a python-like syntax.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
As far as I know, an indented block always follows a line that ends with : . There may be a comment after the : and a few lines of
comment before the first indented line. One could remove the : here, but the : is needed in the single line syntax
for i in range(3): x[i] *= 2
Another interesting feature of the language is that one can remove completely the dot operator. I have a system on my computer where I can write python code without the dot operator. I call it 'dotless' python. I said this to GvR a long time ago in a comment on his blog but he didn't reply.
Reply
#3
The colon and the indentation are redundant in terms of starting the block, but the unindentation is the only certainty in ending a block of code. So you could get rid of the colon, but not the indentation.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
did bdfl write anything about why the colon is a part of the language syntax? i recall a friend showing me a language way back around 1978 that used indentation to nest new blocks and unindentation (undentation) to end a block. i do not recall if it had colons.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
I believe he got the indentation and the colon from ABC, which he was working on when he had the idea for Python.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#6
ABC obviously had to exist before Python. now i wonder if ABC was the language my friend showed me back around 1978. but i am still thinking of making a syntax without colons and a parser for it. maybe it should allow colons as optional because there will be some people typing a colon by habit.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#7
Skaperen Wrote:i wonder if ABC was the language my friend showed me back around 1978
You can download implementations of ABC at Steven Pemberton's web page. Many other very nice topics are discussed on this page, such as invisible xml. As far as I know, ABC was created around the mid 80s.
Reply
#8
i looked around there, but i didn't see a date for creation of ABC.

i do remember that my friend described it as a language well suited for beginners to learn to program with. he wanted to know if i could write a compiler or interpreter for it. we both worked in the school's main computer center giving programming help to users (both students and faculty) of the IBM 370/155 mainframe.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020