fork download
  1. ; Run: clisp multi-return-value.cl
  2. ; This is to test the multi return pattern.
  3. ; It's very convenient for program upgrade.
  4.  
  5. ; Test the multi-return of built-in 'floor' function
  6. (format t "~a~%" (multiple-value-bind (f r)
  7. (floor 130 11)
  8. (list f r)))
  9. (format t "~a~%" (floor 130 11))
  10.  
  11. ; ==== Following is a test to show the power of multi-return ===
  12.  
  13. ; Your original function and how it is called by client
  14. (defun myfunc (a)
  15. "a test function"
  16. a)
  17. (format t "~a~%" (+ (myfunc 1) (myfunc 2)))
  18.  
  19. ; Now we upgrade the function
  20. (defun myfunc2 (a)
  21. "This is the upgrade of 'a test function'"
  22. (values-list (list a (* a 2))))
  23. ; The original call is not influenced
  24. (format t "~a~%" (+ (myfunc2 1) (myfunc2 2)))
  25. ; You can utilize multiple return values
  26. (format t "~a~%"
  27. (multiple-value-bind (v1 v2)
  28. (myfunc2 2)
  29. (* v1 v2)))
  30.  
Success #stdin #stdout 0.02s 10592KB
stdin
Standard input is empty
stdout
(11 9)
11
3
3
8