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

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

by Tom Stuart
November 2017
Beginner to intermediate
344 pages
7h 2m
Chinese
GoTop Information, Inc.
Content preview from 深入理解運算原理|從簡單的機器到無所不能的程式
270
|
8
程式碼就是資料
程式都有兩種人生。除了控制特定系統的指令,我們還可以將程式視為純粹的資料:運
算式的樹狀結構、字元的原始字串,或甚至是單一大型數值。一般都認為身為程式開發
人員的我們應該瞭解這種二元性,但是對於通用型的電腦來說,可以將程式表示成資料
則十分重要,因此就可以將它們用作其他程式的輸入;程式碼和資料一致之後,讓軟體
在一開始變得可能。
在通用圖靈機的例子,我們已經看到了程式即資料,另一個圖靈機的規則手冊預期會在
它的磁帶寫入一組字元。在像是 Lisp
3
XSLT 之類的華麗
同像性
homoiconic
)程式語
言,我們要明確的將程式寫成語言本身可以操作的資料結構:每個 Lisp 程式都是稱為
s-expression
的巢狀串列,而每個 XSLT 樣式表則都是 XML 文件。
Ruby 中通常只有直譯器(至少就 MRI 這種情況,不是以 Ruby 本身編寫)可以看到
程式的結構化表示,但程式碼即資料的原則仍然適用。例如這個簡單的 Ruby 程式:
puts 'hello world'
對於瞭解 Ruby 語法和語意的觀察者來說,這個程式將
puts
訊息和
'hello world'
字串
傳給
main
物件,這會讓
Kernel#puts
方法將
hello world
列印到標準輸出。但在較低的
層次來看,那只是一組字元序列,而且因為將字元表示成位元組,因此最後可以將那個
序列視為大型的數值:
>> program = "puts 'hello world'"
=> "puts 'hello ...
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