JAGS choosing a random subset of a vector I would like to allow the subset of a vector I am summing over to be a random quantity. 
My model is of the form (albeit more complex):
model {
    for (i in 1:N)
    {
      y[i] ~ dpois(a*sum(aVec[1:b]))
    }
    for (j in 1:10)
    {
        punif[j] <- 1/10
    }
    b ~ dcat(punif[])
    a ~ dlnorm(0,10)
}

The above throws the following error when I use jags.model:
RUNTIME ERROR:
Unable to resolve relations

This does not occur if the vector $aVec$ is subsetted deterministically using: 
b <- 10

for example.
The quantity with which I am most interested is the random quantity $b$, which I think I have assigned a discrete uniform prior from 1 to 10.
EDIT: I have also tried the following:
model {
for (i in 1:NTotal)
{
  A[i] <- ifelse(i < b, 1, 0)
}
for (i in 1:NTotal)
{
  y[i] ~ dpois(a*inprod(aVec[],A[]))
}

for (j in 1:10)
{
  punif[j] <- 1/10
}
  b ~ dcat(punif[])
  a ~ dlnorm(0,10)
}

Although, this suffers the same issue. If $b$ is random it doesn't work. Whereas if $b$ is a logical node, it does. Similarly, if I do the sum via a loop, and make the upper index a random variable, I get another error:
Cannot evaluate upper index of counter j 

Does anyone know how I can get the above to work?
Best,
Ben
 A: I have come up with an answer to this, via the use of a the $step$ function. As the answer to this question discussion rightly indicates (JAGS, cannot evaluate upper index of counter), for loops in JAGS are not the same as in a procedural langugage; they are merely declarative. 
Thus, it is not possible to run a loop in JAGS where the index of the loop is a random variable.
However, I suspect that all of these cases can be rewritten using the $step$ function. To answer my question above, this involves a solution of the form:
model {
for (i in 1:NTotal)
{
    for (j in 1:10)
    {
      A[i,j] <- step(j - b)
    }
 captureNumber[i] ~ dpois(a*sum(A[i,]))
}

for (j in 1:10)
{
    punif[j] <- 1/10
}
b ~ dcat(punif[])
a ~ dlnorm(0,10)
}

Hope this helps someone else! Have been racking my brain for the past two days to fix this.
Best,
Ben
A: Have you try adding to the model a random vector A with 0s and 1s, and then do something like 
y[i] ~ dpois(sum( inprod(A[],aVec[]) ))

this way, only the aVec values with indexes where A is 1 will be summed
