in reply to Re: Pass an "extra' variable to Find::File subroutine
in thread Pass an "extra' variable to Find::File subroutine

I can just guess, but that's how you pass data to callbacks in languages like C, which don't have closures.
  • Comment on Re^2: Pass an "extra' variable to Find::File subroutine

Replies are listed 'Best First'.
Re^3: Pass an "extra' variable to Find::File subroutine
by ikegami (Patriarch) on Jun 22, 2010 at 15:42 UTC
    You'd design the C library differently.
      Would I?

      It's a common pattern in C libraries to pass a void pointer to callbacks, and allow the caller of the library to hand in a pointer which is then passed on to the callback.

      And that's a rather sane design in a language without closures, because otherwise the the callback can't obtain additional information about the caller (except for globals, which makes rekursive calls dangerous to impossible).

      Other popular design decision include a hidden, global state variable (same problem with reentrancy), or omitting callbacks altogether (might work for a directory traversal library like File::Find, but would be exceptionally painful for a GUI toolkit).

        Would I?

        You ask this, then proceed to explain exactly what you'd change: The addition of a parameter that takes a pointer to pass to the callback. You answered your own question.