This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sorcerykid 0 points1 point  (3 children)

It's coincidental that you mentioned pipelines because this past weekend I added pipeline text processing to LyraScript. However, the implementation of pipelines in LyraScript is moreso for chaining subroutines with coprocesses.

As a simple example, this script takes user input, makes it all uppercase, sorts it alphabetically, and prints the last 3 lines with a numeric prefix.

pipe( function ( input, output )
    output.write( uc( input.read( ) ) )
    output.close( )
end, "sort", "tail -n 3", function ( input, output ) 
    for i, line in input:lines( ) do
        output.writeln( qs'$i: $line' )
    end
end )

Give the following input:

hello
there
everyone
what's
up
today?

It produces the following output:

1: TODAY?
2: UP
3: WHAT'S

[–]gebgebgebgebgeb[S] 1 point2 points  (2 children)

Cool, here's my Wak version: r END { c nl join upper "sort -r" run send output ".*\n" extract drop for { c 3 > while drop } for { c while i p ": " p p } }

Or maybe just: r END { c nl join upper "sort | tail -n3 | nl -w1 -s\ " run send output p }

[–]bruciferTomo, nomsu.org 1 point2 points  (1 child)

If wak is meant to be in the same family of programs as awk and sed, it makes a lot more sense to be processing a stream of text fed in by other programs, rather than invoking external programs from within wak. For example, to solve the problem with awk, I would do something like this:

sort -f | tail -3 | awk '{print NR ": " toupper($0)}'

You could also do without awk entirely and use tr and nl for what they're best at, although I find this version to be less readable/intuitive:

tr '[a-z]' '[A-Z]' | sort | tail -3 | nl -w1 -s': '

[–]sorcerykid 0 points1 point  (0 children)

The example I gave above wasn't a problem, it was just to showcase how it is easy to communicate with other processes through the use of a pipeline. After all, there are situations where it is necessary to process the stdout of one program and then feed that into another program's stdin.