5. Coq to Scheme
Require Import List .
Fixpoint mapcar {A B} (f: A -> B) (xs: list A): list B :=
match xs with
| nil => nil
| x :: xs ' => f x :: mapcar f xs '
end.
Extraction Language Scheme .
Extraction " test " mapcar .
↓
( define mapcar ( lambdas (f xs)
( match xs
(( Nil) `(Nil ))
(( Cons x xs ~)
`( Cons ,(f x) ,(@ mapcar f xs ~))))))
5 / 14
6. Coq to Emacs Lisp
Require Import List .
Fixpoint mapcar {A B} (f: A -> B) (xs: list A): list B :=
match xs with
| nil => nil
| x :: xs ' => f x :: mapcar f xs '
end.
Extraction Language Scheme .
Extraction " test " mapcar .
↓
;; -*- lexical-binding: t -*-
( define mapcar ( lambdas (f xs)
( match xs
((:Nil) (list ':Nil ))
((:Cons x xs ~)
(list ':Cons (@ f x) (@ mapcar f xs ~))))))
6 / 14
8. Lisp-1 vs. Lisp-2
▶ Scheme は関数と変数の名前空間が同じ
▶ Emacs Lisp は関数と変数の名前空間が別
▶ (defun f (x y) ...) で関数を定義
▶ (defvar g (lambda (x y) ...)) で(関数)値を定義
▶ #'f で関数名から関数値を取り出す
▶ (f a b) で関数適用
▶ (funcall #'f a b) や(funcall g a b)
のようにfuncall を使って関数値#'f やg を適用する
▶ 面倒なのですべて値の世界(defvar + lambda)でやる
▶ 関数呼び出しを(@ fun a b) としていたのをfuncall の入
れ子に展開する
▶ 1 引数のときだけ特別に@ を使わず(fun c) としていたの
を(@ fun c) にするだけ
8 / 14