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

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

by Tom Stuart
November 2017
Beginner to intermediate
344 pages
7h 2m
Chinese
GoTop Information, Inc.
Content preview from 深入理解運算原理|從簡單的機器到無所不能的程式
無為的程式設計
|
213
雖然的確發生了某些事情,但是我們完全沒有得到想要的結果:最後的運算式是
-> p {
-> x { p[-> p { -> x { p[x] } }[p][x]] } }
,但是數值 2 lambda 演算表示應該是
->
p { -> x{ p[p[x]] } })]
。哪裡出錯了?
不一致是因為我們使用的估算策略所造成。結果裡仍然埋著可以簡化的函式呼叫(例如
可以將呼叫
-> p { -> x { p[x] } }[p] 簡化成 -> x { p[x] }
),但是
#reduce
不會處理這
些,因為它們出現在函式主體裡,而我們的語意不會將函式視為可以簡化
9
但就如同第 170 頁的『相等』所討論,如果它們的行為相同,仍然可以將兩個語法不
同的運算式視為相等。我們知道數值 2 lambda 演算如何表現:如果我們給它兩個引
數,它會在第 2 個引數呼叫第 1 個引數兩次。所以讓我們試著以兩個虛構的變數 inc
zero
10
呼叫我們的運算式,並且看看它實際完成了什麼:
>> inc, zero = LCVariable.new(:inc), LCVariable.new(:zero)
=> [inc, zero]
>> expression = LCCall.new(LCCall.new(expression, inc), zero)
=> -> p { -> x { p[-> p { -> x { p[x] } }[p][x]] } }[inc][zero]
>> ...
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