common-lispnon-standard-evaluationmultiple-value

Is it possible to test for no return value?


The output of the following function is suppressed:

(defun foo ()
  ()
  (values))

So in the REPL this happens of course:

CL-USER> (foo)
; No value

I don't get the idea how to test that a function literally returns nothing, not even NIL.

But: Is there a way to do so?

Since I am working on a Common Lisp implementation of Berkeley Logo, I would like to reproduce the behaviour of distinguishing commands which are procedures only for side-effects and operations, procedures for return values.

Maybe I am on the wrong track.

If you enter a Logo instruction such as:

add 2 3   ; or also 2+3

Logo would answer

I don't know what to do with 5.

to make you complete the instruction to

print add 2 3

for instance.

Probably I need to test whether there is a value waiting to be passed on in the chain.
But somehow I think, the behaviour of Common Lisp will get in my way somehow.

Would this indicate some sort of wrapping of the form that results from parsing a Logo string (i.e. a string that contains a Logo instruction here). I think, the listener of Logo might be called a RE-PL where the hyphen stands for this didactical interruption of the loop. Maybe this is something for the condition system? But then I arrive at the question again, what to test.


Solution

  • CL-USER 10 > (multiple-value-call (lambda (&rest args)
                                        (null args))
                   (values 1 2))
    NIL
    
    CL-USER 11 > (multiple-value-call (lambda (&rest args)
                                        (null args))
                   (values))
    T
    

    Above is the magic behind the following: MULTIPLE-VALUE-LIST returns the multiple values of its argument as a list of values.

    CL-USER 21 > (multiple-value-list (values 1 2 3))
    (1 2 3)
    CL-USER 22 > (multiple-value-list (values))
    NIL
    

    This one can then also test for being the empty list or not.