; Multiple-valued-procedures ; - allows a procedure to return more than one value, even if they are not in a list ; - use the command VALUES as follows (values 1 2 3 4) ; as you would expect, the returns ; 1 ; 2 ; 3 ; 4 ; my recommendation if you want to return multiple values, use a a helper procedure ; which passes around these values and then return them at the end using VALUES ; if instead you want to write a recursive procedure that calls itself with multiple ; values, then you need the command CALL-WITH-VALUES, which has an ; "interesting" syntax: (call-with-values CREATOR PROC) ; this command will call: (PROC (CREATOR)) ; so CREATOR called with no arguments should produce the values (with ; VALUES command) that are sent to PROC ; example, adding 1 + 2 (call-with-values (lambda () (values 1 2)) +) ; note that CREATOR is of the form (lambda () ....) ; while I have not yet seen a case where CALL-WITH-VALUES makes things ; simpler, let's do an example so you can decide for yourself ; minmax, takes in a list of numbers and returns the min and the max (define minmax (lambda (ls) (if (null? (cdr ls)) (values (car ls) (car ls)) (call-with-values (lambda () (minmax (cdr ls))) ; CREATOR which return values (lambda (min max) ; PROC which takes in the values (cond ((< (car ls) min) (values (car ls) max)) ((> (car ls) max) (values min (car ls))) (else (values min max)))))))) ; minmax written with a kernel procedure, and without call-with-values ; this way is tail-recursive (define minmax2 (lambda (ls) ; we call the kernel letting the (car ls) be the initial min and max (let kernel ((min (car ls)) (max (car ls)) (lsk (cdr ls))) (cond ; if we are out of elements then return min and max ((null? lsk) (values min max)) ; otherwise update min and max with the (car ls) ((< (car lsk) min) (kernel (car lsk) max (cdr lsk))) ((> (car lsk) max) (kernel min (car lsk) (cdr lsk))) (else (kernel min max (cdr lsk)))))))