LISP语言分析.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
LISP语言分析

* * * * * * * * * * (setq R (Rule4 (if (animal flies) (animal lays eggs)) (then (animal is bird)) ) ) 练习: 用second、third 、rest 等求结论。 (setq c (second (third R) ) ) (setq R (Rule4 (if (animal flies) (animal lays eggs)) (then (animal is bird)) ) ) 练习: 用second、third 、rest 等求结论。 (setq c (second (third R) ) ) 5、逻辑函数(1) (atom ‘(a b c)) nil (atom (third ‘(a b c))) t (null ‘( a b c ) ) nil (null ‘( ) ) t 5、逻辑函数(2) (equal ?(a b c) ?(a b c) ) t (equal ( ) nil ) t (equal ?(a b c) ?(a (b c)) ) nil 5、逻辑函数(3) (and (atom ?( )) (null (cdr ? (a)) ) ) ) t (or (listp ?( )) nil ) t (not (equal ( ) nil ) ) nil 6、条件函数(3) (cond (exp11 exp12 … ) (exp21 exp22 … ) (expn1 expn2 … ) ) (cond ((equal answer y) 1) ((equal answer n) -1) (t (print “Enter y or n) (ask query)) ) 7、定义函数的函数 例:定义一个求表的第二个元素的函数 (defun second ( l ) (cond ((atom l) nil) (t (cadr l)))) (second ( A (B C) D)) (B C) 例:定义前述取规则前提函数 (defun get_if (Rule) (cdadr Rule) ) 递归 例:求mn m0=1 mn=m×mn-1 (n>0) ? (defun power_1 (m n) (cond ((= n 0) 1) (t (* m (power_1 m (- n 1)) ) ) ) ) ? 调用函数的函数:funcall (funcall ‘函数名 参数1 …… 参数n ) ? 例: (funcall + 2 3) 5 (funcall append (a b) ( ) ( c ) ) ) (a b c) * * * * * * * * * * * * * * * * * * * * * AI 1、函数型语言 程序:函数集 没有 “主函数”、 各函数可独立运行 函数:由其它函数构成(无语句概念)

文档评论(0)

yaocen + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档