3 ms·
That's just "I wish this was an expression language". Yeah, good idea, why isn't it? type Num = i32; // Or whatever your preferred numeric type is fn l
by tialaramex 1y ago
That's just "I wish this was an expression language". Yeah, good idea, why isn't it?
type Num = i32; // Or whatever your preferred numeric type is
fn lower_delta(a1: Num, a2: Num, b1: Num, b2: Num) -> Num {
let da = a2 - a1;
let db = b2 - b1;
if da < db { da } else { db }
}
- amiga386 1y agoA more useful example I found: REPEAT ... UNTIL CtrlC() OR (IF m:=GetMsg(wnd.userport) THEN ReplyMsg(m) BUT 1 ELSE 0) Which means loop until Ctrl-C is pressed, or an IDCMP message comes to the window (which must be replied to allow the sender to reuse/free the message, but otherwise we don't care what's in the message, because we know it's either a keypress or a mouseclick, and both end the loop). The comma operator, or "BUT", lets us capture the result of GetMsg(), go down a positive "we got a message so end the loop" path, but also fits in a ReplyMsg() so we don't have to deal with it anywhere else
- tialaramex 1y agoLike I said though, you wanted an expression language, just have an expression language loop { // ... if ctrl_c() || match get_msg(wnd.userport) { None => false, Some(m) => { _ = reply_msg(m); true } } { break; } }