schemegambit

How to use let-values in Gambit Scheme?


I'm testing if redefining of variables work in Scheme, tested this code in Gambit:

(let-values ((x (values 1 2 3))
             (x (values 4 5 6)))
  (display x)
  (newline))

To see what will be the output. But Gambit throws an error:

Unbound variable: let-values

But I've checked the source and let-values is implemented. How to use this name in Gambit. It's probably related to libraries but I don't know how to use them in Gabmit.

I've tried:

(import gambit)

But got an error:

Unbound variable: import

I'm executing gambit with gsi file.scm


Solution

  • Using gambit 4.9.5:

    > (let-values ((x (values 1 2 3))
                 (x (values 4 5 6)))
      (display x)
      (newline))
    *** ERROR IN (stdin)@5.15 -- Duplicate variable in bindings
    

    It doesn't let you re-use identifiers in the bindings; R7RS says of let-values that

    It is an error for a variable to appear more than once in the set of <formals>.

    Fix that, and it works:

    > (let-values ((x (values 1 2 3))
                 (y (values 4 5 6)))
      (display x)
      (newline))
    (1 2 3)
    

    After doing some digging through git commit history, it looks like gambit added let-values in April 2019, and the 4.9.3 you are using was released in February 2019. So using too old a version is responsible for the error you're getting about it not being defined/bound. If you'd been using a more recent instance you'd have run into the error addressed in the first part of this answer.