<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ## 17.1.2 同時處理兩張表 開發 cross,該函數讀入一個符號表和一個數表,返回所有可能的符號——數對。 例如: ``` (cross '(a b c) '(1 2)) ;; 期望值: (list (list 'a 1) (list 'a 2) (list 'b 1) (list 'b 2) (list 'c 1) (list 'c 2)) ``` ``` (define (make-list symbol a-list) (cond [(empty? a-list) empty] [else (append (list (list symbol (first a-list))) (make-list symbol (rest a-list))) ])) (define (cross a-list b-list) (cond [(empty? a-list) empty] [(symbol? a-list) (make-list a-list b-list)] [else (append (cross (first a-list) b-list) (cross (rest a-list) b-list)) ])) (cross '(a b c) '(1 2)) ; '((a 1) (a 2) (b 1) (b 2) (c 1) (c 2)) ``` ## 17.2.1 計算員工薪水 在真實世界中,hours->wages 讀入員工結構體的表和工作結構體的表。員工結構體包含員工的 名字、社會保險號碼和單位工資(每小時工資)。工作結構體包含員工的名字和他一周中的工作時間。函 數的返回值是一個結構體的表,結構體中包含員工的名字和周工資 ``` ;;定義員工一周工作時長的結構體 (define-struct employees (name hours)) ;; 定義員工一周工資結構體 (define-struct employees-out (name salary)) ;; 定義薪水計算 (define (weekly-wage pay-rate hours-worked) (* pay-rate hours-worked)) ;; 計算員工一周薪水以 employess-out 的表 ;;hours->wages:employees,list-salary->employees (define (hours->wages alon1 alon2) (cond [(empty? alon1) empty] [else (list (make-employees-out (employees-name (first alon1)) (weekly-wage (employees-hours (first alon1)) (first alon2) ) ) (hours->wages (rest alon1) (rest alon2)))])) ;; '(#<employees-out> (#<employees-out> ())) (hours->wages (list (make-employees 'a 40.0) (make-employees 'b 30.0)) (list 5.65 8.75)) ``` ## 17.2.2 輸出人名電話表 開發函數 zip,該函數把人名的表和電話號碼的表結合成電話記錄的表。假定其結構體定義如 下 ``` ;; 定義人名電話結構體 (define-struct phone-record (name number)) ;; 注意 else(cons 不能改為 list 否則會出現如下錯誤 ;; (zip (list 'a) (list 1)) -> '(#<phone-record> ()) (define (zip list-name list-phone) (cond [(empty? list-name) empty] [else (cons (make-phone-record (first list-name) (first list-phone)) (zip (rest list-name) (rest list-phone)))])) (zip empty empty) ;empty (zip (list 'a) (list 1)) ;'(#<phone-record>) (zip (list 'a 'b 'c) (list 1 2 3 ));'(#<phone-record> #<phone-record> #<phone-record>) ``` ## 17.3.1 開發 list-pick0,該函數從表中選出一個元素,類似于 list-pick,但是從 0 開始計數。 ``` (define (list-pick0 list-a n) (cond [(empty? list-a) (error 'list-pick0 "the list is too short")] [(= n 0) (first list-a)] [else (list-pick0 (rest list-a) (- n 1))])) (symbol=? (list-pick0 (list 'a 'b 'c 'd) 3)'d) (list-pick0 (list 'a 'b 'c 'd) 4) ``` ## 17.6 merge 函數,合并兩個升序表 開發函數 merge,該函數讀入兩個升序排列的數表,返回一個升序排列的數表,表中包含(且 僅包含)兩個輸入表中所有的數,某個數在輸出表中出現的次數應該與它在兩個輸入表中出現的總數相同 ``` ;; 讀入兩個升序排列的數表,返回一個升序排列的數表 ;; merge:asc1-list,asc2-list:asc3-list ;; 測試案例 ;;(merga empty empty) ;empty ;;(merga empty (list 1)) ;(list 1) ;;(merga (list 1) empty) ;(list 1) ;;(merga (list 1) (list 1 2)) ;(list 1 1 2) ;;(merga (list 1 2) (list 1 3)) ;(list 1 1 2 3) ;;模版 ;;(define (merga list-a list-b) ;; (cond ;; [(empty? list-a) list-b] ;; [(empty? list-b) list-a] ;; [(< (first list-a) (first list-b)) ... (first list-a) ... (merga (rest list-a) list-b )...] ;; [else ... (first list-b) ... (merga list-a (rest list-b ))...])) ;; 測試案例 (define (merga list-a list-b) (cond [(empty? list-a) list-b] [(empty? list-b) list-a] [(< (first list-a) (first list-b)) (cons (first list-a) (merga (rest list-a) list-b ))] [else (cons (first list-b) (merga list-a (rest list-b )))])) (merga empty empty) ;empty (merga empty (list 1)) ;(list 1) (merga (list 1) empty) ;(list 1) (merga (list 1) (list 1 2)) ;(list 1 1 2) (merga (list 1 2) (list 1 3)) ;(list 1 1 2 3) ``` ## 17.8 相等于測試 比較兩個list 是否相等 ``` ;; 比較兩個 list 是否相等 ;; list=?:a-list.b-list->boolean ;;測試 ;;(boolean=? (list=? empty empty) true) ;;(boolean=? (list=? (list 'a) empty) false) ;;(boolean=? (list=? empty (list 'a)) false) ;;(boolean=? (list=? (list 'a) (list 'a)) true) ;;(boolean=? (list=? (list 'a 'b) (list 'a 'b)) true) ;;(boolean=? (list=? (list 'a) (list 'b)) false) ;; 模板 ;;(define (list=? a-list b-list) ;; (cond ;; [(or (empty? a-list) (empty? b-list)) false ] ;; [not(symbol=? (first a-list) (first b-list) ) false] ;; [(symbol=? (first a-list) (first b-list)) ... (first a-list) ... (list=? (rest a-list) (rest )) ...] ;; [else true])) ;; (define (list=? a-list b-list) (cond [(and (empty? a-list) (empty? b-list)) true] [(or (empty? a-list) (empty? b-list)) false ] [else (and (symbol=? (first a-list) (first b-list)) (list=? (rest a-list) (rest b-list)))])) (boolean=? (list=? empty empty) true) (boolean=? (list=? (list 'a) empty) false) (boolean=? (list=? empty (list 'a)) false) (boolean=? (list=? (list 'a) (list 'a)) true) (boolean=? (list=? (list 'a 'b) (list 'a 'b)) true) (boolean=? (list=? (list 'a) (list 'b)) false) ``` ## 17.8.4 判斷兩個數表中是否含有相同的數,而不管他們的順序 ``` ;; 判斷兩個數表中是否含有相同的數,而不管他們的順序 ;; contains-same-numbers:a-list,b-list->boolean ;;輔助函數,檢測 symbol 是否在 list 中 ;;測試 ;;(boolean=? (contains-symbol 1 (list 1)) true) ;;(boolean=? (contains-symbol 1 (list 2)) false) ;;(boolean=? (contains-symbol 1 (list 2 1)) true) ;;(boolean=? (contains-symbol 1 (list 2 3)) false) (define (contains-symbol num search-list) (cond [(empty? search-list) false] [(= num (first search-list)) true] [else (contains-symbol num (rest search-list))])) ;; 測試 ;;(boolean=? (contains-same-numbers empty empty) false) ;;(boolean=? (contains-same-numbers empty (list 1)) false) ;;(boolean=? (contains-same-numbers (list 1) (list 1)) true) ;;(boolean=? (contains-same-numbers (list 1 2 3) (list 3 2 1)) true) ;;模板 (define (contains-same-numbers a-list b-list) (cond [(empty? a-list) false] [else (and (contains-symbol (first a-list) b-list) (cond [(cons? (rest a-list)) (contains-same-numbers (rest a-list) b-list)] [else true]) )])) (boolean=? (contains-same-numbers empty empty) false) (boolean=? (contains-same-numbers empty (list 1)) false) (boolean=? (contains-same-numbers (list 1) (list 1)) true) (boolean=? (contains-same-numbers (list 1 2 3) (list 3 2 1)) true) ``` ## 17.8.5 開發函數 `list-equal?`,該函數讀入兩個原子表,判斷它們是否相等。 ``` ;; 讀入兩張原子表,判斷他們是否相等 ;;原子類型有三種,數,布爾,符號 ;;輔助函數,兩個值是否相等 (define (any-type? x y) (cond [(and (empty? x) (empty? y)) true] [(and (boolean? x) (boolean? y)) (boolean=? x y)] [(and (number? x) (number? y)) (= x y)] [(and (symbol? x) (symbol? y)) (symbol=? x y)] [else false])) ;;輔助函數測試 ;;(boolean=? (any-type? empty empty) true) ;;(boolean=? (any-type? 1 1) true) ;;(boolean=? (any-type? 1 2) false) ;;(boolean=? (any-type? 'a 'a) true) ;;(boolean=? (any-type? 'a 'b) false) ;;(boolean=? (any-type? false false) true) ;;(boolean=? (any-type? false true) false) ;;(boolean=? (any-type? (list 1) 1) false) ;; list-equal?:a-list,b-list->boolean ;;測試 ;;(boolean=? (list-equal? empty empty) true) ;;(boolean=? (list-equal? (list 'a) (list 'a)) true) ;;(boolean=? (list-equal? (list 'a 1 true) (list 'a 1 true)) true) ;;(boolean=? (list-equal? (list 'a 1 true) (list 'a 2 true)) false) (define (list-equal? a-list b-list) (cond [(empty? a-list) (any-type? a-list b-list) ] [else (and (any-type? (first a-list) (first b-list)) (list-equal? (rest a-list) (rest b-list)))])) (boolean=? (list-equal? empty empty) true) (boolean=? (list-equal? (list 'a) (list 'a)) true) (boolean=? (list-equal? (list 'a 1 true) (list 'a 1 true)) true) (boolean=? (list-equal? (list 'a 1 true) (list 'a 2 true)) false) ``` ## 17.8.7 該函數讀入兩個二元的posn結構體,判斷它們是否相等 ``` ;;該函數讀入兩個二元的posn結構體,判斷它們是否相等。 ;; posn 的結構體 (define-struct posn (x y)) ;; posn=?:a-posn,b-posn->boolean ;; 測試 ;; (define (posn=? a-posn b-posn) (cond [(and (posn? a-posn) (posn? b-posn)) ( and (= (posn-x a-posn) (posn-x b-posn)) (= (posn-y a-posn) (posn-y b-posn)))] [else false])) (boolean=? (posn=? empty empty) false) (boolean=? (posn=? empty (make-posn 1 1)) false) (boolean=? (posn=? (make-posn 1 1) empty) false) (boolean=? (posn=? (make-posn 1 1) (make-posn 1 1)) true) (boolean=? (posn=? (make-posn 1 1) (make-posn 1 2)) false) ```
                  <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>

                              哎呀哎呀视频在线观看