v icon indicating copy to clipboard operation
v copied to clipboard

multi value variable

Open kahsa opened this issue 2 years ago • 3 comments

A simple and easy way to handle multiple variables as a set of variables.

For example, use keywords such as record to allocate variables of multiple types as a single variable.

here's how to use it.

fn investigate_1(){
    mut rows := []record{
        no int
        f1 int
        f2 f64
        calc1 f64
        calc2 f64
    }
    for ....{
        rows << .....
    }
    top := rows.sort()[0].calc1
}

Currently, structures cannot be declared within functions. Since we simply want to treat multiple variables as a single variable, we do not need advanced functionality such as structs. This is a simplified version of the structure.

kahsa avatar Sep 16 '22 05:09 kahsa

It looks like sumtype

shove70 avatar Sep 19 '22 00:09 shove70

Looks like structures or union or maybe array.

fn foo(....) (int, int){
	....
}

fn main(){
	mut rows := []record{
		id  int
		sum int
	}
	for d in data{
		rows << foo(d.col1, ....)
	}
	.....

}

For example, it would be very useful to be able to add directly from multi-value like this.

ghost avatar Sep 19 '22 03:09 ghost

Oh, i see.

shove70 avatar Sep 19 '22 03:09 shove70