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

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

by Tom Stuart
November 2017
Beginner to intermediate
344 pages
7h 2m
Chinese
GoTop Information, Inc.
Content preview from 深入理解運算原理|從簡單的機器到無所不能的程式
188
|
6
感謝這個未用欺騙手段的
MOD
版本仍然有效:
>> to_integer(MOD[THREE][TWO])
=> 1
>> to_integer(MOD[
POWER[THREE][THREE]
][
ADD[THREE][TWO]
])
=> 2
現在我們可以呼叫
MOD
來換掉 FizzBuzz 程式裡所有出現的
%
(ONE..HUNDRED).map do |n|
IF[IS_ZERO[MOD[n][FIFTEEN]]][
'FizzBuzz'
][IF[IS_ZERO[MOD[n][THREE]]][
'Fizz'
][IF[IS_ZERO[MOD[n][FIVE]]][
'Buzz'
][
n.to_s
]]]
end
串列
我們只剩下些許Ruby 功能要替FizzBuzz 重新實作:範圍、
#map
、字串常值、
Fixnum#to_s
。我們已經看過很多我們實作過的其他的值和運算的細節,所以會盡快瀏覽
剩下的一些細節(不用擔心無法瞭解所有的一切,我們只是要淺嚐風味而已)。
為了能實作範圍和
#map
,我們需要串列的實作物,而建置串列最簡單的方法就是使用
對組。這個實作物的運作就像鏈結串列,其中每個對組儲存一個值和一個指到串列裡下
個對組的指標;我們在此例使用巢狀的對組而非指標。如下是標準串列的運算:
EMPTY = PAIR[TRUE][TRUE]
UNSHIFT = -> l { -> x {
PAIR[FALSE][PAIR[x][l]]
} }
IS_EMPTY = LEFT ...
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