[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Short function definition syntax; thoughts on Lua
- From: steve donovan <steve.j.donovan@...>
- Date: Sun, 6 Dec 2009 17:32:10 +0200
On Sat, Dec 5, 2009 at 9:41 PM, Mark Hamburg <mark@grubmah.com> 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
syntax.
steve d.
- References:
- [ANN] GSL Shell new beta release with anti-gran graphics module, Francesco Abbate
- Re: [ANN] GSL Shell new beta release with anti-gran graphics module, David Kastrup
- Re: [ANN] GSL Shell new beta release with anti-gran graphics module, Norman Ramsey
- Short function definition syntax; thoughts on Lua (was Re: [ANN] GSL Shell new beta release...), Doug Rogers
- Re: Short function definition syntax; thoughts on Lua (was Re: [ANN] GSL Shell new beta release...), steve donovan
- Re: Short function definition syntax; thoughts on Lua (was Re: [ANN] GSL Shell new beta release...), Luiz Henrique de Figueiredo
- Re: Short function definition syntax; thoughts on Lua (was Re: [ANN] GSL Shell new beta release...), spir
- Re: Short function definition syntax; thoughts on Lua, David Kastrup
- Re: Short function definition syntax; thoughts on Lua, spir
- Re: Short function definition syntax; thoughts on Lua, Mark Hamburg