1

Often, I have main functions that run multiple functions in my common lisp apps.

(main 
  (run-function-1...)
  (run-function-2...)
  (run-function-3...)
  (run-function-4...)
  (run-function-5...))

At the moment, I have this situation where each function in main returns a varying number of values. However, the number of return values are also fixed.

I want main to return all values from all function.

(main 
  (run-function-1...) ;<--- returns 2 values
  (run-function-2...) ;<--- returns 2 values
  (run-function-3...) ;<--- returns 1 values
  (run-function-4...) ;<--- returns 3 values
  (run-function-5...)) ;<--- returns 2 values

;; main should return 10 values

When I do multiple-value-bind inside of main it doesnt capture all function returns. Because it only accepts one value-form.

2 Answers 2

4

You could use multiple-value-list + append + values-list, but I think the most straightforward is multiple-value-call:

(multiple-value-call #'values
  (run-function-1 ...) 
  (run-function-2 ...)
  (run-function-3 ...) 
  (run-function-4 ...)
  (run-function-5 ...))

If you want to return a list, replace #'values with #'list.

Sign up to request clarification or add additional context in comments.

Comments

2

You have to repack the returned values into a new values call:

(defun run-function-1 ()
  (values 1 2))
(defun run-function-2 ()
  (values 3 4 5))
(defun main () 
  (multiple-value-bind (a b) (run-function-1) 
    (multiple-value-bind (c d e) (run-function-2)
    (values a b c d e))))
(main)
1 ;
2 ;
3 ;
4 ;
5

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.