[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Iterators vs Lambdas
- From: Andrew Starks <andrew.starks@...>
- Date: Tue, 10 Sep 2013 20:36:37 -0500
On Tuesday, September 10, 2013, Javier Guerra Giraldez wrote:
On Tue, Sep 10, 2013 at 3:19 PM, Andrew Starks <email@example.com> wrote:
> I wanted to add one more thought. If you do the above version, your user may
> wish to add additional arguments. So the argument list to "find" might be:
> find( dir_str, patt, fun, ...)
that's what closures are for.
If my object is constructed as per the PiL example of a table with its index method pointing to self, and I'm using self.method_name, then I can't use a closure, because all methods defined in the template share the same metatable.
Of course, I could choose to bend/patch/hack my (pre-existing library) /(preferred way of doing things) to accommodate the lower-level API, but avoiding pain for me was why I was focusing on the "self" problem.
As you've pointed out, it is not much of an issue when you're primarily using the closure approach to objects.
Also, you could define the "lambda" such that the extra arguments come first.