top | item 6033425

(no title)

ilcavero | 12 years ago

what about functions passed as arguments? quite a basic technique and I don't think it passes this test.

discuss

order

Strilanc|12 years ago

Functions passed as arguments can be traced the same way you trace values. You find all invocations of the surrounding function and see what function arguments are being passed in.

It's more involved than just grepping for the name, but the same is true of tracing where any other argument value came from.

phleet|12 years ago

functions passed as arguments are fine, because something needs to be passing them. While the function invocation site itself is dynamic, the source of the call isn't.

Basically the important aspect is that even if you have higher order functions, the things passing the functions to these higher order functions will still be greppable.

anonymoushn|12 years ago

I have unfortunately created an annoying case of this, in which a bunch of thunks are put in a list and invoked en masse. If any one of them has a problem, it's a bit of a problem to sort out where it was created. This is exasperated by the fact that functions do not know their own names in Lua.

  Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
  > function f(g) g[1]() end
  > function thisFunctionCrashes() undefinedVariable() end
  > f({thisFunctionCrashes})
  stdin:1: attempt to call global 'undefinedVariable' (a nil value)
  stack traceback:
  	stdin:1: in function '?'
  	stdin:1: in function 'f'
  	stdin:1: in main chunk
  	[C]: ?
In the example, the source line is available, but in the genuine article the thunks are for native functions.

papsosouid|12 years ago

It has nothing to do with being dynamic, it is about names. The article insists that you need to be able to grep for the identifier, but you don't have the identifier. So you have to grep for the function you are in, find all the places it is called from, and then sort through all the functions passed into it as arguments. The function passed in as an argument is often an anonymous function, so it still won't have an identifier anyways. The entire concept is just plain nonsense.