方忘河吧 关注:37贴子:658
little lisp & SCIP


1楼2016-01-20 02:44回复
    (cdr a)错,不可对atom。(cdr (a))=nil


    3楼2016-02-01 09:05
    回复
      cdr, car只处理非空list


      4楼2016-02-01 09:10
      收起回复
        cons将原子加到list的前头;将任何S表达式整个加到list前头


        5楼2016-02-01 09:12
        回复
          (cons a (b))=(a b)
          错(cons (a) b)


          6楼2016-02-01 09:14
          回复
            (null? ())=true用来判断list是否为空(是否含有S表达式),不可用于原子


            7楼2016-02-01 10:08
            收起回复
              #lang racket
              (define (atom? x)
              (and (not (null? x))
              (not (pair? x))))
              (define lat?
              (lambda (l)
              (cond
              ((null? l) #t )
              ((atom? ( car l)) (lat? (cdr l)))
              (else #f ) ) ) )


              8楼2016-02-04 12:17
              回复
                #lang racket
                ;whether atom a is a member of list lat
                (define member?
                (lambda (a lat)
                (cond ((null? lat) #f)
                (else (or (eq? (car lat) a)
                (member? a (cdr lat)))))))


                10楼2016-02-04 13:18
                回复
                  else is a question whose value is always true


                  11楼2016-02-04 13:39
                  回复
                    过程定义 (define (square x) (* x x))
                    其中x为参数
                    (define (sum-of-square x y) (+ (square x) (square y)))


                    12楼2016-02-04 14:09
                    回复
                      代换模型,将实值一层层地向上代换掉形参,人类的做法,无法被数学严格定义,因为用作过程中形参的名字会与表达式中的名字混淆。但是解释器不是如此。正则序求值:完全展开而后归约;目前LISP用应用序求值,先求值参数而后应用,避免对表达式重复求值。


                      13楼2016-02-04 14:27
                      回复
                        #lang racket
                        ( define (abs x)
                        (cond ((> x 0) x)
                        ((< x 0) (- x))
                        ((= x 0) 0))
                        )
                        (define (>= x y)
                        (or (> x y) (= x y))
                        )


                        14楼2016-02-04 14:35
                        回复
                          (define (>= x y)
                          (not (< x y) )
                          )


                          15楼2016-02-04 14:36
                          回复
                            输入三个数,输出最大两数之和
                            #lang racket
                            (define (sum-of-max x y z)
                            (if(> x y)
                            (if(> y z) (+ x y) (+ x z))
                            (if(> x z) (+ x y) (+ y z))
                            )
                            )


                            16楼2016-02-04 14:56
                            回复
                              牛顿法计算立方根
                              #lang racket
                              ;cube root
                              (define (cube-root x)
                              (cube-iter 1.0 x)
                              )
                              (define (cube-iter guess x)
                              (if (good-enough? guess x)
                              guess
                              (cube-iter (improve guess x) x)
                              )
                              )
                              (define (improve guess x)
                              (get-result guess x)
                              )
                              (define (get-result x y)
                              (/ (+ (/ y (* x x)) (* 2 x)) 3)
                              )
                              (define (good-enough? guess x)
                              (< (abs (- (* guess guess guess) x)) 0.0001)
                              )


                              17楼2016-02-08 10:04
                              回复