Multiple Assignment to environment variables

Is it possible to do Multiple Assignment to environment variables?

I can do it with vars:

(
var a, b, c;
#a, b, c = [1, 2, 3];
[a, b, c].postln;
)

And I can do it with interpreter variables:

(
#a, b, c = [1, 2, 3];
[a, b, c].postln;
)

But it doesn’t work with environment variables:

(
#~a, ~b, ~c = [1, 2, 3];
[~a, ~b, ~c].postln;
)

I even tried this (not that I would ever want to write code like this):

(
#currentEnvironment[\a], currentEnvironment[\b], currentEnvironment[\c] = [1, 2, 3];
[~a, ~b, ~c].postln;
)

(
#currentEnvironment.at(\a), currentEnvironment.at(\b), currentEnvironment.at(\c) = [1, 2, 3];
[~a, ~b, ~c].postln;
)

Is there some other way to do multiple assignment with environment variables? I looked through the docs and couldn’t find anything.

I suppose there is this, but it’s a bit ugly in my opinion:

(
var result = [1, 2, 3];
[\a, \b, \c].do{|name, index| currentEnvironment[name] = result[index]};
[~a, ~b, ~c].postln;
)

Is it possible to do Multiple Assignment to environment variables?

not really but you can…

currentEnvironment.putAll((a:1, b:2, c:3))
currentEnvironment.putPairs([a:4, b:5, c:6])
currentEnvironment.putEach([\a, \b, \c], [7, 8, 9])

perhaps the last one?
_f

#|
fredrikolofsson.com musicalfieldsforever.com

1 Like

Thank you. I was hoping there was a way to use the # operator for convenience, but I think it’s safe to say that’s not possible. Your last option is probably the closest we can get, so I’m marking it solved.