Alright so basically, you'll want something like this:
List2D dim := method(x, y,
target := list
blk := call evalArgAt(2) # Get the third argument, and evaluate it in the context of the sender
if(blk isNil, blk := block setScope(call sender))
for(i, 1, y,
subTarget := list
for(j, 1, x,
subTarget append(blk call(i, j))
target append(subTarget)
)
)
target
)
Basically, what's going on here is since your filler, you want to give it arguments, the easiest method is just to pass in a Block
. You can do this with messages, but you in effect, end up setting up your own duplicate of Block
anyway if you introduce a new scope, which you should. If the third argument evaluates to nil
, then we'll just create a new function and set its scope to the calling context; as if the user had passed in an empty function, which has no argument arty and as such, you can pass arguments to it even if it doesn't define any parameters. The fact we scope it to the caller isn't really needed, but you should always scope blocks to the calling context if you're creating the blocks inside your method call. This will give access to the lexical scope of the calling context inside that block; which you're probably shoving some message the user has supplied in it. When ready, just call that method explicitly using the call
method.
If your filler
method didn't require any arguments, I'd just grab the raw message argument at the 2nd index, instead of evaluating it. This would yield some major performance improvements for some large matrices.