开发者

What does this xkcd code do?

On the xkcd site today, the following appeared as a joke in a <script language="scheme"> tag

so what does the following code do / represent?

(define
  (eval exp env)
  (cond ((self-evaluating? exp) exp)
    ((variable? exp)
      (lookup-variable-value exp env))
    ((quoted? exp)
      (text-of-quotation exp))
    ((assignment? exp)
      (eval-assignment exp env))
    ((definition? exp)
      (eval-definition exp env))
    ((if? exp)
      (eval-if exp env))
    ((lambda? exp)
      (make-procedure
        (lambda-parameters exp)
        (lambda-body exp)  env))
    ((begin? exp)
      (eval-seq开发者_如何学Gouence (begin-actions exp) env))
    ((cond? exp)
      (eval (cond->if exp) env))
    ((application? exp)
      (apply (eval (operator exp) env)
        (list-of-values (operands exp) env)))
    (else  (error "Common Lisp or Netscape Navigator 4.0+ Required" exp))))


It's essentially a simple interpreter, if you assume that all the requisite methods are filled in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜