BML Q&A

 

1. Iterate of java native string array in BML

Q: Oleg, first question this channel. How can I iterate of java native string array in BML. Example:

$heading = "aa,bb,cc" $attributesArray = $heading.split(",") logInfo = $attributesArray

A: absolutely the same way as over any java.lang.Iterable or java.util.Iterator:
foreach(var $item, in: $attributesArray):
log = "item = " + $item;
the default accessor (e.g absence thereof as above) will simply assign the value obtained from the iterator. For specific iterators returning composite values (e.g. time sequence iterator returns an array of two values: interval begin and interval end times) you can use some accessor which will unpack the composite value (see https://docs.google.com/document/d/1_7f2XoKHHFQBqn36Ws9BPi00OQyZ5xSbe7-p0nY2DQo/edit#heading=h.vomjsxpcogfb)

2. Loop array with active assignment

Q: Hi Oleg. I m getting the different output for the above code

$heading = "aa,bb,cc" $attributesArray = $heading.split(",") foreach(var $item, in: $attributesArray): logInfo = "item = " + $item;

output:

 

item = "attributesArray": java.lang.String[3]{ "aa", "bb", "cc" }

Expected

What should be the way to get the expected output

A: if you're using variable value rather than variable expression then you need to use active assignment (see https://docs.google.com/document/d/1_7f2XoKHHFQBqn36Ws9BPi00OQyZ5xSbe7-p0nY2DQo/edit#heading=h.5hojlrr65vkp)

so in your case in = $attributesArray rather than in: $attributesArray. The former will use $attributeArray variable value for the "in" while the latter will use variable expression definition which is an entry (this is what you see in your printout)

3. inserting a key which has . in ML

Q: Today i was facing problem inserting a key which has . in ML, The key was getting truncated upto the string which has .

is there any reason. why key is filtering the .

A: "dot" is a part of BML syntax and every string you use in naming will be split into parts by dots. (This is why you can do $x.y.z = 0 and x and y will be [nested] MLs). If you want to get around the language you can always drop to native ML API, e.g. $x.flatPut("y.z", 0). here string "y.z" will be used as an opaque key and not processed by the compiler