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

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

by Tom Stuart
November 2017
Beginner to intermediate
344 pages
7h 2m
Chinese
GoTop Information, Inc.
Content preview from 深入理解運算原理|從簡單的機器到無所不能的程式
不可能的程式
|
277
程式可以自我參照
does_it_say_no.rb
使用的自我參照技巧,雖然取決於我們所構建的程式能力(此程式可
以讀取它自己的原始碼),但它似乎有點像是要欺騙來假設這永遠都可能發生。多虧了
周圍環境(也就是殼層)提供的功能,我們範例裡的程式才能接收它自己的原始碼作為
輸入;若無此選項,它也能利用 Ruby 的檔案系統 API 和永遠都包含目前檔案名稱的特
FILE
常數,透過
File.read(__FILE__)
直接從磁碟讀取資料。
但是我們應當提出全面性的論證,它只取決於 Ruby 的通用性,而不是作業系統或
File
類別的能力。執行時可能無法存取它們原始碼的編譯語言(像是 JavaC)呢?透過網
路連線而載入記憶體,而且根本不會儲存在本機檔案系統的 JavaScript 程式呢?諸如圖
靈機和 lambda 演算這類自我包含的通用系統,『檔案系統』和『標準輸入』的概念在
這些系統都不存在嗎?
所幸
does_it_say_no.rb
引數經得起這樣的異議,因為程式能從標準輸入讀取自己的原始
碼,只是所有通用系統都能做的方便速記,而且不論其環境或其他功能如何。這是
雷尼第二遞迴定理
Kleene's second recursion theorem
)的基本數學結果的推論,它保
證任何程式皆可轉換成能運算它自己原始碼的等效版本。這項遞迴定理保證我們的速
記完全合理:我們可以用一些程式碼換掉這行
program = $stdin.read
,來產生
does_it_
say_no.rb
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