Racket Lang--Scheme 如何组合环境的变量和值列表

Racket Lang--Scheme How to combine a list of variables and values for an environment

我是 scheme 的新手,我正在尝试创建一个真正简单的解释器作为起点。

给定两个列表,其中一个包含以下形式的变量:

(x y z) 

第二个包含它们的值:

(1 2 3)

我怎样才能将它们组合成一个如下所示的列表:

((x 1) (y 2) (z 3))

然后我会将其附加到我的原始环境中。我正在努力适应这种编程语言的这些简单操作。谢谢

使用map.

(map list '(x y z) '(1 2 3))

我目前是一名大学生,正在使用 Dr. Racket 的 Beginning Student 环境。因此在符号和语法方面可能存在一些差异。

(define (combine-list list1 list2)
  (cond
;; Using (cond) function to create a recursion
    [(or (empty? list1) (empty? list2)) empty]
;; The base case: when to stop the recursion
;; It would be written in the first line cuz it will be evaluated first
    [else (cons (list (first list1) (first list2))
;; The recursive case: construct one typical element of the resulting list
                (combine-list (rest list1) (rest list2)))]))
;; Do the recursive case on all of the rest of the lists

我还没有了解 (map) 的作用,但在我看来,如果输入是两个参数,函数 (combine-list) 与 (map) 具有相同的行为,就像@soegaard 所做的那样在答案中。