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

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

by Tom Stuart
November 2017
Beginner to intermediate
344 pages
7h 2m
Chinese
GoTop Information, Inc.
Content preview from 深入理解運算原理|從簡單的機器到無所不能的程式
180
|
6
它的運作十分正常,所以我們可以在 FizzBuzz 將所有的
#zero
呼叫換成
IS_ZERO
(ONE..HUNDRED).map do |n|
IF[IS_ZERO[n % FIFTEEN]][
'FizzBuzz'
][IF[IS_ZERO[n % THREE]][
'Fizz'
][IF[IS_ZERO[n % FIVE]][
'Buzz'
][
n.to_s
]]]
end
對組
我們有數值和布林值形式的自由資料,但卻完全沒有能以有組織的方式儲存多個值的資
料結構。為了實作更複雜的功能,我們很快就需要一些資料結構,所以讓我們稍微暫停
做些介紹。
對組
pair
)是最簡單的資料結構,例如雙元素陣列。對組非常容易實作:
PAIR = -> x { -> y { -> f { f[x][y] } } }
LEFT = -> p { p[-> x { -> y { x } } ] }
RIGHT = -> p { p[-> x { -> y { y } } ] }
對組的目的是儲存兩個值,並在稍後需要的時候再次提供它們。為了建構對組,我們可
以用兩個值(
x
y
)來呼叫
PAIR
,而它會傳回它內部的 proc
-> f { f[x][y] }
以另一個 proc
f
一起呼叫這個 proc 時,這個 proc 會以先前的
x
y
值作為引數呼叫
它。
LEFT
RIGHT
是揀選出對組的左右元素的運算,作法是以分別傳回它第 1 個或第 2
個引數的 proc 來呼叫它。整個運作都非常簡單:
>> ...
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