<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] ## 由n個 hello構成的表 下面設計函數 hellos,該函數以自然數n為參數,輸出為由n個 hello構成的表,該函數的合約為: ``` ;由n個 hello構成的表 ;hellos:n->list-of-symbols ;預期值 ;(hellos 0) ;empty ;(hellos 1) ;(cons 'hello empty) ->(cons 'hello (hellos 0)) ;可以看出帶有遞歸性 ; (hellos 2) ; (cons 'hello (cons 'hello empty)) -> (cons 'hello (hellos 1)) (define (hellos n) (cond [(= n 0) empty] [else (cons 'hello (hellos (- n 1)))])) (hellos 2) ;(list 'hello 'hello) ``` ## 11.2.1 把 hellos一般化為 repeat,該函數讀入自然數n和一個符號,返回包含n個符號的表。 ``` (define (repeat sym n) (cond [(= n 0) empty] [else (cons sym (repeat sym (- n 1)))])) (repeat 'hello 3) ; (list 'hello 'hello 'hello) ``` ## 11.2.2 設計函數 tabulate-f,把函數f應用于一些由自然數值組成的表,其中f是 ``` ;; f:number->number (define (f x) (+ (* 3 (* x x)) (+ (* -6 x)) -1)) ``` 具體地說,函數讀入自然數n,返回由n個posn結構體組成的表,表的第一個元素是點`n (f n)`,第二個元素是點`(n-1 (f n-1))`,以此類推。 解答 ``` ;(f 0) ;-1 ;(f 1) ;-4 (define (f x) (+ (* 3 (* x x)) (+ (* -6 x)) -1)) ;tabulate-f: n-> (cons (n fn) (cons (n-1 (f n-1)))) ;0 -> empty ;1 -> (cons (1 (f 1) empty)) -> (cons (1 (f 1) (tabulate-f 0))) ;2 -> (cons (2 (f 2) (cons (1 (f 1)) empty))) ->(cons (2 (f 2) (tabulate-f 1) )) (define (tabulate-f n) (cond [(= n 0) empty] [(= n 1) (cons (make-posn 1 (f 1)) empty)] [else (cons (make-posn n (f n)) (tabulate-f (- n 1)))])) ;(tabulate-f 0) ;'() ;(tabulate-f 1) ;(list (make-posn 1 -4)) (tabulate-f 2) ;(list (make-posn 2 -1) (make-posn 1 -4)) ``` ## 11.4.3 設計 product-from-minus-11這個函數讀入一個大于或等于-11的整數n,返回在-11(不包括)和n(包括)之間所有數的乘積。 解答 ``` ;product-from-minus-11:number->number ; -11 -> 1 ; -10 -> -10*1 ; -9 -> -9*-10 ; -8 -> -8*-10*-9 - > -8 * (product-from-minus-11 -9 ) ; -n -> n * (product-from-minus-11 (- n 1) ) (define (product-from-minus-11 n) (cond [(= n -11) 1] [else (* n (product-from-minus-11 (- n 1)))])) ;(product-from-minus-11 -11) ;-1 (product-from-minus-11 -10) ;-10 ``` ## 11.5.2 定義函數 multiply,其輸入是兩個自然數n和x,不使用 Scheme提供的*,返回n*x。最后,去除這些定義之中的+。 提示:n乘以x就是把n個x加起來。 解體 ``` ;; multiply:number,number->number ;; 0,2->0 ;; 1,2->1*2 ;; 2,2->2*2 ;; 3,3->2*2*2->2*(multiply 2 2) ;; n,x->x*(multiply (- n 1) x) (define (multiply n x) (cond [(= n 0)0] [(= n 1)x] [else (* x (multiply (- n 1) x))])) (multiply 0 2);0 (multiply 1 2);2 (multiply 3 2);8 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看