Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Functional programming 使用关联列表的方案中的函数表_Functional Programming_Lisp_Scheme_Interpreter - Fatal编程技术网

Functional programming 使用关联列表的方案中的函数表

Functional programming 使用关联列表的方案中的函数表,functional-programming,lisp,scheme,interpreter,Functional Programming,Lisp,Scheme,Interpreter,我试图在Scheme中构建一个基本的解释器,我想使用关联列表映射到算术函数。这就是我到目前为止所做的: ; A data type defining an abstract binary operation (define binoptable '(("+" . (+ x y))) ("-" . (- x y)) ("*" . (* x y)) ("/" . (/ x y))) ) 问题是表的右侧的元素存储为符号列表。有没有人对如何补救他的错误有什么想法。提前感谢。

我试图在Scheme中构建一个基本的解释器,我想使用关联列表映射到算术函数。这就是我到目前为止所做的:

; A data type defining an abstract binary operation
(define binoptable
  '(("+" . (+ x y)))
    ("-" . (- x y))
    ("*" . (* x y))
    ("/" . (/ x y)))
)
问题是表的右侧的元素存储为符号列表。有没有人对如何补救他的错误有什么想法。提前感谢。

您可能需要:

(define binoptable
  `(("+" . ,+)
    ("-" . ,-)
    ("*" . ,*)
    ("/" . ,/)))
此外,还可以使用宏来更容易地指定:

(define-syntax make-binops
  (syntax-rules ()
    [(make-binops op ...)
     (list (cons (symbol->string 'op) op) ...)]))
(define binoptable (make-binops + - * /))