| English | 释义 | 拼音 |
|---|---|---|
| reusable/riːˈjuːzəbl/ | 可重用 | kě zhòng yòng |
| procedure/prəˈsiːdʒə/ | 过程 | guò chéng |
| call/kɔːl/ | 调用 | diào yòng |
| method/ˈmeθəd/ | 方法 | fāng fǎ |
| arguments/ˈɑːɡjuːmənts/ | 实参 | shí cān |
| parameters/pəˈræmɪtəz/ | 形参 | xíng cān |
| return value/rɪˈtɜːn ˈvæljuː/ | 返回值 | fǎn huí zhí |
| implementation/ˌɪmplɪmənˈteɪʃn/ | 实现 | shí xiàn |
| abstraction/əbˈstrækʃn/ | 抽象 | chōu xiàng |
可重用的代码块
- 一个过程(procedure),也叫函数(function)或方法(method),是一个命名的可重用(reusable)代码块。
- 你写它一次,用它许多次。
- 它给一个任务一个名字,于是你能在需要时调用那个任务。
- 这是"不要重复自己"的核心。
A procedure (function/method) is:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Write it once, call it many times.
To run a procedure's instructions from elsewhere, you ______ it by name.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
After the call finishes, the program continues where it left off.
调用过程
- 要从别处运行一个过程,你按名字调用(call)它。
- 当调用完成,程序从它离开的地方继续。
- 所以调用像一段绕路:去做那个任务,然后回来。
- 同一个过程能从许多地方被调用。

实参(Arguments)传入,主体执行,RETURN 返回一个值
How a procedure call works
A call jumps to the procedure with its arguments, runs the body, returns a value, and the program continues where it left off.
Match each term in area(4, 5) to its meaning.
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Arguments are the actual values; parameters are the named slots.
In total ← area(4, 5), what does area give back?
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
The returned result is stored for later use.
实参、形参、返回
- 过程可以接收输入:你通过形参(parameters)向过程传递参数(arguments)。
area(length, width)以area(4, 5)调用时接收 4 和 5。- 一个过程也能返回一个返回值(return value)——一个你以后用的结果。
- 例如
total ← area(4, 5)存储返回的值。
If square(n) returns n × n, what does square(square(3)) return?
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
square(3) = 9, then square(9) = 81.
To call square(3), you must know exactly how it works inside.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
False. Procedural abstraction means you only need to know what the procedure does, not how it is implemented.
隐藏实现
- 过程通过对调用者隐藏实现(implementation)细节支持抽象(abstraction)。
- 你只需知道一个过程做什么,而非它内部如何工作。
square(n) 返回 n × n。 a ← square(3) 存 9。b ← square(a) 存 81,因为 square(9) 是 81。调用者从不看到内部的乘法——它只用返回值。
一个过程(函数或方法)是你按名字调用的可重用代码;程序在它返回后继续。你把实参传进它的形参,并能用它的返回值。过程给出抽象——调用者知道它做什么,而非实现。