プログラム断片(2008/06/08)

for VisualWorks 7.6 with Jun780, Lispインタプリタのマニュアル(PDF)

Lispインタプリタを開く

JunLispInterpreter open
01 Lispインタプリタのマニュアル(PDF)

引用

a
'a
(quote a)
123
'123
(quote 123)
nil
'nil
(quote nil)
(1 2 3)
'(1 2 3)
(quote (1 2 3))
(a b c)
'(a b c)
(quote (a b c))
02
> a
*** Error: a is unbound atom
nil
> 'a
a
> (quote a)
a
> 123
123
> '123
123
> (quote 123)
123
> nil
nil
> 'nil
nil
> (quote nil)
nil
> (1 2 3)
*** Error: null function 1
nil
> '(1 2 3)
(1 2 3)
> (quote (1 2 3))
(1 2 3)
> (a b c)
*** Error: undefined function a
nil
> '(a b c)
(a b c)
> (quote (a b c))
(a b c)

関数

((lambda (x y) (+ x y)) 3 4)

(+ 3 4)
03
> ((lambda (x y) (+ x y)) 3 4)
7
> (+ 3 4)
7

ラムダ記法

((lambda (x y) (+ x y)) 3 4)

((lambda (x y) (- x y)) 3 4)

((lambda (x y) (* x y)) 3 4)

((lambda (x y) (/ x y)) 3 4)
04
> ((lambda (x y) (+ x y)) 3 4)
7
> ((lambda (x y) (- x y)) 3 4)
-1
> ((lambda (x y) (* x y)) 3 4)
12
> ((lambda (x y) (/ x y)) 3 4)
(3/4)

ラベル記法

(defun plus . (lambda (x y) (+ x y)))
(plus 3 4)

(defun plus lambda (x y) (+ x y))
(plus 3 4)

(defun plus (x y) (+ x y))
(plus 3 4)
05
> (defun plus . (lambda (x y) (+ x y)))
plus
> (plus 3 4)
7
> (defun plus lambda (x y) (+ x y))
plus
> (plus 3 4)
7
> (defun plus (x y) (+ x y))
plus
> (plus 3 4)
7

for VisualWorks 7.6 with Jun780, Lispインタプリタのマニュアル(PDF)


Updated: 2015/11/08 (Created: 2008/06/08) KSU AokiHanko