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

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

by Tom Stuart
November 2017
Beginner to intermediate
344 pages
7h 2m
Chinese
GoTop Information, Inc.
Content preview from 深入理解運算原理|從簡單的機器到無所不能的程式
172
|
6
雖然這對 FizzBuzz 問題依然是有意義的解決方案,但現在這是我們只使用 proc 來實作
的機會。
儘管它很簡單,但如果我們沒有程式語言的任何功能,這會是非常具有野心、抱負
的程式:它建立範圍、映射到它、估算大條件、以模數運算子完成算術運算、使用
Fixnum#zero?
述語、使用一些字串常值,而且會以
Fixnum#to_s
將數值轉換成字串。
這是相當大量的 Ruby 內建功能,我們不得不全數刪除,並且重新以 proc 實作。
數值
我們首先將焦點放在出現在 FizzBuzz 的數值。怎麼做可以不使用 Fixnums Ruby
供的任何其他資料型別而能表示數值?
如果想要試著從頭開始實作數值
3
最好對自己正在實作的內容能有充分的瞭解。不管
如何,究竟何謂
數值
?這實在很難從我們剛好正在定義的某些假設觀點給個具體的解
釋;例如,『告訴我們有多少…』就不是很實用,因為『多少』真的只是另一種『數值』
說法。
這裡有一種描述數值特徵的方式:想像我們有一袋蘋果和一袋橘子。我們從某個袋子裡
拿出一個蘋果,也從另一個袋子裡拿出一個橘子,並且將它們放在一邊,然後我們持續
拿出蘋果和橘子,一直到至少其中某個袋子是空的。
如果兩個袋子同時變空,我們就能學到一些有趣的東西:儘管包含的東西不同,但這些
袋子具有一些意謂著它們同時變空的共用特性;每次在反覆從每個袋子移出物品的過
程,兩個袋子都不是空的,或者兩個袋子都是空的。我們可以將這些袋子共用的抽象特
性稱為數值(雖然我們不知道
哪個
號碼!),而且我們可以將這些袋子與世界上其他任 ...
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