What is scheme's equivalent of tuple unpacking?

前端 未结 6 1673
说谎
说谎 2021-02-05 07:39

In Python, I can do something like this:

t = (1, 2)
a, b = t

...and a will be 1 and b will be 2. Suppose I have a list \'(1 2) in

6条回答
  •  别那么骄傲
    2021-02-05 08:05

    A bare-bones idiom is to use apply with lambda where you'd use let, like:

    (define t '(1 2))
    (apply (lambda (a b)
              ;; code that would go inside let
            )
            t)
    

    The advantage is that it works on any implementation. Of course this can only be used on simple cases, but sometimes that's all you need.

提交回复
热议问题