[Compiler-sig] Re: if .. elif:

Finn Bock bckfnn@worldonline.dk
Sun, 14 Apr 2002 13:49:13 GMT


[Jeremy]

>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?

I guess it will work, but I don't like it much. It doesn't feel honest
to the actual python syntax. 

regards,
finn