[python-win32] A Suggestion for Python Syntax
Jim Vickroy
Jim.Vickroy@noaa.gov
Mon, 04 Nov 2002 08:45:05 -0700
Perhaps, a better audience for this proposal would be comp.lang.python
rather than to the MS Windows-specific group.
----- Original Message -----
From: "Hung, Le Khanh" <softex@hn.vnn.vn>
Date: Saturday, November 2, 2002 8:36 pm
Subject: [python-win32] A Suggestion for Python Syntax
> We all know that the statement like continue, break, .. are not
> structured.But they are useful for flexible control of the
> execution. It is mainly
> because of loop structure limitations.
> Here we suggest a strengthened loop and selective constructions.
> With them
> we need not to use break statement at all.
>
>
> CompoudStatement ::= dostatement | loop statement
> dostatement::=
> "do" suite
> GuardedCommand
> loopstatement::=
> "loop" suite
> GuardedCommand
> GuardedCommand::=
>
> ( ?[!] "check" Condition suite )*
> Condition ::= expression :
> Condition ::=
> ( "case" Condition suite )*
> These constructions could replace all Python's compound statements
>
> Some examples:
> 1. Python command
> if B1 : S1
> elif B2 : S2
> else S3
>
> is equivalent to
>
> do
> ?! check case B1 : S1
> case B2 : S2
> S3
> 2. Python command
> while B : S
> is equivalent to
> loop
> ? check B : S
>
> 3. # 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
> elif a[k]>x : j = k-1
> else break
>
> It is not obvious and natural here that there are two exit points
> from the loop.
> I would be happy to receive comments
> Best regards.
> Hung
>
>