Page 1 of 1
newlisp --quite
Posted: Sun Feb 15, 2015 8:29 pm
by hds1
Hello,
is it possible to turn off the standard return output of newlisp ?
i.e: echo "(print 'willi')" | newlisp
willinil
nil
Here the "nil" value.
So my feature request would be something like:
echo "(println 'willi')" | newlisp -q
--> willi
Kubuntu 14.04, kernel 3.13.0-45-generic, newLISP v.10.6.2 64-bit on Linux IPv4/6 UTF-8 libffi
Regards
Heiko
Re: newlisp --quite
Posted: Sun Feb 15, 2015 8:44 pm
by Lutz
Note, that newLISP does
not use single quotes as string delimiters.
To suppress the return value of an expression in the console, use
silent. Now you only see the side effect, printing the string "will" and a line feed, because
println was used instead of
print
Code: Select all
~> echo '(silent (println "willi"))' | newlisp
willi
~>
Re: newlisp --quite
Posted: Mon Feb 16, 2015 8:39 am
by hds1
thanks for the hint with (silent).
But you need to wrap your whole proggi into it.
Hm, it doesn't feel right to me.
Consider other scripting languages:
echo 'print "laura\n";' | perl
echo 'print "laura\n";' | ruby
echo 'print "laura\n";' | python (adds an extra \n because of default print)
No extra return value on the console.
echo '(println "laura")' | newlisp
laura -> printed
"laura" -> return value
Is there a special reason i miss (or don't understand) that NL needs to return a value to the console ?
Thanks and Regards
Heiko
Re: newlisp --quite
Posted: Mon Feb 16, 2015 3:22 pm
by Lutz
In a functional language like Lisp,
everything has a return value - consumed by an enclosing expression. There are no functions with only side effects, like in other programming languages. Often it is important to distinguish between the side effect and the return value of a function. You also wouldn’t have a longer
prog in an
echo statement. With a longer
prog you would do:
or with “#!/usr/bin/newlisp” in the first line of the script:
Code: Select all
#!usr/bin/newlisp
(define (foo x)
(+ x x))
(println "(foo 123 ->)" (foo 123))
(exit)
... you can do in the shell:
prog must have executable permissions and in the executable path and you only see
print action, no return values.
BTW, you also can do:
Code: Select all
echo '(silent) (println "hello")' | newlisp
the first expression after silent would than be silent. You don’t have to enclose the whole expression.
But in a one-liner you probably wouldn’t use
print at all but just work with the return value:
Code: Select all
~> echo '(+ 3 4)' | newlisp
7
~> newlisp -e '(+ 3 4)'
7
A few links about the REPL (heavily relying on return values) and shell scripting:
http://www.newlisp.org/downloads/newlis ... .html#REPL
http://www.newlisp.org/downloads/newlis ... ml#options
http://www.newlisp.org/downloads/CodePa ... html#toc-2
the last link shows you how to consume output from another program in newLISP when newLISP is at the receiving end of a pipe.