newLISP Fan Club

Forum => newLISP in the real world => Topic started by: pjot on April 05, 2008, 02:35:10 AM

Title: Howto embed newlisp in (shell) programs part 2
Post by: pjot on April 05, 2008, 02:35:10 AM
Hi,



Pending the issue of the previous post (//http), I tried to solve it in a different way.



Similar to other core Unix programs, I tried to use a pipe to the STDIN of newLisp, but it fails. Below taken from the command prompt:
Quote
peter[~]$ echo "help" | awk '{print}'

help

peter[~]$ echo "help" | sed {}

help

peter[~]$ echo "help" | cut -f1

help

peter[~]$ echo "help" | newlisp -e "(println)"



nil


So how can I accept stdin to the newLisp binary and perform a task with it?



If newLisp wants to integrate in a Unix environment then it would be great if this works!



Thanks
Title:
Post by: Lutz on April 05, 2008, 02:40:25 AM
not necessary, see my answer to your previous post, we posted at the same time.
Title:
Post by: Lutz on April 05, 2008, 02:44:48 AM
and here is the solution to your pipe problem:


~> echo "help" | newlisp -e "(read-line)"
"help"
~>
Title:
Post by: pjot on April 05, 2008, 02:45:53 AM
Hi Lutz,



Indeed, the solution works fine!



However, just for arguments sake, how would you think about implementing a STDIN for newLisp? It would help a lot in different (Unix) situations if this is possible.



Just curious on your ideas about this.



Thanks

Peter
Title:
Post by: pjot on April 05, 2008, 02:46:29 AM
You're fast! It always worked, thanks a lot!



Complete list now:


Quote
peter[~]$ echo "help" | awk '{print}'

help

peter[~]$ echo "help" | sed {}

help

peter[~]$ echo "help" | cut -f1

help

peter[~]$ echo "help" | newlisp -e "(read-line)"

"help"


Peter
Title:
Post by: Lutz on April 05, 2008, 02:54:35 AM
In this chapter: http://www.newlisp.org/CodePatterns.html#scripts you find the basic pattern of a UNIX filter written in newLISP:


~> echo "hello world" | ./filter
HELLO WORLD

~> cat filter
#!/usr/bin/newlisp

(while (read-line) (println (upper-case (current-line))))

(exit)

~>


'current-line' always contains the last result from 'read-line'. This pattern has been well tested in a UNIX environment. It also works with inetd for setting up servers.



ps: I am on your timezone ;-)
Title:
Post by: pjot on April 05, 2008, 07:04:48 AM
Aha! I was already wondering why you were responding so fast ;-)



Maybe time for another European Newlisp Conference? ;-)
Title:
Post by: Lutz on April 05, 2008, 08:00:47 AM
QuoteMaybe time for another European Newlisp Conference? ;-)


Sure!