English-like Python

Aaron Brady castironpi at gmail.com
Sat Jan 17 04:09:40 EST 2009


On Jan 15, 7:02 pm, The Music Guy <music... at alphaios.net> wrote:
> Just out of curiousity, have there been any attempts to make a version
> of Python that looks like actual English text? I mean, so much of Python
> is already based on the English language that it seems like the next
> natural step would be to make a programming language which is actually a
> spoken one.
>
> For example, the following code...
>
> >>> import os
>
> >>> def list_files(dirname):
> >>>     for p in os.listdir(dirname):
> >>>         print p
>
> >>> list_files("some_dir")
>
> foo
> bar
> etc
>
> ...might be translated as...
>
> >>> Import the operating system module.
>
> >>> Define a new function as "list files" which accepts
>
>     "a path" and does the following:
>         For every item in the list returned by the operating system's
>         directory listing of the given path, do the following:
>              Print the item.
>
> >>> List files from "some_dir".
>
> foo
> bar
> etc
>
> Obviously, creating a parser capable of handling such "code" would
> require a very good understanding not only of the English language but
> also of how ideas expressed in spoken languages are represented in terms
> that a computer can understand.
>
> A language like this would, of course, blow a lot of staple coding
> coding concepts like "variables," "objects," etc. right out of the
> water. I think, however, that it could be done, and wouldn't necessarily
> have to be any slower than any other scripting language as any text/code
> could be cached as bytecode, just like Python.
>
> I know it's sort of silly but I think something like this would be very
> interesting, maybe even useful. ^_^

I'm actually moderately interested in this idea.  I was pursuing it a
while back, but didn't find anyone else interested.  You want to avoid
requiring an understanding, since English syntax doesn't always
guarantee its semantics.  Even a trivial transformation from non-
delimited English can cause an AmbiguityException.

The basics started like this:

'a= open "file1.py"' --> 'a= open( "file1.py" )'

'''
a= nat_list()
append 0 to a
append 1 to a
sort a
'''
-->
'''
a= nat_list()
a.append( 0 )
a.append( 1 )
a.sort()
'''

However, as you can see, 'open a' can map to both 'a.open()' and 'open
( a )'.  If 'open' is both a method on 'a', and a callable defined in
current scope, the expression is ambiguous and raises an
AmbiguityException.

If you're willing to constrain yourself to a subset of English which
the language will understand, you open a lot of doors; that is, if you
will accept a 'more natural Python' instead of 'true natural Python'.



More information about the Python-list mailing list