How to Design Programs的笔记(19)

按有用程度 按页码先后 最新笔记

  • [已註銷]

    The functions we have developed so far fall into two broad categories. On one hand, we have the category of functions that encapsulate domain knowledge. On the other hand, we have functions that consume structured data. These functions typically decompose their arguments into their immediate structural components and then process those components. If one of the immediate components belongs to t...

    2013-03-06 13:54:27

  • [已註銷]

    Syntax of lambda A lambda-expression is just a new form of expression: <exp> = (lambda (<var> ... <var>) <exp>) Here are three useful examples: (lambda (x c) (> (* x x) c)) (lambda (ir p) (< (ir-price ir) p)) (lambda (ir p) (symbol=? (ir-name ir) p)) Scope and Semantics of lambda As discussed in the introduction, a lambda-expression is just a short-hand for a loca...

    2013-03-05 14:47:49

  • [已註銷]

    def-1 ... def-n E[(local ((define (f-1 x) exp-1) ... (define (f-n x) exp-n)) exp)] = def-1 ... def-n (define (f-1' x) exp-1') ... (define (f-n' x) exp-n') E[exp'] ;; sort : list-of-numbers -> list-of-numbers (define (sort alon) (cond [(empty? alon) empty] [(cons? alon) (insert (first alon) (sort (rest alon)))])) ;; insert : number list-of-numbers (sorted) -> list-of-numbers (define (i...

    2013-03-05 14:19:33

  • [已註銷]

    Lists and natural numbers are two classes of data whose description requires self-referential data definitions. Both data definitions consist of two clauses; both have a single self-reference. Many interesting classes of data, however, require more complex definitions than that. Indeed, there is no end to the variations. It is therefore necessary to learn how to formulate data definitions on ou...

    2013-03-05 13:31:39

  • [已註銷]

    A simpler way to understand list expressions is to think of them as abbreviations. Specifically, every expression of the shape (list exp-1 ... exp-n) stands for a series of n cons expressions: (cons exp-1 (cons ... (cons exp-n empty))) (list 1 2) = (cons 1 (cons 2 empty)) (list 'Houston 'Dallas 'SanAntonio) = (cons 'Houston (cons 'Dallas (cons 'SanAntonio empty))) (list false true false false) ...

    2013-03-05 13:11:21

  • [已註銷]

    (first (cons 10 empty)) = 10 (rest (cons 10 empty)) = empty (first (rest (cons 10 (cons 22 empty)))) = (first (cons 22 empty)) = 22 A list-of-symbols is either the empty list, empty, or (cons s los) where s is a symbol and los is a list of symbols. 所以要检查empty的list, 也。不。喜。欢。 ;; hours->wages : list-of-numbers -> list-of-numbers ;; to create a list of weekly wages from a list...

    2013-02-28 14:17:03

  • [已註銷]

    #The Scheme Vocabulary <var> = x | area-of-disk | perimeter | ... <con> = true | false 'a | 'doll | 'sum | ... 1 | -1 | 3/5 | 1.22 | ... <prm> = + | - | ... The first category is that of variables, which are the names of functions and values. The second introduces constants: boolean, symbolic, and numeric constants. As indicated before, Scheme has a powerful number sy...

    2013-02-28 14:00:39

  • [已註銷]

    (define (f a-shape) (cond [(square? a-shape) ...] [(circle? a-shape) ...])) (error 'checked-area-of-disk "number expected") 所以还要手动检查变量类型?不科学呀。 (define (checked-area-of-disk v) (cond [(number? v) (area-of-disk v)] [(boolean? v) (error 'checked-area-of-disk "number expected")] [(symbol? v) (error 'checked-area-of-disk "number expected")] [(struct? v) (error 'checked-area-of-disk...

    2013-02-28 13:28:23

  • [已註銷]

    ;; Data Analysis & Definitions: (define-struct student (last first teacher)) ;; A student is a structure: (make-student l f t) where f, l, and t are symbols. ;; Contract: subst-teacher : student symbol -> student ;; Purpose: to create a student structure with a new ;; teacher name if the teacher's name matches 'Fritz ;; Examples: ;; (subst-teacher (make-student 'Find 'Matthew 'Fritz) '...

    2013-02-27 15:00:45

  • [已註銷]

    define-struct posn (x y)) When DrScheme evaluates this structure definition, it creates three operations for us, which we can use to create data and to program: make-posn, the CONSTRUCTOR, which creates posn structures; posn-x, a SELECTOR, which extracts the x coordinate; posn-y, also a selector, which extracts the y coordinate. (symbol=? 'Hello 'Hello) = true (symbol=? 'Hello 'Howdy) = false (...

    2013-02-27 14:27:38

<前页 1 2 后页>

笔记是你写在书页留白边上的内容;是你阅读中的批注、摘抄及随感。

笔记必须是自己所写,不欢迎转载。摘抄原文的部分应该进行特殊标明。

How to Design Programs

>How to Design Programs