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.