lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Sat, Dec 5, 2009 at 9:41 PM, Mark Hamburg <> wrote:
> The argument for not just using : syntax for pipes is that that requires that the method being sent be supported on the left-hand object and I therefore can't encapsulate a series of pipe operations in another function. For example, using the above, I could define:

If something is not a method of the sequence object, then you can try
apply the method to the elements of the list, if it is a method of the
first element of the sequence:

    strings:sub(1,72)  <==> strings:map(function(s) return s:sub(1,72) end)

This trick can be extended further, so that this method lookup on the
first element could then look at enclosing context, e.g.
strings:tonumber() would transform a list of strings into a list of
numbers using the global tonumber.   But, as always, beware of
anything that might be a little difficult to explain ;)

>like there might be an opportunity for intelligent pipe building and application.

Pipes are an excellent way to _declare_ what the flow of data should
be. Naturally fits in well with a coroutine model.

>        $ + 1 would be defined as function( x ) return x + 1 end

Penlight does have placeholder expressions of the form _1 + 1, in
imitation of the Boost C++ libraries.

> One could almost build this as is, but for the lack of metatable support for certain operators such as and and or.

That's the rub, alas.  One ends up with things like Or(_1,_2) etc. But
still, it's amazing what we can do with stock Lua without extra

steve d.