[Compiler-sig] Re: if .. elif:
Jeremy Hylton
jeremy@zope.com
Sun, 14 Apr 2002 00:09:53 -0400
>>>>> "FB" == Finn Bock <bckfnn@worldonline.dk> writes:
FB> Hi Maybe I'm missing something, but I think the If() constructor
FB> is a bit too simple to handle a list of 'elif:' parts.
FB> If(expr test, stmt* body, stmt* orelse)
I was expecting to encode 'elif' parts as a series of new If()
constructors in the orelse slot.
if x == 1:
print 1
elif x == 2:
print 2
else:
print 3
If(Compare(Lvalue(Name(x)), Num("1")),
[Print(NULL, [Num("1")], False)],
[If(Compare(Lvalue(Name(x)), Num("2")),
[Print(NULL, [Num("2")], False)],
[Print(NULL, [Num("3")], False)])])
Does that make sense?
(And, yuck, the Lvalue is a pain.)
Jeremy