[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pipeing fucntions
- From: meino.cramer@...
- Date: Mon, 25 Jun 2012 19:46:54 +0200
Coda Highland <chighland@gmail.com> [12-06-25 19:44]:
> On Mon, Jun 25, 2012 at 12:34 PM, <meino.cramer@gmx.de> wrote:
> > Hi,
> >
> > (Warning! Newbie ahead!)
> >
> > With UNIX systems you can build chains of cammands
> > on the commandline eacht connected via stdout/stdin.
> >
> > Is it possible to chain lua-functions in a similiar way, that is:
> > To create an output stream with one function which gets the
> > input stream of another function?
> >
> > Is taht possible (portable...)?
> >
> > Thank you very much in advance for any help!
> > Best regards,
> > mcc
> >
>
> Why wouldn't it be?
>
> function a(x)
> return x .. "a"
> end
>
> function b(x)
> return x .. "b"
> end
>
> print(b(a("t")) -- "tab"
>
> Or if you like it better:
>
> local l = { a, b }
> local value = "t"
> for _, fn in pairs(l) do
> value = fn(value)
> end
> print(value) -- "tab"
>
> /s/ Adam
>
This is sequencing, not pipeing...
Pipeing means: Function a produces a _stream_ of data
/while/ function b consumes that stream.
Is it possible (portable...) ?
Best regards,
mcc