Skip to Content
深入理解運算原理|從簡單的機器到無所不能的程式
book

深入理解運算原理|從簡單的機器到無所不能的程式

by Tom Stuart
November 2017
Beginner to intermediate
344 pages
7h 2m
Chinese
GoTop Information, Inc.
Content preview from 深入理解運算原理|從簡單的機器到無所不能的程式
四處皆通用
|
225
對於讓
y * (n + 1)
大於
x
n
值來說,運算式
subtract(increment(x)
,
multiply(y, increment(n)))
設計成傳回零。如果我們試著將 13 除以 4
(x
= 13, y = 4)
,當遞增
n
的時候,請檢查
y * (n + 1)
的值:
n x y * (n + 1) y * (n + 1) 是否大於 x
0 13 4 no
1 13 8 no
2 13 12 no
3 13 16 yes
4 13 20 yes
5 13 24 yes
滿足條件的
n
的第 1 個值是
3
,所以我們傳給
#minimize
的區塊將在
n
變成
3
的時候,第 1 次傳回零,而且我們會如同
divide(13, 4)
的結果得到
3
以合理的引數呼叫
#divide
時,它一定會傳回結果,就如同基元遞迴函式:
>> divide(six, two)
=> 3
>> def ten
increment(multiply(three, three))
end
=> nil
>> ten
=> 10
>> divide(ten, three)
=> 3
但是
#divide
並非一定要傳回答案,因為
#minimize
可以永遠循環。以
#divide
除以零會
有無法預期的結果:
>> divide(six, zero)
SystemStackError: stack level too deep
在這裡看到堆疊溢位讓人有點驚訝,因為
#minimize
的實作物不僅是迭
代,而且不會直接增加堆疊的呼叫,而是在
#divide ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

JSON實務手冊

JSON實務手冊

Tom Marrs

Publisher Resources

ISBN: 9789864766000