【发布时间】:2014-01-13 18:15:30
【问题描述】:
此程序产生错误:
define: unbound identifier;
also, no #%app syntax transformer is bound in: define
当粘贴到 REPL 中时(准确地说,最后一行:(displayln (eval-clause clause state))),它可以工作。在定义窗口中运行时,它会失败。我不知道为什么。
#lang racket
(define *state* '((a false) (b true) (c true) (d false)))
(define *clause* '(a (not b) c))
(define (eval-clause clause state)
(for ([x state])
(eval `(define ,(first x) ,(second x))))
(eval (cons 'or (map eval clause))))
(displayln (eval-clause *clause* *state*))
这也是:
(define (eval-clause clause state)
(eval `(let ,state ,(cons 'or clause))))
生产
let: unbound identifier;
also, no #%app syntax transformer is bound in: let
这是我尝试翻译以下 Common Lisp 程序:Common Lisp 胜出?
; (C) 2013 KIM Taegyoon
; 3-SAT problem
; https://groups.google.com/forum/#!topic/lisp-korea/sVajS0LEfoA
(defvar *state* '((a nil) (b t) (c t) (d nil)))
(defvar *clause* '(a (not b) c))
(defun eval-clause (clause state)
(dolist (x state)
(set (car x) (nth 1 x)))
(some #'identity (mapcar #'eval clause)))
(print (eval-clause *clause* *state*))
在Paren:
(set *state* (quote ((a false) (b false) (c true) (d false))))
(set *clause* (quote (a (! b) c)))
(defn eval-clause (clause state)
(for i 0 (dec (length state)) 1
(set x (nth i state))
(eval (list set (nth 0 x) (nth 1 x))))
(eval (cons || clause)))
(eval-clause *clause* *state*)
【问题讨论】: