Values and void

Started by hsmyers, July 10, 2009, 09:03:05 PM

Previous topic - Next topic

hsmyers

In CL and scheme empty version of values and void are used to indicate nothing is returned.


(define (f)
  (print 5)
  (newline)
  (void))

or


(defun f ()
  (format #t "~d~%" 5)
  (values))


Is there a newLISP equivalent? If not could there be?



--hsm
\"Censeo Toto nos in Kansa esse decisse.\"—D. Gale \"[size=117]ℑ♥λ[/size]\"—Toto

Lutz

#1
Something is always returned, but there is 'silent' function to suppress the return value being sent to the console.

hsmyers

#2
Of course. So could we have one--- pretty please?



--hsm
\"Censeo Toto nos in Kansa esse decisse.\"—D. Gale \"[size=117]ℑ♥λ[/size]\"—Toto

Lutz

#3
use this one:



http://www.newlisp.org/downloads/newlisp_manual.html#silent">http://www.newlisp.org/downloads/newlis ... tml#silent">http://www.newlisp.org/downloads/newlisp_manual.html#silent

hsmyers

#4
Ah! Bad me for not RTFM-ing!! 'silent' will do quite nicely. Thanks!



--hsm
\"Censeo Toto nos in Kansa esse decisse.\"—D. Gale \"[size=117]ℑ♥λ[/size]\"—Toto

ale870

#5
But don't forget that (silent) has a strange side-effect: it will ask to press enter key to "finalize" the output, if used in the console (I didn't check the most recent version, but older newLisp versions do that).



Try this:


> (silent (println "ok"))
ok

>


After the output test "ok" there is an empty line: it is similar a (read-line).
--

m i c h a e l

#6
I usually always end my silent expressions this way:


> (silent (println "ok?") (print ">  ")) ; notice the space after '>'
ok?
> _


silent is merely suppressing the prompt newlisp usually prints. Hitting enter on an empty line prints the prompt again (what you are experiencing). (print ">  ") at the end of a silent expression restores the normal prompt.



Or if you get tired of doing that every time, you could put this in your init.lsp file:


(set (global 'quiet) (fn ()
   (eval (cons silent (args)))
   (print "> ")
))


And use it like this:


> (quiet (println "ok"))
ok
> _


This still won't fool readline, but it does the job.



m i c h a e l

ale870

#7
wow, this is a news for me, since I didn't notice that, even if prompt is suppressed, it is ready to accept new commands! Thank you for this trick!!
--

m i c h a e l

#8
You're welcome. Glad I could be of help.



m i c h a e l