This is absolutely correct. There is no context at the global variables so global vars and vals cannot see each other nor can they be referenced. So if you can’t do it on one line then you have to do it in a Rule (System started Rule perhaps).
But in this case it is possible to do it all in one line.
val contacts = newArrayList(newLinkedHashMap('name'->'Cal Evans', 'address'->'cal@example.com'),
newLinkedHashMap('name'->'Bob Evans', 'address'->'bob@example.com'))
But when I see something like this it starts to have just a whiff of code smell for Rules DSL. It’s a perfectly reasonable approach in most programming languages but for Rules DSL going down this path often leads towards long, complicated, and brittle code.
I was going to suggest something similar. I wrote up a DP for it awhile back: Design Pattern: Encoding and Accessing Values in Rules
Another approach for you to consider would be to use .map files and the transform Action.
For example, you could create a single map file:
Cal = Cal Evans$cal@example.com
Bob = Bob Evans$bob@example.com
If you are careful with your naming conventions for Items (see Design Pattern: Associated Items) you can then do something like:
rule "Cal needs an email"
when
Member of CalsItems changes
then
val info = transform("MAP", "addresses.map", "Cal").split("$")
val name = info.get(0)
val email = info.get(1)
end
Obviously you don’t provide enough detail to provide a more reasonable example. The advantage to using a .map file or files is that you don’t have to edit the Rule itself to add or remove names and addresses.