next up previous
Next: 10.2 if文 Up: 10 リード,コンパイル,実行ループの実装 Previous: 10 リード,コンパイル,実行ループの実装

10.1 変数・関数定義


<cl> (scheme)

=> 1
1
=> (car '(a b))
A
=> (+ 1 2)
3
=> (define a 10)
A
=> a
10
=> (define (test a) (list a a))
TEST
=> (test 1)
(1 1)
=> (define (test1 a)
      (let ((b 2))
         (let ((c 3))
             (list a b c))))
TEST1
=> (test1 1)
(1 2 3)

=> (define (test a) (test1 a))
TEST
=> (define (test1 b) (list a b))
TEST1
=> (test 1)
("unbound" 1)
=> q
"unbound"
=> a
"unbound"

=> (define (fact n)
      (if (< n 1) 1 (* n (fact (- n 1)))))
FACT
=> (fact 8)
120
=> (fact 8)
40320
上のtest1の中には,変数aがあるが この変数は,testを実行する場合に testの引数のaになることはなく, あくまでも大域変数のaをさしている ことがわかります.

generated through LaTeX2HTML. M.Inaba 平成18年5月6日