TableOfContents

Building Abstractions with Procedures

1. The Elements of Programming

1.1. Expressions

486

   1 486

(+ 137 349)
486
(- 1000 334)
666
(* 5 99)
495
(/ 10 5)
2
(+ 2.7 10)
12.7

   1 137 + 349
   2 1000 - 334
   3 5 * 99
   4 10 / 5
   5 2.7 + 10

(+ 21 35 12 7)
75

(* 25 4 12)
1200

   1 21 + 35 + 12 + 7
   2 25 * 4 * 12

或者

reduce(int.__add__, [21, 35, 12, 7])
reduce(int.__mul__, [25, 4, 12])

(+ (* 3 5) (- 10 6))
19

   1 (3 * 5) + (10 - 6)

(+ (* 3
      (+ (* 2 4)
         (+ 3 5)))
   (+ (- 10 7)
      6))

   1 (3 * ((2*4)+(3+5)) ) + ((10-7)+6)

1.2. Naming and the Environment

(define size 2)

   1 size = 2

size
2
(* 5 size)
10

   1 size
   2 5 * size

(define pi 3.14159)
(define radius 10)
(* pi (* radius radius))
314.159
(define circumference (* 2 pi radius))
circumference
62.8318

   1 pi = 3.14159
   2 radius = 10
   3 pi * (radius * radius)
   4 circumference = 2 * pi * radius
   5 circumference

1.3. Evaluating Combinations

(* (+ 2 (* 4 6))
   (+ 3 5 7))

   1 (2+(4*6)) * (3+5+7)
ch3n2k.com | Copyright (c) 2004-2020 czk.