What else?

Stoffel Erasmus (ERASMUS@ufhcc.ufh.ac.za)
Tue, 25 Jan 1994 16:35:38 GMT+120

Hi

I used the following code segment as part of a question in a (suppl)
exam paper for CS1:

from String import lowercase
a2z = 'The quick brown fox jumps over the lazy dog'

for ch in lowercase:
if ch not in a2z:
print ch, 'not found!'
break
else: print 'All letters found.'

When proofreading the paper, one of my colleagues (who has not looked at
Python much) thought that I had indented the `else:' line incorrectly!

He, however, is very interested in programming language design --- in
the language that he is busy implementing the above could have been
written as:

a2z := `The quick brown fox jump over the lazy dog'

put first([all ch in {`a' .. `z'} | ch not in a2z])+` not found!' ?
`All letters found.'

(You'll notice some SetL and Icon influences ;-)

This brings one to the question whether {else} is the best keyword
to use with {for} and {while} loops. Is it not perhaps a case of false
economy to `overload' this keyword? I suspect that {end} might be a
better alternative here. One of the other alternatives might be
{finally} (as in the {try} statement), but it might be a bit too long.

This issue reminded me of something I had seen in Liskov & Guttag's book
``Abstraction and Specification in Program Development''. (I was hoping
for an alternative keyword.) When I went back I found that they used an
{except} *statement*, e.g.

while ...
...
end except when ... end

Am I missing the point?

---------------
Stoffel Erasmus (Erasmus@CS.UFH.Ac.ZA)
CS, Fort Hare, S. Africa