Values and void

Pondering the philosophy behind the language
Locked
hsmyers
Posts: 104
Joined: Wed Feb 20, 2008 4:06 pm
Location: Boise, ID, USA
Contact:

Values and void

Post by hsmyers »

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

Code: Select all

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

Code: Select all

(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 "ℑ♥λ"—Toto

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

hsmyers
Posts: 104
Joined: Wed Feb 20, 2008 4:06 pm
Location: Boise, ID, USA
Contact:

Post by hsmyers »

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

--hsm
"Censeo Toto nos in Kansa esse decisse."—D. Gale "ℑ♥λ"—Toto

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »


hsmyers
Posts: 104
Joined: Wed Feb 20, 2008 4:06 pm
Location: Boise, ID, USA
Contact:

Post by hsmyers »

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

--hsm
"Censeo Toto nos in Kansa esse decisse."—D. Gale "ℑ♥λ"—Toto

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Post by ale870 »

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:

Code: Select all

> (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
Posts: 394
Joined: Wed Apr 26, 2006 3:37 am
Location: Oregon, USA
Contact:

Post by m i c h a e l »

I usually always end my silent expressions this way:

Code: Select all

> (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:

Code: Select all

(set (global 'quiet) (fn () 
   (eval (cons silent (args))) 
   (print "> ")
))
And use it like this:

Code: Select all

> (quiet (println "ok"))
ok
> _
This still won't fool readline, but it does the job.

m i c h a e l

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Post by ale870 »

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
Posts: 394
Joined: Wed Apr 26, 2006 3:37 am
Location: Oregon, USA
Contact:

Post by m i c h a e l »

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

m i c h a e l

Locked