《How to design programs》第三回

中秋佳節到了,祝大家中秋節快樂!

今天討論第五章《符號》

符號(symbol)是一個基本的類型。原文是這樣描述的,”Like a number, a symbol has no inherent meaning. It is up to the function's user to relate symbolic data and real-world information, though the connection is typically obvious in a specific context. “符號沒有實質含義,符號是作者大人將符號信息聯繫現實世界信息。比如'east代表東方,但是我也可以說'王老五代表東方。從某種意義上來說,符號就是在給現實世界事物取名。

符號表示原文是這樣說的,”A symbol is a sequence of keyboard characters16 preceded by a single forward quotation mark“符號表示爲單引號開頭,然後一長串字符序列。

符號在scheme中只有一種運算,那就是判斷兩個符號是否相同(symbol=? ‘east ’west)

然後書上舉了一個使用條件判斷和符號的例子。我內容修改一下,改成如下對答。

A: How are you?

B: I'm fine.Think you.And you?

C: Me too.

這個是初中英語的前幾句經典臺詞吧。好,就做這個了

;; replay: symbol -> symbol
;; return the reply to the symbol
(define (reply s)
	(cond ((symbol=? s 'Howareyou) 'Imfine3QAndyou)
	      ((symbol=? s 'Imfine3QAndyou) 'Metoo)
              (else 'Idontknow))) 

看起來很簡單吧!


jdrgsbirr

發佈了44 篇原創文章 · 獲贊 17 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章