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

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

by Tom Stuart
November 2017
Beginner to intermediate
344 pages
7h 2m
Chinese
GoTop Information, Inc.
Content preview from 深入理解運算原理|從簡單的機器到無所不能的程式
無為的程式設計
|
205
雖然大多認為這個實作物比原本的簡單,但一般來說它不僅更難以閱讀且效率較低,因
為它總是執行狀況最糟的重複呼叫次數,而不是盡快停止。它也不會等於原來的版本,
因為如果我們要求它除以
ZERO
(條件式
n <= m
永遠不會變成 false),舊版本的
MOD
將會
永遠循環,而這個實作物只會傳回它的第 1 個引數:
>> to_integer(MOD[THREE][ZERO])
=> 3
RANGE
雖然稍微具有挑戰性,但是我們可以使用類似讓
DECREMENT
運作的技巧:設計
一個函式,在某些初始引數呼叫
n
次時,能從所需的範圍傳回
n
個數值的串列。和
DECREMENT
相同的是,其中的秘密是使用對組來儲存結果的串列和下一次迭代所需的資
訊:
def countdown(pair)
[pair.first.unshift(pair.last), pair.last - 1]
end
>> countdown([[], 10])
=> [[10], 9]
>> countdown(countdown([[], 10]))
=> [[9, 10], 8]
>> countdown(countdown(countdown([[], 10])))
=> [[8, 9, 10], 7]
>> countdown(countdown(countdown(countdown([[], 10]))))
=> [[7, 8, 9, 10], 6]
這很容易以 proc 重新編寫:
COUNTDOWN = -> p { PAIR[UNSHIFT[LEFT[p]][RIGHT[p]]][DECREMENT[RIGHT[p]]] ...
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