How to define a procedure that returns multiple values in R7RS

105 Views Asked by At

TL;DR: How to define a procedure foobar which can be used as (let-values ((foo bar) (foobar)) ...).


R7RS defines two procedures floor/ and truncate, which computes the quotient and remainder of two numbers divided. I find this really tricky because I can only use these procedures with let-values (or let*-values). A more important issue is that I cannot find a way to define my own procedures that returns multiple values.

Does someone have any ideas?

Note:

  • The definitions of floor/ and truncate/ are on the top of page 37 of the report.
  • I'm not lucky enough to successfully install any R7RS-compliant interpreters or compilers, so I haven't tested any of the above ideas yet. When I had the opportunity I would update this question, if needed.
1

There are 1 best solutions below

1
Martin Půda On

Did you try values? The report mentions it on page 53.

(define (foobar)
  (values 1 2))

(let-values (((foo bar) (foobar)))
  (cons foo bar))