I was feeling adventurous and in my haste to look into legato.cal I double clicked on it instead of opening it with notepad. This popped up :
Which had me fearful of CAL being dropped from Sonar. But then I tried it within Sonar and it appears to work proplerly, though I didn't study the result of the operation.
The script is very short. If you can understand that "(= x y)" really means "x = y" [or "assign y to x"] and
"if (== x y)" means "if (x == y)" [or "if x happens to be the same as y"] then you can probably figure out the rest pretty easily. The nested parentheses are just to define the scope of each operation.
Which reminds me of when I used to program functions in emacs to make my life easier, 30+ years ago.
PS. CAL scripts are invoke by selecting "Process / Run CAL..." from Sonar's main menu.