Hi Lutz,
is it possible to extend newlisp so that its capable of beeing a 'filter'.
So it accepts input during startup.
example:
echo "(println \"hello newlisp\")" | newlisp -e '(eval $main-args)'
I know $main-args wont work here but its just an example.
I would like to use newlisp in the command stream of linux this way.
Hope its something you to concider?
Greetings :-)
newlisp with filter function (unix only)
newlisp with filter function (unix only)
-- (define? (Cornflakes))
Re: newlisp with filter function (unix only)
The following examplewould work like a filter:
you could also use it like this:
instead of 'upper-case' you could do anything else on the incoming lines.
See also here: http://www.newlisp.org/CodePatterns.html#toc-2 for a sub chapter "File filters"
Code: Select all
#!/usr/bin/newlisp
# demo filter script as pipe
# example:
# ./filter < my-text
(while (read-line) (println (upper-case (current-line))))
(exit)
Code: Select all
cat mytext.txt | filter | grep 'FOO BAR'
See also here: http://www.newlisp.org/CodePatterns.html#toc-2 for a sub chapter "File filters"
Re: newlisp with filter function (unix only)
Hi Lutz,
...yes yes i know :-), but my suggestion is more related to newlisp as being a command-line filter
and not such as being able to filter, its about 'not' creating a file/script when using newlisp but
about using newlisp on the command-line.
newlisp has functions that can be used on the regullar command-line in the OS, outside newlisp.
Just simple example on how it could be used:
Greetings :-)
...yes yes i know :-), but my suggestion is more related to newlisp as being a command-line filter
and not such as being able to filter, its about 'not' creating a file/script when using newlisp but
about using newlisp on the command-line.
newlisp has functions that can be used on the regullar command-line in the OS, outside newlisp.
Just simple example on how it could be used:
Code: Select all
# assuming $IN eats from STDIN on the commandline
echo 234.234 | newlisp -e '(add $IN 24.4234)'
258.6574
#or
cat myfile | newlisp -e '(explode $IN)'
#or
firstscript.lsp | newlisp -e '(net-send-udp "host.com" 1233 $IN)'
# or
Greetings :-)
-- (define? (Cornflakes))
Re: newlisp with filter function (unix only)
Same thing, use 'read-line' for STDIN:
but for multiple lines you would use '(while (read-line) (do-thing-with (current-line)))'.
Probably you are looking for automatic iterating over the input without 'while'.
Code: Select all
~> echo hello | newlisp -e '(upper-case (read-line))'
"HELLO"
~> echo 123.456 | newlisp -e '(mul 2 (float (read-line)))'
246.912
Probably you are looking for automatic iterating over the input without 'while'.
Re: newlisp with filter function (unix only)
Of all options i did not test read-line... how stupid of me ;-) Thanks..
-- (define? (Cornflakes))