Plural constants are great! Now I want plural variables.

zarqon

Well-known member
Ehhh???

> ash boolean[skill] dontcast = $skills[confrontation, sneakiness, annoyance, donho, inigo]; dontcast[$skill[celerity]] = true;

Cannot modify constant value (zlib.ash)
Returned: void

Does this mean I can't use plural constants as a quick way to populate a list if I want to add to the list later? If yes, is there a different, also quick way?
 

xKiv

Active member
Plural values are immutable (which goes hand in hand with their elements staying in the same order they were defined).

You probably want some variant of cloning. Something that would, in effect, do
PHP:
foreach sk in $skills[confrontation, sneakiness, annoyance, donho, inigo] {
  dontcast[sk] = true;
}
but more generic.
N.b.: this is different from normal cloning, because it changes type of the value (and type of the underlying java representation).
 

zarqon

Well-known member
I had been under the impression that the plural constant was essentially cast as a map when assigning it to a variable declared as a boolean[skill] map. Is there a way to trick mafia into doing this? Perhaps assigning an arbitrary value to the map before assigning it the plural constant?
 

xKiv

Active member
It is cast in the java sense of the word - you can access it through the interface. But the underlying object still has any modification disbled and forbidden.

Perhaps assigning an arbitrary value to the map before assigning it the plural constant?
Don't tell me you expected that to work.
Variables are not values. Variables are names for "cells" that hold values. Assigning value to a variable changes that "cell". You can't access the old value through that variable any more.

(where "cell" can be a memory location, or an abstract wrapper around an immutable simple value (like 1 or true))

The only thing you can do right now is the foreach. You might consider posting a feature request for a new cloning operator or something.

Example of what I envision:
PHP:
ash boolean[skill] dontcast;

dontcast = $skills[confrontation, sneakiness, annoyance, donho, inigo];
// now dontcast just points to the constant value
// dontcast[$skill[celerity]] = true; // would be an error at this point

// cloning operator:
dontcast :- $skills[confrontation, sneakiness, annoyance, donho, inigo];
// essentially duplicates the foreach thing
dontcast[$skill[celerity]] = true; // OK now, dontcast contains a proper map

// or something:
dontcast = $skills[confrontation, sneakiness, annoyance, donho, inigo].mutableClone();
// similar, but defined only on plural constants
dontcast[$skill[celerity]] = true; // OK now, dontcast contains a proper map
 
Top