lisp
xiangjie256
这个作者很懒,什么都没留下…
展开
-
list
[code="lisp"]> (define x (list 1 2 3))> x'(1 2 3)> (define y (list 4 5 6))> (append x y)'(1 2 3 4 5 6)> (cons x y)'((1 2 3) 4 5 6)> (list x y)'((1 2 3) (4 5 6))> (reverse x)'(3...原创 2013-11-06 22:04:01 · 82 阅读 · 0 评论 -
scheme lisp
(define a 3)> a3> (define radius 10)> (*a radius). . ..\..\Program Files\Racket\collects\racket\private\more-scheme.rkt:263:2: *a: undefined; cannot reference an identifier before its def...原创 2013-10-09 21:23:03 · 152 阅读 · 0 评论 -
scheme基本元素
[code="lisp"](define a 1)(define b 2)(+ a b 3)(- a b 3)(* a b 3)(/ a b 3)[/code]居然能显示1/6,是竖直的哦[img]http://dl2.iteye.com/upload/attachment/0089/9910/c3d1e12a-9e27-32b7-b298-7a2d5d...原创 2013-10-09 21:30:52 · 225 阅读 · 0 评论 -
cond与if
[code="lisp"](define (f x) (cond ((>= x 0) (- x))) (cond ((< x 0) x)) )(define (f1 x) (if (< x 0) (- x) x))> (f -1)-1> (f1 -1)1> [/code]cond相当于c,c++中...原创 2013-10-10 21:51:10 · 400 阅读 · 0 评论 -
and or not
[code="lisp"]> (or (> 1 0) (< 1 0))#t> (and (> 1 0) (< 1 0))#f> (not (> 1 0))#f[/code]原创 2013-10-13 09:51:55 · 82 阅读 · 0 评论 -
递归(fab)
[code="lisp"](define (fab n) (if (= n 1) 1 (* n (fab (- n 1)))))> (fab 3)6[/code]一个递归,用到的括号真多啊原创 2013-10-16 22:15:39 · 254 阅读 · 0 评论 -
求 余
[code="lisp"]> (remainder 21 3)0> (remainder 21 2)1[/code]最大公约数[code="lisp"]> (define (gcd a b) (if (= b 0) a (gcd b (remainder a b...原创 2013-10-22 21:09:24 · 89 阅读 · 0 评论