newlisp --quite

Started by hds1, February 15, 2015, 12:29:27 PM

Previous topic - Next topic

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

Lutz

#1
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



~> echo '(silent (println "willi"))' | newlisp
willi
~>

hds1

#2
thanks for the hint with (silent).

But you need to wrap your whole proggi into it.

(silent
  (long prog to follow))

Hm, it doesn't feel right to me.



Consider other scripting languages:

echo 'print "lauran";' | perl

echo 'print "lauran";' | ruby

echo 'print "lauran";' | 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

Lutz

#3
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:



newlisp prog | otherprog

or with "#!/usr/bin/newlisp" in the first line of the script:

#!usr/bin/newlisp

(define (foo x)
    (+ x x))

(println "(foo 123 ->)" (foo 123))
(exit)

... you can do in the shell:

~> prog
(foo 123) -> 246
~>

prog must have executable permissions and in the executable path and you only see print action, no return values.



BTW, you also can do:



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:

~> 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/newlisp_manual.html#REPL">http://www.newlisp.org/downloads/newlis ... .html#REPL">http://www.newlisp.org/downloads/newlisp_manual.html#REPL

http://www.newlisp.org/downloads/newlisp_manual.html#options">http://www.newlisp.org/downloads/newlis ... ml#options">http://www.newlisp.org/downloads/newlisp_manual.html#options

http://www.newlisp.org/downloads/CodePatterns.html#toc-2">http://www.newlisp.org/downloads/CodePa ... html#toc-2">http://www.newlisp.org/downloads/CodePatterns.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.