You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function Integer[] cumsum(Integer[] xs) {
acc = 0
for (ix in 1:3) {
acc = acc + xs[ix]
ys[ix] = acc
}
return ys
}
for (ix in 1:3) {
z1[ix] = rpois(1, 1)
z2[ix] = ix
z3[ix] = 0
}
print(z1)
print(z2)
print(z3)
x = [1,2,3]
acc = 0
for (ix in 1:3) {
acc = acc + x[ix]
y1[ix] = acc
}
print(y1)
y2 = cumsum(x)
print(y2)
Output looks like:
> source("rb-command.Rev")
Processing file "rb-command.Rev"
1,2,0
1,2,3
0,0,0
1,3,6
Missing Variable: Variable ys[1] does not exist
Error: Problem processing line 29 in file "rb-command.Rev"
>
This is sort of odd, because I get the same error if I save rb-command.Rev in a regular text editor and try running it with the eb executable at the cmd line. But if I run cell-by-cell in a Jupyter notebook, I get the expected output. But then if I run it line-by-line in the revbayes exectuteable, I still get the Variable ys[1] does not exist. I'm not sure what's going on here.
It looks like if you define variables in a function, then they can't be referenced outside the function. This makes code like the following not work:
While it would be ideal if such things would work, it might be OK to just document what you can and cannot expect from functions.
The text was updated successfully, but these errors were encountered: