ANSI Common Lisp Learn
It has been a long time that I haven't dealt with my blog. On one hand I was preparing the exams.On the other hand I just learn more things and take some documents at local PC. As a result, I begin to learn Lisp as planned.
2.10 Variables
let ; define local variables
; x y are local variables
(let ((x 1) (y 2))
(+ x y)
)
; the function doesn't stop until you enter a number
(defun ask-number ()
(format t "Please enter a number. ")
(let ((val (read)))
(if (numberp val)
val
(ask-number)
)
)
)
defparameter ; define global variables
; to avoid the same with local variables, we use **
> (defparameter *glob* 99)
defconstant ; define constants
> (defconstant limit (+ *glob* 1))
boundp ; test whether a symbol is a global variable or constant
> (boundp '*glob*)
2.11 Assignment
setf ; assign global/local variables
(setf *glob* 98)
; if the first variable is a symbol but not a name of local variable, setf will set it as global variable
(let ((n 10))
(setf n 2)
n
)
setf can also:
(defparameter x (list 'a 'b 'c))
(setf (car x) 'n)
; x will be (N B C)
setf can also:
(setf a 'b c 'd e 'f)
2.12 Function Programming
Function Programming means using the return value and not changing original things. It allows interactive testing
; lst won't be changed
(setf lst '(c a r a t))
(remove 'a lst)
; x will be changed
(setf x (remove 'a x))
; so you'd better not use functions like setf
2.13 Iteration
do is the basic iterative symbol and it can create variables. The first actual variable is a format list of a group variables; each element in the list is (variable initial update)
The second actual variable contains one or more expressions.The first expression used to test whether the iteration reach end.The rest expressions will be calculated and the last expression's value will be returned
; iteration
(defun show-squares (start end)
(do ((i start (+ i 1))) ; counter
((> i end) 'done) ; done will be returned
(format t "~A ~A~%" i (* i i)) ; main iteration
)
)
; recursive
(defun show-squares (start end)
(if (> start end)
'done
(progn ; accept expressions and return the last value
(format t "~A ~A~%" start (* start start))
(show-squares (+ start 1) end)
)
)
)
; iterate in a list:
(defun our-length (lst)
(let ((len 0))
(dolist (obj lst)
(setf len (+ len 1))
)
len
)
)
; recursive version
(defun our-length (lst)
(if (null lst)
0
(+ (our-length (cdr lst)) 1)
)
)
; it is not tail-recursive
ANSI Common Lisp Learn的更多相关文章
- 简体中文 — ANSI Common Lisp 中文版
简体中文 - ANSI Common Lisp 中文版 简体中文¶
- ANSI Common Lisp 中文翻譯版 — ANSI Common Lisp 中文版
ANSI Common Lisp 中文翻譯版 — ANSI Common Lisp 中文版 ANSI Common Lisp 中文翻譯版¶
- ANSI Common Lisp Practice - My Answers - Chatper - 3
Ok, Go ahead. 1 (a) (b) (c) (d) 2 注:union 在 Common Lisp 中的作用就是求两个集合的并集.但是这有一个前提,即给的两个列表已经满足集合的属性了.具体 ...
- ANSI Common Lisp Practice - My Answers - Chatper - 2
I work out the questions by myself Chapter 2 question 4. (defun greater (x y) (if (> x y) x y ) ) ...
- MAC 下用 Common Lisp 调试 OpenGL 程序
MAC 下用 Common Lisp 调试 OpenGL 程序 环境搭建 运行环境: OSX 10.11.3 EI Capitan Common Lisp: SBCL 使用 SBCL, 首先要安装这几 ...
- 在windows上安装common lisp开发环境
(2014.1写于CSDN的文章) 最近对lisp非常感兴趣,因此在google中搜索了“common lisp install windows”, 想装一个开发环境玩玩. 第一条结果就是 “Gett ...
- Common Lisp学习资源整理
Lisp Hackers: Interviews with 100x More Productive Programmers Posted on June 26th, 2013 Lisp Hacker ...
- 一道Common Lisp 宏的练习题
这是<ANSI Common Lisp>第10章“宏”的习题第6题: 定义一个宏,接受一变量列表以及一个代码主体,并确保变量在代码主体被求值后恢复 (revert)到原本的数值
- 搭建fedora开发环境 common lisp, c++, go
第三方软件库: http://download1.rpmfusion.org/free/fedora/releases/25/Everything/x86_64/os/repoview/index.h ...
随机推荐
- 支持10种格式的 HTML 表格导出 jQuery 插件
HTML 表格导出 jQuery 插件可以帮助用户导出 HTML 表格到 JSON.XML.PNG.CSV.TXT.SQL.MS-Word.MS-Excel.MS-PowerPoint 和 PDF 格 ...
- Frameless - 用于预览 iOS8 原型的浏览器
Frameless 是一个用于在 iOS8 中预览产品原型的浏览器.可以可以帮助那些需要一个简单的方法来预览 iOS 设备上的原型设计和开发效果.没有状态栏,通过手势控制浏览器的历史以及键盘的显示. ...
- React入门--------顶层API
React.createClass 参数:config(object) 创建一个ReactClass(组件类),参数是一个对象且必须带有render属性方法,该方法必须返回一个封闭的容器(容器内可以由 ...
- scroll事件实现监控滚动条并分页显示示例(zepto.js)
scroll事件实现监控滚动条并分页显示示例(zepto.js ) 需求:在APP落地页上的底部位置显示此前其他用户的购买记录,要求此div盒子只显示3条半,但一页有10条,div内的滑动条滑到一页 ...
- 原生JS实现轮播+学前端的感受(防止走火入魔)
插件!插件!天天听到有人求这个插件,那个插件的,当然,用第三方插件可以大幅提高开发效率,但作为新手,我还是喜欢自己来实现,主要是我有时间! 今天我来给大家分享下用原生JS实现图片轮播的写法 前辈们可以 ...
- 创建SAP GUI快捷方式保存密码
1.在注册表中创建GUI 快捷方式的子键 a.首先运行 微软标识键+R b.窗口中输入sapshcut,如果有窗口跳出点击“确定” 2.维护子键下的键值 a.再次运行 微软标识键+R ...
- Swift安装
Server1 .Update sudo apt-get update sudo apt-get upgrade . sudo apt-get install bridge-utils .IP 3.1 ...
- java文件读写操作大全
转自:http://hi.baidu.com/0_net/blog/item/8566fc2bb730c293033bf63e.html一.获得控制台用户输入的信息 public String get ...
- Autodesk View and Data API练练手
大家如果参加过我们的活动,你应该已经听过看过不少关于View and Data Web Service的例子里,如果还没有的话,请看看下面这几篇: http://www.cnblogs.com/jun ...
- iOS使用Charles(青花瓷)抓包并篡改返回数据图文详解
写本文的契机主要是前段时间有次用青花瓷抓包有一步忘了,在网上查了半天也没找到写的完整的教程,于是待问题解决后抽时间截了图,自己写一遍封存在博客园中以便以后随时查阅. charles又名青花瓷,在iOS ...