Default parameters for loops. I can't get mine to work


#1

Here’s the default list “any?” with and added parameters so I can see the index where it stopped (the body of the function is identical as the original):

((ItemClass_ item Integer idx) Boolean test) Boolean
[
!count: length
!idx: 0
!result?: false
loop
[
if idx >= count [exit]
test({idx}) [result?: true exit]
idx++
]
result?
]

I get the error:
“The trailing omitted ‘idx’ parameter does not have a default and must be supplied an argument expression.”

What am I doing wrong?


#2
((ItemClass_ item Integer idx) Boolean test) Boolean
  [
  !count: length
  !idx: 0
  !result?: false
  loop
    [
    if idx >= count [exit]
      test(at(idx) idx) [result?: true exit]
    idx++
    ]
  result?
  ] 

#3

Thanks! now that error message makes sense.


#4

Had to run so couldn’t explain much.

Also wanted to note that operators cannot use an implied this. If you want to use an operator on the current/this class then you have to explicitly use this.

So in a list you can use this{idx} but not just {idx}.

Alternatively you can use the name version of an operator and that will allow an inferred this.

So in a list you can use at(idx).