About Python Syntax
Hung, Le Khanh
softex at hn.vnn.vn
Thu Oct 17 01:23:42 EDT 2002
Dear Sirs and Mmes.
I'm not sure that I have send this e-mail to the right address. If not, please forward it.
Thank you.
We are interested in Programming Language Methodology in general and in Language Structure for long time.
When i first have seen Python, i was deeply impresed by its simplicity and usability, especialy for beginers.
Before, we have developed some control structures for Programming Language and now would like to deliver here.
The Python's unstructured statements like break, continue, while, if elseif else could be replaced by more declarative
The short sketch of these structures:
(some of keywords has been used for other's Python statement so we had to use some other symbol. But it play no important role for describing our main concept. I tryed to use Python's Syntax description)
CompoudStatement ::= dostatement | loop statement
dostatement::=
"do" suite
GuardedCommand
loopstatement::=
"loop" suite
GuardedCommand
GuardedCommand::=
( ?[!] "check" Condition suite )*
Header ::= "forall" target_list "in" expression_list : suite
Condition ::= expression :
Condition ::=
( case Condition suite )*
In my opinion those constructions could replace all Python's compound statements
Some examples:
if B1 : S1
elif B2 : S2
else S3
is equivalent to
do
?! check case B1 : S1
case B2 : S2
S3
while B : S
is equivalent to
loop
? check B : S
for i in a[:] :
S
is equivalent to
forall i in a[:]
S
for i in a[:]
while(1):
S1
if(B) break
S2
S3
is equivalent to
for i in a[:]
loop
S1
? check B : S2
S3
Here is the more practical example:
# Search in Array
# This is common sketch for searching algorithms
InitSearchScope
loop
? check NotEmptySearchScope:
TakeAnElement
? check NotFit:
SrinkSearchScope
# Implementation of Sequential Search
i = lo; # Scope is from lo to hi
loop
? check i < hi : # i is in Scope
? check a[i] != x :
i+=1
# Binary Search
i,j = lo,hi
loop
? check i<j : k = (i+j) / 2
? check
case a[k]<x : i = k+1
case a[k]>x : j = k-1
This bit of code has the same structure as the previous!
# For comparison, here is Python's Binary search
i,j = lo,hi
while i<j : k = (i+j) / 2
if a[k]<x : i = k+1
elseif a[k]>x : j = k-1
else break
The more important reason for introduction of new control structures for Python is the possibility of making a fullly visual interactive IDE for Python. Programmer would be not able to make syntax errors!
Best regards.
Hung
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20021017/a721376c/attachment.html>
More information about the Python-list
mailing list