On Lisp メモ

関数の定義

Lisp

(defun double (x) (* x 2))

Ruby

def double (x) x * 2 end

Lisp

(lambda (x) (* x 2))

Ruby

lambda{|x| x * 2}

Lisp

> (setq double 2)
2
> (double double)
4

Ruby

> double = 2
=> 2
> double double
=> 4

Lisp

> (mapcar #'(lambda (x) (+ x 10))
          '(1 2 3))
(11 12 13)

Ruby

>[1,2,3].map{|x| x + 10}
=> [11, 12, 13]

Lisp

> (mapcar #'+
          '(1 2 3)
          '(10 100 1000))
(11 102 1003)

Ruby

> Vector[1,2,3] + Vector[10,100,1000]
=> Vector[11, 102, 1003]