[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Injecting names & method chaining (was Re: [ANN] Penlight Libraries, First release)
- From: Mark Hamburg <mark@...>
- Date: Fri, 1 May 2009 09:48:23 -0700
With regard to injection, it's interesting to look at Michael Franz's
paper on Protocol Extension.
ftp://ftp.inf.ethz.ch/doc/tech-reports/2xx/226.ps.gz
Essentially, he uses the module system in Oberon to avoid name
conflicts on extensions.
In the context of something like the method chaining wrapper, one
could write:
local stringx = require "stringx"
S " test " : [ stringx.trim ] () ()
(This assumes a Lua extension to support calling methods identified by
variables. The patch to support this looks reasonably simple, but I
haven't pushed hard on it.)
Or for more efficient execution, one could write:
local stringx = require "stringx"
local stringx_trim = stringx.trim
S " test " : [ stringx_trim ] () ()
Of course, this then raises the question, why not just name the method
"stringx_trim" and be done with it:
S " test " : stringx_trim() ()
One answer might be that the method chaining wrapper could handle
functions passed as indices by returning the function itself. Then
stringx.trim isn't just an identifier for the method, it can actually
be the method implementation.
Mark