The semicolon operatorMay 15. 2012
Sequencing of expressionsThe semicolon operator in Wirbel behaves exactly like the widely unknown comma operator in C: It combines two expressions A and B into one new expression C. The type and value of C is that of B, but A is executed nevertheless. The semicolon operator comes in handy in lambda expressions. In lambda expressions you cannot use statements but only one expression. With semicola you can create sequences of expressions to be executed, nevertheless. Because the type of A and B are completely independent, A may even have the type void. That's what functions like print return. The following two examples illustrate this: semicolon.w a = 1 ; "Hello" print(a) The output is Hello, which is the value of 1 ; "Hello". Its type is string. The type of 1 is not taken into account. Now look at a second example: semicolon_lambda.w
b = lambda x: print("x is %s" % x) ; x*2
print(b("hi"))
The output is: user@host> wirbel semicolon_lambda.w x is hi hihi |
| |||||||||||||||||||||