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...
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...
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...
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) ...
(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...
#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...
;; 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) '...
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-03-06 13:54:27
[已註銷]
2013-03-05 14:47:49
[已註銷]
2013-03-05 14:19:33
[已註銷]
2013-03-05 13:31:39
[已註銷]
2013-03-05 13:11:21
[已註銷]
2013-02-28 14:17:03
[已註銷]
2013-02-28 14:00:39
[已註銷]
2013-02-28 13:28:23
[已註銷]
2013-02-27 15:00:45
[已註銷]
2013-02-27 14:27:38