One line conditionals in boo?

Quick question to the people scripting with boo, in c++ and java you can express one line conditionals using the syntax:

condition? statement1 : statement2;

Which has the meaning:

if(condition){statement1;} else{statement2;}

However the ‘?’ operator syntax is not valid for boo, and attempting to write conditionals on a single line is also giving me compiler errors. Knowing that boo has the ability to use user defined macros (which I’ve never done before) I thought about defining my own syntax for expressing this type of thing, but I’m not sure it’s even possible since expanding something like:

hash = 23 * hash + check member, member.GetHashCode(), 0

to something like:

hash = 23 * hash + if member:
                       member.GetHashCode()
                   else:
                       0

is still a compiler error. It seems like what I really need to do is expand and replace the entire thing with one of the two statements at run time based on the value of the conditional. Correct me if I’m wrong but I suspect this is outside the power of macros. Anyone have any ideas on how I might implement the desired effect of one line conditionals in boo?

If you’re wondering why I want this behavior, as the above examples hinted at, I’m writing hash code functions for all my classes and writing out:

temp = 0
if member:
      temp = member.GetHashCode()
hash = 23 * hash + temp

for every member of my class is a pain in the butt.

https://groups.google.com/forum/?fromgroups=#!topic/boolang/gjaJiqN2qAg

–Eric

Thanks, you just saved my quite a bit of time, I was reading up on AbstractAstMacro and MethodInvocationExpression and thinking I might be able to define a macro that replaces the construct with a method invocation where the method’s statements and return type is determined by the arguments to the macro, but using the built-in mechanism is much easier :stuck_out_tongue:

On the other hand, I feel slightly saddened at losing the chance to learn about writing syntactic macros for the first time :neutral:

Eh, might as well go for it anyway. :wink:

–Eric