Using local # variables inside for loops?

I have a global variable ‘v’ which is just a simple JSON formatted string holding some numbered keys and their values.

I would like to take this local variable and make modifications to it using the tc(reg) function inside a formula bit by bit - all easily done.

If I refer to the modified local variable inside an if() function using # notation it works fine, but not inside a for loop.

Perhaps there is something I’m trying to do which is illegal but I haven’t made sense of it yet. Is it a known issue?

The output from my current formula is below together with the formula that generates it.

{1:2,2:4,3:6,4:8,5:10,6:12}  (Original)
{1:2,2:5,3:2,4:9,5:10,6:12}  (Altered)
2,4,6,8,10,12
,,,,,
yes


$gv(v)$ (Original)
$lv(v, tc(reg, gv(v), "3:(\d{1,2})", "3:2"))
+ lv(v, tc(reg, #v, "4:(\d{1,2})", "4:9") )
+ lv(v, tc(reg, #v, "2:(\d{1,2})", "2:5") )
+ #v$ (Altered)
$fl(1, 6, "i+1", "tc(json, gv(v), i)", ",")$
$fl(1, 6, "i+1", "tc(json, #v, i )", ",")$
$if(tc(json, #v, 2)=5, "yes", "no")$

As you can see, using the normal gv(v) inside the for loop just calls the original as it is likely evaluated first, but using the #v shortcut renders blanks with five comma separators.

Using the #v notation inside an if() function to test for the modified value renders success.

yeah I reported this bug 2 years ago but it was never fixed.

A workaround would be to concatenate the JSON into the formula body string you’re passing to fl(). tc(utf, 22) returns a doublequote ".

$fl(1, 6, "i+1", "tc(json, " + tc(utf, 22) + #v + tc(utf, 22) + ", i)", ",")$

You can also use a placeholder and replace it with a doublequote like this:

$fl(1, 6, "i+1", tc(reg, "tc(json, '" + #v + "', i)", ', tc(utf, 22)), ",")$

Hi, glad to know it’s not just me. I did search to see if it had been reported before but rather annoyingly didn’t find your post. Good to know there is a solution in the interim but it would have been great to have it addressed before now. Thanks for your help. Much appreciated.

Hi there,

I think the $fl()$ function does not support local variable.

I tried several tricks but that function doesn’t read the value of the local variable.

I hope this would help.
:smiling_face::+1: