What is scheme's equivalent of tuple unpacking?

前端 未结 6 1697
说谎
说谎 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:08

    This works in Racket if you don't want to bring in the match dependency:

    From a list:

    (let-values ([(a b c) (apply values '(1 2 3))])
      (+ a b c))
    

    Or directly from a values expression:

    (let-values ([(a b c) (values 1 2 3)])
      (+ a b c))
    

提交回复
热议问题