Page 1 of 1

Returning "nothing at all" or a

Posted: Thu Aug 03, 2006 9:19 pm
by starseed
I like to play at the console.

One thing I noticed at the newLisp console, is that prints and returns frequently run into each other, e.g.

Code: Select all

> (define (test a) (print a))
(lambda (a) (print a))
> (test 5)
55
Why the hell is it printing 55??? Well, I found out quite fast, but with a little more complicated values, it may pose a problem.

Right now, I do return a nonintrusive symbol at the end of functions, which are solely meant to be used at the console:

Code: Select all

> (define (test a) (print a) '-)
(lambda (a) (print a) '-)
> (test 5)
5-
What I would like to have, would be either
- an automatic return value marker, like

Code: Select all

> (define (test a) (print a))
(lambda (a) (print a))
> (test 5)
5
== 5
- or a way to return something, that isn't printed at all, e.g.

Code: Select all

> (define (test a) (print a) '-)
(lambda (a) (print a) no-print)
> (test 5)
5
Well, I can live without it ...


Ingo

P.S.: Edited, to get the bbcode markup ...

Posted: Thu Aug 03, 2006 9:42 pm
by cormullion
I've always used println... !

Posted: Fri Aug 04, 2006 5:28 am
by HPW
What about:

(silent(test 5) )

Posted: Fri Aug 04, 2006 9:49 am
by starseed
Hi Peter,

hmm, silent should work ... it looks a little funny, maybe I need a better name ...

Code: Select all

(def (.) "Just to end interactive funcs, put it at the last place in your func"
   (silent (print "\n> ")))

(def (src "Prints the source of a lambda expression" 
      of-func "function, to get source of")
   (println (source of-func))
   (.))
So you get the next prompt, but no return value. Of course, this makes the func only usable at the console.


Ingo

Posted: Fri Aug 04, 2006 2:13 pm
by Lutz
Of course, this makes the func only usable at the console.
'silent' only silences the output, the return value would still be available to another function receiving it. 'silent' is mainly used when controlling newLISP from other programs tu suppress return value being sent back to the caller.

Lutz