noname icon indicating copy to clipboard operation
noname copied to clipboard

Enhancement for ITE

Open katat opened this issue 1 year ago • 3 comments

The current ITE requires the branches to be variables:

bits[index] = if bit_num == 1 {true_val} else {false_val};

This restriction makes it inconvenient to use the ITE in noname. Ideally, we should allow expressions in the branches.

Examples for feature enhancement:

Allow literals

bits[index] = if bit_num == 1 {true} else {false};
num = if cond == true {1} else {0};

Allow expressions

let mut counter = 0;
// func_a and func_b has to return the same type
num = if cond == true { 
    counter = counter + 1; 
    func_a(counter); 
} else { 
    func_b() 
};

katat avatar Oct 24 '24 03:10 katat

Can you label this as easy/medium/hard? Can we provide more info and ask the open source community to take a look at it?

mimoo avatar Oct 25 '24 19:10 mimoo

Sure, I added a few examples.

katat avatar Oct 28 '24 08:10 katat

to add to this, I don't think we should support expressions for now! but we should make sure that any types are supported though if that's not already the case

mimoo avatar Jan 17 '25 23:01 mimoo