1.Scheme位移操作
<1>.8左移1位
(ash 8 1)<2>.8右移1位
(ash 8 -1)2.平方操作
<3>.2的4次方
(expt 2 4)3.打印
(print "Hello World")
1.hello world:(print "hello world")只需存为文本文件在终端使用clisp hello就行了...2.打印1+1...
(print (+ 1 1))3.将11左移一位
(print (ash 11 1))4.将11右移一位
(print (ash 11 -1))5.计算2的100次方
(print (expt 2 100))6.打印一句话:
(print "He yelled \"Stop that thief!\" from the busy street.")7.输出5个列表:
(print (cons 'chicken 'cat))
(print (cons 'chicken 'nil))
(print (cons 'chicken ()))
(print (cons 'pork '(beef chicken)))
(print (list 'a 'b 'c))
其中cons(list)表示建立列表函数 () 或者 'nil代表空8.输出列表首个元素:
(print (car '(pork beef chicken)))
(print (car '(beef chicken)))car表示提取列表首个元素...9.输出列表其他元素(除了首个):
(print (cdr '(abc balabala beef chicken)))10.列表中的列表:
(print '(cat (duck bat) ant))11.这个有点意思,有点分配律的味道...
(print (cdr (car '((peas carrots tomatoes) (pork beef chicken)))))
(print (cdar '((peas carrots tomatoes) (pork beef chicken))))大概是d或a都拉上一个c和r就行了...12.复杂点的组合:
(print(cadadr '((peas carrots tomatoes) (pork beef chicken) duck)))
(print (car (cdr (car (cdr'((peas carrots tomatoes) (pork beef chicken) duck))))))
想是好想,就是不好还原回来... 组合最多只能是4层,5层以上就不行了...13.if语句:
(print (if '(true)'i-am-true'i-am-false))(print (if '()'i-am-true'i-am-false))
列表为空时为假...14.定义并使用求长度的递归函数(好看吗?):
(defun my-length(list)(if list(1+ (my-length (cdr list)))0))
(print (my-length '(1 2 3 )))15.比较空值:
(print (eq '() nil))16.像样点的if:
(print (if (= (+ 1 2) 3)'yup'nope))
(print (if (= (+ 1 2 ) 4)   'yup'nope))
比较1+2和3是否相等...17.判断奇数:
(print  (if(oddp 5)'odd-number'even-number))
oddp 是判断奇数操作符18.使用变量:
(defvar *number* nil)
(print *number*)
(if (oddp 5)(progn (setf *number* t)'odd-number)'even-number)
(print *number*)defvar 定义变量number
progn 用于获取最后一个表达式的返回值
setf 用于设置变量的值19.when语句:
(defvar *number* nil)
(print *number*)
(when (oddp 5)(setf *number* t)'odd-number)
(print *number*)当条件成立时...20.unless语句
(defvar *number* nil)
(print *number*)
(unless (oddp 4)(setf *number* nil)'even-number)
(print *number*)21.if else语句:
(defvar *who* nil)
(defun whatshouldsay(person)(cond ((eq person 'alice) (setf *who* 'sweethert)'(Love you))((eq person 'bob) (setf *who* 'friend)'(Welcome))(t (setf *who* 'enemy)'(I hate you!))))(print (whatshouldsay 'alice))
(print *who*)(print (whatshouldsay '()))
(print *who*)(print (whatshouldsay 'BOB))
(print *who*)定义变量who和函数whatshouldsay,cond是条件语句,
最后一个t表示默认时候总会是enemy22.使用case语句重写:
(defvar *who* nil)
(defun whatshouldsay(person)(case person((alice) (setf *who* 'sweethert)'(Love you))((bob) (setf *who* 'friend)'(Welcome))(t (setf *who* 'enemy)'(I hate you!))))(print (whatshouldsay 'alice))
(print *who*)(print (whatshouldsay 'bad))
(print *who*)(print (whatshouldsay 'BOB))
(print *who*)23.逻辑与(或)运算符,有短路特性:
(print (and (oddp 5) (oddp 7) (oddp 9)))
(print (or (oddp 5) (oddp 2) (oddp (expt 2 1))))
(print (or (oddp 4) (oddp 2) (oddp (expt 2 1))))24.python中的in符号:
(print (if (member 1 '(3 4 1 5))'one-is-in-list'one-is-not-in-list ))
member相当于in但是:
(print (member 1 '(2 3 1 6 8)))
会返回(1 6 8)
因为'(2 3 1 6 8)
在构造时:
使用(cons 2 (cons 3 (cons 1 (cons 6 (cons 8 nil)))))
所以解析时返回最初发现的序列...25.find-if语句:
(print (find-if #'oddp '(2 4 5 6)))
发现就返回值26.比较运算符:
eq用于比较符号
equal用于比较常量
note:
eq can also be used to compare conses (the links created by the cons command). How-
ever, it returns true values only when a cons is compared directly to itself, created by the
same cons call. This means, two unrelated conses that “look” exactly the same can fail
an eq test. Since eq can check a cons cell only against itself, using eq with conses isn’t
really that useful for a beginner. However, an advanced Lisper may want to compare
conses with eq under certain circumstances.
如:
(print (eq '(2 3 1 6 8) (cons 2 (cons 3 (cons 1 (cons 6 (cons 8 nil)))))))
返回nil
而
(print (equal '(2 3 1 6 8) (cons 2 (cons 3 (cons 1 (cons 6 (cons 8 nil)))))))
返回Teql和eq类似,但是还能比较字符和数字equalp可以忽略整型实型大小写比较,如:
(print (equalp "Bob" "bob"))
(print (equalp "Bob" "bob"))
(print (equalp 0.0 0))
都返回T27.mapcar,类似python的map
The mapcar function is used frequently by Lispers. This function takes
another function and a list, and then applies this function to every member
of a list.(print (mapcar #'sqrt '(1 2 3 4 5)))
(print (mapcar #'oppd '(1 2 3 4 5)))
(print (mapcar #'car '((foo bar) (baz qux))))28.append函数,类似python的append:
(print (append '(I have) '(a ) '(book)))29.apply函数,类似python的apply:
(print (apply #'append '((she has) (a) (book))) )(print (apply #'append '((this is a list) (this is another list))))30.push函数:
(defparameter *foo* '(1 2 3))
(push 8 *foo*)定义一个list,将8加入list31.prin1函数(不会换行):
(prin1 "hello world!")32.let定义全局变量:
(let ((a 5)(b 6)(+ a b))33.输入函数read:
(defun hello()(print "Please input your name:")(let ((name (read)))(print "Hello")(print name)))
(hello)read以后保存在name中
(defun say-hello()(princ "Please input your name:")(let ((name (read-line)))(princ "Hi,")(princ name))
)
(say-hello)34.代码模式和数据模式:
'(+ 1 2) 是数据模式,仅表示字串
(+ 1 2) 是代码模式(defparameter *f* '(+ 1 2))
(eval *f*)
可以求出具体数值35.匿名函数:
(lambda (n) (/ n/2))

Scheme调试手册(四)相关推荐

  1. plc和pc串口通讯接线_Plc与pc串口调试手册

    Plc 与 pc 串口调试手册 硬件连接线 制作串口连接线, plc 管脚 23459 ,不可连接错误! ! pc 管脚 23875 , 串口模块 232 插在 1 号插槽,通信时 sw4 保持 of ...

  2. 西门子rwd60参数设置调试手册_西门子控制器RWD60

    RWD60西门子控制器可与西门子电动阀,西门子传感器等组合成西门子温控阀,是RWD62和RWD68控制器的简化版本,适用于换热器及其它输出0-10V的项目 RWD60西门子控制器 · 带 P 或 PI ...

  3. 802d简明调试手册_SINUMERIK-828D简明调试手册.pdf

    SINUMERIK 828D / 828D BASIC 简明调试手册 SINUMERIK Answers for industry. SIEMENS A B C 01.2012 A SINUMERIK ...

  4. 深信服服务器装系统,深信服新上网行为管理系统安装调试手册..doc

    深信服新上网行为管理系统安装调试手册. 新上网行为管理系统安装调试手册 系统平台: RedHat Linux Enterprise 4: 安装方式: 自定义安装: 安装前设置: 启用防火墙 允许ssh ...

  5. 深信服服务器装系统,深信服新上网行为管理系统安装调试手册[1].doc.docx

    新上网行为管理系统安装调试手册 系统平台: RedHat Linux Enterprise 4: 安装方式: 自定义安装: 安装前设置 : 启用防火墙(允许ssh服务和ftp服务) 软件包选择: 只勾 ...

  6. 西门子bop20显示电流_S120BOP20调试手册V1.3

    参数号 设定值 备注 F07815 功率单元更改 F01043 项目下载错误 F01042 参数下载错误 P10 2 修改功率单元 P201 5200 6SL3210-1SE11-3Uxx 0.37K ...

  7. 怎样修改日立uax规格表_UAX型电梯调试手册.pdf

    UAX型电梯调试手册 UAX 型 电 梯 调 试 手 册 5-16 磁极传感器设置调整 UA 电梯必需进行磁极传感器的微调整,可利用马达电流的最小值进行调整,也可利用 磁极传感器补偿自动调整.两者中必 ...

  8. 基于GPS的公交车站点播报调试第四天

    基于GPS的公交车站点播报 任务书 本设计的主控芯片单片机为基础,利用GPS获取比较精确的公交位置信息:并由AT89C51进行智能整合处理信息,发送控制指令:利用ISD1700系统语音芯片实现语音播报 ...

  9. 公交语音播报调试第四天

    任务书 公交报站器由控制模块STC89C52单片机作为控制核心,硬件电路分为12864液晶屏.ISD1730语音芯片.温湿度传感器和红外传感器等模块.该系统的功能是:首先可以通过八个按键实现" ...

最新文章

  1. 风格化手绘纹理包 CGTrader – Stylized Mix Vol. 41 – Hand Painted Texture Pack
  2. Istio如何使用相同的端口访问网格外服务
  3. C++ 类访问控制(public/protected/private)小结
  4. 111 第一章操作系统概述总结思维导图+错题整理
  5. boost的chrono模块等待按键的测试程序
  6. 感觉要火!妹子实地采访网易猪厂程序员七夕怎么过
  7. 该Tiled地图制作拿到项目~~这是偷懒,为了直接复制后写来
  8. 【树莓派学习笔记】六、启用摄像头、实时视频、录像和截图
  9. k8s pod里访问不到外部ip_K8S容器网络如何实现通信?
  10. EasyRecovery如何恢复系统镜像
  11. FLask框架AJAX操作
  12. 科普数据迁移技术和方法论
  13. pip安装pytorch清华_镜像安装pytorch的简便方法总结
  14. stc单片机c语言程序头文件(stc12c5a60s2.h,stc12c5a60s2头文件在keil中没法用?
  15. 常见电路面试题20道
  16. java-opencv拍照(可自定义分辨率)
  17. 用matlab画黑底白条,计算机仿真F型结构电能表自动检测流水线_论文答辩PPT范例...
  18. 使用2节点梁或梁/杆单元分析弹塑性梁或框架(python,有限元)
  19. Jackson - 将 JSON字符串转换为 List
  20. 如何学好高中数学函数之秒解函数性质问题(颠覆性思维)

热门文章

  1. windows上编译和安装hadoop2 (一)
  2. 寒门难再出贵子(6),一篇值得思考的文章
  3. MYSQL 远程访问被限制
  4. 针对 Java 开发人员的 C# 编程语言
  5. Arduino 硬件开发 教程收集
  6. mysql 怎么改属性_mysql怎么修改字段的属性
  7. 椭圆极点极线性质_圆锥曲线(18)———圆锥曲线题目背后的性质总结(1)
  8. 固定字符结尾的正则_新手上路:图文解读助你理解和使用正则表达式
  9. 连续arq协议的利用率_Chrome底层原理和HTTP协议 - 石吴玉
  10. 20世纪50年代电子计算机的功能元件,第1章 计算机基础知识习题答案