如影随形 魔法禁忌

(define numbered?
  (lambda (aexp)
    (cond
      ((atom? aexp)(number? aexp))
      ((eq?(car(cdr aexp))(quote +))
       (and(numbered?(car aexp))
           (numbered?
            (car(cdr(cdr aexp))))))
      ((eq?(car(cdr aexp))(quote *))
       (and(numbered?(car aexp))
           (numbered?
            (car(cdr(cdr aexp))))))
      ((eq?(car(cdr aexp))(quote →))
       (and(numbered?(car aexp))
           (and(numbered?(car aexp))
               (numbered?
                (car(cdr(cdr aexp))))))))))

;由于aexp已经被看作一个表达式,简化numbered?
(define numbered1?
  (lambda(aexp)
    (cond
      ((atom? aexp)(numbered1? aexp))
      (else
         (and(numbered1?(car aexp))
             (numbered1?
              (car(cdr(cdr aexp)))))))))

(define value
  (lambda(nexp)
    (cond
      ((atom? nexp)nexp)
      ((eq?(car(cdr nexp))(quote +))
       (+ (value(car nexp))
          (value(car(cdr(cdr nexp))))))
      ((eq?(car(cdr nexp))(quote *))
       (* (value(car nexp))
          (value(car(cdr(cdr nexp))))))
      (else
       ((value(car nexp))
          (value
           (car(cdr(cdr nexp)))))))))

;一个算术表达式的表示方式的第一个子表达式
(define 1st-sub-exp
  (lambda(aexp)
    (car(cdr aexp))))

(define 2nd-sub-exp
  (lambda(aexp)
    (car(cdr(cdr aexp)))))

(define operator
  (lambda(aexp)
    (car aexp)))
;重写value
(define value1
  (lambda(nexp)
    (cond
      ((atom? nexp)nexp)
      ((eq?(operator nexp)(quote +))
       (+(value1(1st-sub-exp nexp))
         (value1(2nd-sub-exp nexp))))
      ((eq?(operator nexp)(quote *))
       (*(value1(1st-sub-exp nexp))
         (value1(2nd-sub-exp nexp))))
      (else
       ((value1(1st-sub-exp nexp))
         (value1(2nd-sub-exp nexp)))))))

;一种新的数字表示法()表示零,(())表示1(()())表示2,(()()())表示3
(define sero?
  (lambda(n)
    (null? n)))

(define edd1
  (lambda(n)
    (cons(quote())n)))

(define zub1
  (lambda(n)
    (cdr n)))

(define +
  (lambda(n m)
    (cond
      ((sero? m)n)
      (else(edd1(+ n(zub1 m)))))))
      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值