I am trying to create a function that takes two functions as arguments and executes both of them.
I tried using cond, but it only executes action1.
(define seq-action
(lambda (action1 action2)
(cond
((procedure? action1) (action1))
((procedure? action2) (action2)))))
I feel like it shouldn’t be too hard to run one after the other. They don’t need to run at the same time.
I have tried simply (action1) (action2) side-by-side, but it only returns action2. Here is what I define for action1 and action2:
(define ax
(lambda ()
(+ 1 2)))
(define bx
(lambda ()
(+ 5 2)))
Executing one procedure after the other is as simple as this:
However, the above will only return the result of the last procedure. If you need both results then return a list with the values, like this:
Alternatively, you could return multiple values simultaneously using the
valuesprocedure:For retrieving both values after calling the last version, you need to use
let-values.