2019独角兽企业重金招聘Python工程师标准>>>

PROPERTIES AND ARRAYS
---------------------------------
property lists and arrays* A procedure that creates data is a constructor.
* A procedure that extracts data is a reader.
* A procedure that changes data is a writer.
-----------------------------------------------------------
Symbol     Parents Property    Children Property
patrick    (robert dorothy)    (sarah)
karen      (james eve)         (sarah)
-------------------------------------------------------------
(get <symbol <property name>)* (get 'patrick 'parents)
(ROBERT DOROTHY)
-----------------------------------------------------------
(setf (get <symbol> <property name>) <property vaule>)* (setf (get 'patrick 'parents) '(robert dorothy))
(ROBERT DOROTHY)
------------------------------------------------------------
(remprop <symbol> <property name>)* (setf (get 'bag 'contents) '(bread butter))
(BREAD BUTTER)* (get 'bag 'contents)
(BREAD BUTTER)* (remprop 'bag 'contents)
T* (get 'bag 'contents)
NIL題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題11-1: Assume that if a person's father is known, the father's
name is given as the value of the FATHER property.  Define GRANDFATHER,
a procedure that returns the name of a person's paternal grandfather, if
known, or NIL otherwise.
-------------------------------------------------------------------
11-2: Define ADAM, a procedure that returns the most distant male
ancestor of a person through the paternal line, working through the
FATHER property.  If no male ancestor is known, the procedure is to
return the name given as its argument.  For simplicity, assume that no
name is ever used twice.
--------------------------------------------------------------------
11-3: Define ANCESTORS, a procedure that returns a list consisting of
the person given as its argument together with all known ancestors of
the person.  It is to work through both the FATHER and MOTHER properties.
You may assume that related people do not have children together; that
is, there is never a way to get to any ancestor by two distinct paths.
----------------------------------------------------------------------
11-4: Suppose each city in a network of cities and highways is
represented by a symbol.  Further suppose that each city has a property
named NEIGHBORS.  The value of the NEIGHBORS property is a list of all
the other cities for which there is a direct highway connection.Define CONNECT, a procedure that takes two cities as arguments and puts
each into a list which the value of the NEIGHBORS property of the other.
Write CONNECT such if a connection is already in place, CONNECT changes
nothing and returns NIL; otherwise CONNECT returns T.
------------------------------------------------------------------------
11-5: Suppose that the value of the position property is a list of two
coordinates.  Assuming a flat earth, write DISTANCE, a procedure
that calculates the distance between two cities based on the values of
their POSITION properties.  Remember that SQRT calculates square roots.-----------------------------------------------------------------------* (setf part-bins (make-array '(4)))* (setf checker-board (make-array '(8 8)))* (setf part-bins (make-array 4))* (setf part-bins (make-array 4 :initial-element 'e))
#(E E E E)* (setf checker-board(make-array '(8 8):initial-contents'(X B X B X B X B)(B X B X B X B X)(X B X B X B X B)(B X B X B X B X)(X E X E X E X E)(W X W X W X W X)(X W X W X W X W)(W X W X W X W X))))
#2A((X B X B ...)(B X B X ...)(X B X B ...)(E X E X ...)...)
-----------------------------------------------------------
* (aref part-bins 0)    ;Expression stored in place 0.
EMPTY* (aref part-bins 3)    ;Expression stored in place 3.
EMPTY* (aref checker-board 0 3)    ;Expression stored in place (0 3).
B* (aref checker-board 3 0)    ;Expression stored in place (3 0).
E
---------------------------------------------------------------
(setf (aref part-bins 0) 'nails)    ;Store expression in place 0.
(Setf (aref part-bins 1) 'nuts)     ;Store expression in place 1.
(setf (aref part-bins 2) 'bolts)    ;Store expression in place 2.
(setf (aref part-bins 3) 'washers)  ;Store expression in place 3.
------------------------------------------------------------------
(defun count-bins-with-specified-part (part)(let ((result 0))(dotimes (n 4 result)(when (eq part (aref part-bins n))(setf result (+ result 1))))))* (count-bins-with-specified-part 'washers)
1
-----------------------------------------------------------------
(defun count-elements-with specified-part (part array)(let ((result 0))(dotimes (n (array-demension array 0) result)(when (eq part (aref array n))(setf result (+ result 1))))))題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題題11-6: Write STATIC-VALUE, a procedure that counts the number of
white pieces minus the number of black pieces in the CHECKER-BOARD
array.  Assume ordinary pieces are represented by W and B and kings
are represented by W-KING and B-BING.  Also one king is worth two
ordinary pieces.解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解解11-1:
(defun grandfather (x)(when (get x 'father)(get (get x 'father) 'father)))The following, more efficient solution binds a LET parameter to the
value returned by GET:(defun grandfather (x)(let ((father (get x 'father)))(when father(get father 'father))))
-------------------------------------------------------------------
11-2:
(defun adam (x)(if (get x 'father)(adam (get x 'father))x))
-----------------------------------------------------------------
11-3:
(defun ancestors (x)(when x(cons x (append (ancestors (get x 'father))(ancestors (get x 'mother))))))
------------------------------------------------------------------
11-4:
(defun connect (a b)(let ((a-neighbors (get a 'neighbors))(b-neighbors (get b 'neighbors))(result nil))(unless (member b a-neighbors)(setf (get a 'neighbors) (cons b a-neighbors))(setf result t))(unless (member a b-neighbors)(setf (get b 'neighbors) (cons a b-neighbors))(setf result t))result))
-----------------------------------------------------------------
11-5:
(defun distance (city-1 city-2)(let ((p1 (get city-1 'position))(p2 (get city-2 'position)))(sqrt (+ (expt (- (first p1) (first p2)) 2)(expt (- (second p1) (second p2)) 2)))))
-----------------------------------------------------------------
11-6: The following solution works, but inefficiently, inasmuch
as it looks at the white squares, which cannot hold pieces:(defun static-value (board)(let ((result 0))(dotimes (m 8 result)(dotimes (n 8)(cond ((eq 'white (aref board m n))(setf result (+ 1 result)))((eq 'black (aref board m n))(setf result (- result 1)))((eq 'white-king (aref board m n))(setf result (+ result 2)))((eq 'black-king (aref board m n))(setf result (- result 2))))))))How could you improve the efficiency of the procedure?

转载于:https://my.oschina.net/chuangpoyao/blog/39466

第拾壹章學習 Lisp 3rd Edition, Winston Horn相关推荐

  1. java书籍 李清华_201772020113 李清華《面向對象程序設計(java)》第18周學習總結...

    1.實驗目的與要求 (1) 綜合掌握java基本程序結構: (2) 綜合掌握java面向對象程序設計特點: (3) 綜合掌握java GUI 程序設計結構: (4) 綜合掌握java多線程編程模型: ...

  2. 從turtle海龜動畫學習Python-高中彈性課程1

    Goal: 藉由有趣的「海龜動畫繪圖」學會基礎的 Python 程式設計 本篇介紹本彈性課程之開設由來, 以及一些供後續查閱之Python 之細節, 方便後面再回頭交叉索引之內容, 文獻等 " ...

  3. (轉貼) 千頭萬緒 : 學習多執行緒程式設計的好書 (.NET) (Java)

    轉貼自千頭萬緒 : 學習多執行緒程式設計的好書 找對書,多執行緒不再避之唯恐不及 科學家對於人類大腦的運作方式,目前仍存在許多爭議.但是許多經過科學實驗的證據顯示,人類的大腦是以平行的方式工作.即使如 ...

  4. 從turtle海龜動畫 學習 Python - 高中彈性課程系列 3 烏龜繪圖 所需之Python基礎

    "Talk is cheap. Show me the code." ― Linus Torvalds 老子第41章 上德若谷 大白若辱 大方無隅 大器晚成 大音希聲 大象無形 道 ...

  5. java中集合什么时候有索引,JavaSE中Collection集合框架學習筆記(1)——具有索引的List...

    前言:因為最近要重新找工作,Collection(集合)是面試中出現頻率非常高的基礎考察點,所以好好惡補了一番. 復習過程中深感之前的學習不系統,而且不能再像剛畢業那樣死背面試題,例如:String是 ...

  6. 從turtle海龜動畫 學習 Python - 高中彈性課程系列 10.2 藝術畫 Python 製作生成式藝術略覽

    Goal: 藉由有趣的「海龜繪圖」學會基礎的 Python 程式設計 本篇著重在以 Python 海龜繪圖模擬藝術圖形, 討論與生成式藝術的關聯. 本篇我們列舉一些網路上見到的, 用電腦程式或某些軟體 ...

  7. 學習 React.js:瞭解 Flux,React.js 的架構

    2019独角兽企业重金招聘Python工程师标准>>> Getting To Know Flux, the React.js Architecture Ken Wheeler (@k ...

  8. 從turtle海龜動畫 學習 Python - 高中彈性課程系列 6 多重旋轉圓, 螺旋正方形

    Goal: 藉由有趣的「海龜動畫繪圖」學會基礎的 Python 程式設計 本篇介紹基礎的 Python 海龜動畫繪圖, 確實可以只以簡單的指令畫出極為複雜有趣或美麗的圖案: 多重旋轉之圓或多邊形, 多 ...

  9. Gazebo機器人仿真學習探索筆記(二)基本使用說明

    在完成Gazebo7安裝後,需要熟悉Gazebo,方便之後使用. 部分源代碼可以參考:https://bitbucket.org/osrf/gazebo/src/ 如果還沒有安裝請參考之前內容完成安裝 ...

最新文章

  1. Python炫技操作:条件语句的七种写法
  2. 《Java并发编程实践》学习笔记之一:基础知识
  3. centos7 各版本区别 DVD Netinstall Everything Minimal GnomeLive KdeLive
  4. Basic:三层架构开发
  5. 同步Android与PC的时间
  6. php strstr 从尾部,PHP strstr() 和 strrchr() 详解
  7. php 小程序 活动弹幕,小程序:弹幕效果的消息提示
  8. 因为简单!我的第一本算法书,就被女友抢走了……
  9. 计算机应用基础实操题怎么操,计算机基础实操试题
  10. 2012年7月份第1周51Aspx源码发布详情
  11. Android, App常用图标尺寸规范
  12. 北航计算机专硕考研大纲,2017年北京航空航天大学609数学专业基础硕士研究生考试大纲...
  13. npm的package.json和package-lock.json更新策略
  14. 女生学大数据好就业吗?前景如何?
  15. [USACO Hol10] 政党
  16. 3d Max安装失败(Microsoft Visual C++ 2010 SP1 Redistributable (x86) Failed...
  17. 字符串正则替换、点替换横杠
  18. python 小说下载工具_python 制作网站小说下载器
  19. 国产计算机硬件发展史,计算机基础-计算机硬件发展史以及硬件
  20. Discuz被挂马的处理经验,Dz为什么会被挂马

热门文章

  1. struts2框架之国际化(参考第二天学习笔记)
  2. Windows下基于python3使用word2vec训练中文维基百科语料(一)
  3. Fiddler抓包使用教程-会话图标
  4. sql对应C#的类型
  5. SharePoint 2007 SDK v1.5
  6. sql大于某个时间_学习SQL-复杂查询
  7. vue 循环 递归组件_全局组件实现递归树,避免循环引用
  8. 地域和地方的区别_商标、品牌、LOGO,三者区别在哪里?
  9. java 不知道类名_Java 中获取类名的三种方法,你知道几种?
  10. 3d旋转相册代码源码_实现可旋转的Reflection Probe(原创)