Speaking Python

rzed Dick.Zantow at lexisnexis.com
Tue Oct 14 10:27:55 EDT 2003


Sean Ross wrote:
> "David Mertz" <mertz at gnosis.cx> wrote in message
> news:mailman.72.1066076254.2192.python-list at python.org...
>> So quick test, how do you say:
>>
>>     def range_sum(N):
>>         if N < 0:
>>             return None
>>         elif N == 1:
>>             return 1
>>         else:
>>             tot = 0
>>             for n in range(1,N+1):
>>                 tot += n
>>             return tot
>
> def range underscore sum open bracket n close bracket colon new
> line indent if n less than zero colon newline indent
> return none newline dedent
> elif n equals equals 1 colon newline indent
> return 1 newline dedent
> else colon newline indent
> tot equal zero newline
> for n in range open bracket 1 comma n plus 1 close bracket colon
> newline indent
> tot plus equal n newline dedent
> return tot newline dedent
> dedent
>
> (this assumes that the user is aware that if no indent or dedent
> message is given, the current level of indentation should be
> maintained).

This seems pretty good to me, although I'd let 'colon' imply a
subsequent indent. Line breaks would be indicated by pauses and pitch
changes, which I think would be true in the above as well.

def range underscore sum open paren n close paren colon
if n less than zero colon
return none dedent
elif n equal-equal 1 colon
return 1 dedent
else colon
tot equal zero
for n in range open paren 1 comma n plus 1 close paren colon
tot plus equals n dedent
return tot
dedent
dedent

I would probably use "paren" to mean "open paren" as well, although
explicit might be better there. I once worked as a proofreader, where
one task was to record written material in a fairly stylized manner
similar to this. Punctuation was explicitly pronounced, as was space
where it was unusual. The listeners could generally make the best
sense of the minimum information; too much would slow reading down to
the point that comprehension suffered. Conventions (in reading) that
were usually honored tended to work better than explicit statement of
what was expected.

In code like:
    if n < 3: break    # don't worry about this stuff
The colon convention above would have to be overridden explicitly, so
it would come out more like Sean's reading.
if n less than three colon no-newline break [ and perhaps, "comment
don't worry about this stuff" ]

--
rzed






More information about the Python-list mailing list