chan = Channel(Tuple(String, String)).new
a = spawn(name: "spawn1") do
sleep rand(10)
chan.send({"spawn1", "a"})
end
b = spawn(name: "spawn1") do
sleep rand(10)
chan.send({"spawn2", "b"})
end
2.times do
select
when a, b = chan.receive
pp! a, b
end
end
Get following error:
In 1.cr:15:8
15 | when a, b = chan.receive
^
Error: invalid select when expression: must be an assignment or call
Multiple conditions separated by commas can share a when clause in a case expression. I think it would be quite confusing if the same when could turn the conditions into one multiple assignment when the parser encounters = ... at the end
I think it looks a bit weird to have a multi assign in a condition of a control structure. if a, b = c doesn’t work either.
Arguably, select is a bit special and conditions actually work quite differently from those of if and case. So maybe it’s okay.
I wouldn’t object to adding it, but I’m not quite convinced about it.
syntax error, unexpected ',', expecting `then' or ';' or '\n'
> 1 if a, b = [100, 200]
> 3 end
1.rb:1: syntax error, unexpected ',', expecting `then' or ';' or '\n' (SyntaxError)
if a, b = [100, 200]
I consider this not so useful, because don’t know use which one (a or b?) to as if condition.