Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can a variable have multiple values

In algebra if I make the statement x + y = 3, the variables I used will hold the values either 2 and 1 or 1 and 2. I know that assignment in programming is not the same thing, but I got to wondering. If I wanted to represent the value of, say, a quantumly weird particle, I would want my variable to have two values at the same time and to have it resolve into one or the other later. Or maybe I'm just dreaming?

Is it possible to say something like i = 3 or 2;?

like image 496
Ziggy Avatar asked Sep 20 '26 10:09

Ziggy


1 Answers

This is one of the features planned for Perl 6 (junctions), with syntax that should look like my $a = 1|2|3;

If ever implemented, it would work intuitively, like $a==1 being true at the same time as $a==2. Also, for example, $a+1 would give you a value of 2|3|4.

This feature is actually available in Perl5 as well through Perl6::Junction and Quantum::Superpositions modules, but without the syntax sugar (through 'functions' all and any).

At least for comparison (b < any(1,2,3)) it was also available in Microsoft Cω experimental language, however it was not documented anywhere (I just tried it when I was looking at Cω and it just worked).

like image 54
Andrey Shchekin Avatar answered Sep 23 '26 13:09

Andrey Shchekin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!