next up previous
Next: 2 第一級身分 Up: 1 プログラムをデータとして扱う Previous: 1.1 引数としてわたす手続き

1.2 関数の戻り値として返す手続き

たとえば任意の関数を与えてその微分関数として 手続きを返すような場合も可能である.

(defun deriv (f dx)
  #'(lambda (x)
      (/ (- (funcall f (+ x dx)) (funcall f x))
	 dx)))

> (funcall (deriv 'cube 0.01) 5)
75.15106
> (funcall (deriv 'cube 0.001) 5)
75.15106
> (funcall (deriv 'cube 0.001) 5)
75.01221
> (* 3 (square 5))
75
> (funcall (deriv #'(lambda (x) (* 2 x)) 0.001) 5)
1.9998549
derivに任意の関数を与えるとその微分関数をもとめ, それに値を与えると微分値を得ることができる.

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