SlideShare a Scribd company logo
1 of 14
Download to read offline
Proof and Emacs 
@dico leque 
2014/09/06 
於Proof Summit 2014 
1 / 14
自己紹介 
▶ Twitter: @dico leque 
▶ そこらへんにいるプログラマ 
▶ お仕事では最近はJava, Objective-C, Haskell, ... 
▶ Coq をちょっと触ったことがある程度 
▶ エディタはEmacs の中でvi をエミュレーションする系 
2 / 14
今回のお話 
▶ 証明されたEmacs Lisp プログラムが欲しい 
▶ Coq to Scheme を改造すれば簡単にできそう? 
▶ Coq to Clojure: 
▶ Coq 8.2 用に作ったことがある 
http://patch-tag.com/r/leque/coq-clojure-ext/home 
▶ 最新版のCoq ではhttps://github.com/clarus/coq 
3 / 14
方針 
▶ Scheme としてもEmacs Lisp としても実行できるようにし 
たい 
▶ Coq のソースコードはできるかぎり触らない 
▶ あわよくば他のLisp 方言にも対応したい 
4 / 14
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
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
Scheme とEmacs Lisp の違い 
▶ Lisp-1 vs. Lisp-2 
▶ Lexical scope vs. Dynamic scope 
▶ シンボルの意味 
▶ (quasiquote の扱い) 
▶ どちらもMaclisp の子孫なので言うほどの違いではない 
7 / 14
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
Lexical scope vs. Dynamic scope 
▶ Emacs Lisp はDynamic scope 
▶ 1980 年代では多数派の判断 
▶ ;; -*- lexical-binding: t -*- 
と書けばlexical scope になる(Emacs 24~) 
▶ トップレベル変数は依然としてdynamic scope (スペシャル 
変数) 
▶ internal-make-var-non-special というundocumented な 
関数を使って変数をnon-special (= lexical) にした 
9 / 14
シンボルの意味 
▶ Scheme のシンボルはただの記号 
▶ Emacs Lisp (伝統的なLisp)のシンボルはパッケージ情報や 
属性リストを持っていたりしてよりリッチ 
▶ Emacs Lisp では問題にならないが代わりにキーワードを使う 
ことにしておく 
▶ キーワードは名前の前に: をつける 
▶ Scheme では:S は依然としてただのシンボル 
10 / 14
quasiquote の扱い 
▶ quasiquote の構文は方言によって異なる 
e.g. Clojure(Script), Wisp 
▶ 帰納型の値S n のextract 結果を`(S ,n) と書くのに使っ 
ている 
▶ 単純に(list ':S n) とする 
▶ Emacs Lisp Extcation には必要なかった 
11 / 14
補助関数・マクロ 
▶ Coq to Scheme と同じく、Coq とEmacs Lisp のギャップは 
Emacs Lisp 側のライブラリで吸収する 
▶ だいたい50 行くらいのライブラリ 
▶ define → defvar + internal-make-var-non-special 
▶ @ → funcall の入れ子 
▶ lambdas → lambda の入れ子 
▶ delay, force → 自前でpromise を実装する 
▶ letrec → let + setq. 
See R7RS 7.3. Derived expression types 
▶ match → 適当なマクロを書く 
12 / 14
おまけ: Coq to Common Lisp 
▶ 補助ライブラリを書けばCoq to Emacs Lisp でextract した 
ものはCommon Lisp としても実行できる 
▶ Common Lisp は基本lexical scope 
▶ 問題になりそうな部分はCoq to Emacs Lisp の方で既に潰し 
てある 
▶ トップレベル変数をlexical scope にするのは 
define-symbol-macro を使う方法がよく知られている 
▶ こちらも関数とマクロを合わせてだいたい50 行くらい 
13 / 14
まとめ 
▶ Coq to Scheme をちょっと改造したらCoq to Scheme / 
Emacs Lisp / Common Lisp ができた 
▶ https://github.com/leque/coq/tree/lisp-extraction 
▶ https://github.com/leque/coq-to-lisp/ 
▶ S 式の力! 
▶ Coq to Vim script は誰かにお任せします…… 
14 / 14

More Related Content

What's hot

C++ lecture-2
C++ lecture-2C++ lecture-2
C++ lecture-2sunaemon
 
20130215 fluentd esper_2
20130215 fluentd esper_220130215 fluentd esper_2
20130215 fluentd esper_2Ogibayashi
 
Erlangやってみた
ErlangやってみたErlangやってみた
Erlangやってみたina job
 
Tokyo.R 白熱教室「これからのRcppの話をしよう」
Tokyo.R 白熱教室「これからのRcppの話をしよう」Tokyo.R 白熱教室「これからのRcppの話をしよう」
Tokyo.R 白熱教室「これからのRcppの話をしよう」Nagi Teramo
 
Elixir macro-in-action-1
Elixir macro-in-action-1Elixir macro-in-action-1
Elixir macro-in-action-1k1complete
 

What's hot (7)

C++ lecture-2
C++ lecture-2C++ lecture-2
C++ lecture-2
 
20130215 fluentd esper_2
20130215 fluentd esper_220130215 fluentd esper_2
20130215 fluentd esper_2
 
Erlangやってみた
ErlangやってみたErlangやってみた
Erlangやってみた
 
Haxeについて
HaxeについてHaxeについて
Haxeについて
 
Tokyo.R 白熱教室「これからのRcppの話をしよう」
Tokyo.R 白熱教室「これからのRcppの話をしよう」Tokyo.R 白熱教室「これからのRcppの話をしよう」
Tokyo.R 白熱教室「これからのRcppの話をしよう」
 
Perl motion
Perl motionPerl motion
Perl motion
 
Elixir macro-in-action-1
Elixir macro-in-action-1Elixir macro-in-action-1
Elixir macro-in-action-1
 

Viewers also liked

Gold investment types introduction
Gold investment types introductionGold investment types introduction
Gold investment types introductionFuqiang Wang
 
Scala funbyexample
Scala funbyexampleScala funbyexample
Scala funbyexampleFuqiang Wang
 
挖财的互联网金融技术实践与探索@upyun opentalk
挖财的互联网金融技术实践与探索@upyun opentalk挖财的互联网金融技术实践与探索@upyun opentalk
挖财的互联网金融技术实践与探索@upyun opentalkFuqiang Wang
 
モナドをつくろう
モナドをつくろうモナドをつくろう
モナドをつくろうdico_leque
 
Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Fuqiang Wang
 
Architecture patterns and practices
Architecture patterns and practicesArchitecture patterns and practices
Architecture patterns and practicesFuqiang Wang
 
Scala the-good-parts
Scala the-good-partsScala the-good-parts
Scala the-good-partsFuqiang Wang
 
More Than Java Concurrency
More Than Java ConcurrencyMore Than Java Concurrency
More Than Java ConcurrencyFuqiang Wang
 
Zookeeper In Simple Words
Zookeeper In Simple WordsZookeeper In Simple Words
Zookeeper In Simple WordsFuqiang Wang
 
Uncertainty Awareness in Integrating Machine Learning and Game Theory
Uncertainty Awareness in Integrating Machine Learning and Game TheoryUncertainty Awareness in Integrating Machine Learning and Game Theory
Uncertainty Awareness in Integrating Machine Learning and Game TheoryRikiya Takahashi
 

Viewers also liked (12)

Gold investment types introduction
Gold investment types introductionGold investment types introduction
Gold investment types introduction
 
Kafka简介
Kafka简介Kafka简介
Kafka简介
 
Scala funbyexample
Scala funbyexampleScala funbyexample
Scala funbyexample
 
挖财的互联网金融技术实践与探索@upyun opentalk
挖财的互联网金融技术实践与探索@upyun opentalk挖财的互联网金融技术实践与探索@upyun opentalk
挖财的互联网金融技术实践与探索@upyun opentalk
 
モナドをつくろう
モナドをつくろうモナドをつくろう
モナドをつくろう
 
Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Continuations in scala (incomplete version)
Continuations in scala (incomplete version)
 
Architecture patterns and practices
Architecture patterns and practicesArchitecture patterns and practices
Architecture patterns and practices
 
SBT Made Simple
SBT Made SimpleSBT Made Simple
SBT Made Simple
 
Scala the-good-parts
Scala the-good-partsScala the-good-parts
Scala the-good-parts
 
More Than Java Concurrency
More Than Java ConcurrencyMore Than Java Concurrency
More Than Java Concurrency
 
Zookeeper In Simple Words
Zookeeper In Simple WordsZookeeper In Simple Words
Zookeeper In Simple Words
 
Uncertainty Awareness in Integrating Machine Learning and Game Theory
Uncertainty Awareness in Integrating Machine Learning and Game TheoryUncertainty Awareness in Integrating Machine Learning and Game Theory
Uncertainty Awareness in Integrating Machine Learning and Game Theory
 

Similar to Proof and Emacs

Uk ar
Uk arUk ar
Uk aruk-ar
 
括弧への異常な愛情 または私は如何にして心配するのを止めてCommon Lispを愛するようになったか
括弧への異常な愛情 または私は如何にして心配するのを止めてCommon Lispを愛するようになったか括弧への異常な愛情 または私は如何にして心配するのを止めてCommon Lispを愛するようになったか
括弧への異常な愛情 または私は如何にして心配するのを止めてCommon Lispを愛するようになったかm2ym
 
Lisp Tutorial for Pythonista Day 6
Lisp Tutorial for Pythonista Day 6Lisp Tutorial for Pythonista Day 6
Lisp Tutorial for Pythonista Day 6Ransui Iso
 
Beginners Scala in FAN 20121009
Beginners Scala in FAN 20121009Beginners Scala in FAN 20121009
Beginners Scala in FAN 20121009Taisuke Shiratori
 
ES6,7で書ける JavaScript
ES6,7で書ける JavaScriptES6,7で書ける JavaScript
ES6,7で書ける JavaScriptShin Sekaryo
 
From Java To Clojure
From Java To ClojureFrom Java To Clojure
From Java To ClojureKent Ohashi
 
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8y_taka_23
 
20110820 metaprogramming
20110820 metaprogramming20110820 metaprogramming
20110820 metaprogrammingMasanori Kado
 
rpscala35-scala2.9.0
rpscala35-scala2.9.0rpscala35-scala2.9.0
rpscala35-scala2.9.0Kenji Yoshida
 
第1回勉強会スライド
第1回勉強会スライド第1回勉強会スライド
第1回勉強会スライドkoturn 0;
 
Lisp tutorial for Pythonista : Day 1
Lisp tutorial for Pythonista : Day 1Lisp tutorial for Pythonista : Day 1
Lisp tutorial for Pythonista : Day 1Ransui Iso
 
TypeScript 言語処理系ことはじめ
TypeScript 言語処理系ことはじめTypeScript 言語処理系ことはじめ
TypeScript 言語処理系ことはじめYu Nobuoka
 
Javaで簡単にgpgpu aparapi
Javaで簡単にgpgpu aparapiJavaで簡単にgpgpu aparapi
Javaで簡単にgpgpu aparapiKen'ichi Sakiyama
 

Similar to Proof and Emacs (20)

Uk ar
Uk arUk ar
Uk ar
 
括弧への異常な愛情 または私は如何にして心配するのを止めてCommon Lispを愛するようになったか
括弧への異常な愛情 または私は如何にして心配するのを止めてCommon Lispを愛するようになったか括弧への異常な愛情 または私は如何にして心配するのを止めてCommon Lispを愛するようになったか
括弧への異常な愛情 または私は如何にして心配するのを止めてCommon Lispを愛するようになったか
 
Lisp Tutorial for Pythonista Day 6
Lisp Tutorial for Pythonista Day 6Lisp Tutorial for Pythonista Day 6
Lisp Tutorial for Pythonista Day 6
 
Beginners Scala in FAN 20121009
Beginners Scala in FAN 20121009Beginners Scala in FAN 20121009
Beginners Scala in FAN 20121009
 
MoteMote Compiler Plugin
MoteMote Compiler PluginMoteMote Compiler Plugin
MoteMote Compiler Plugin
 
ES6,7で書ける JavaScript
ES6,7で書ける JavaScriptES6,7で書ける JavaScript
ES6,7で書ける JavaScript
 
From Java To Clojure
From Java To ClojureFrom Java To Clojure
From Java To Clojure
 
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
 
20110820 metaprogramming
20110820 metaprogramming20110820 metaprogramming
20110820 metaprogramming
 
Hokuriku Scala 1
Hokuriku Scala 1Hokuriku Scala 1
Hokuriku Scala 1
 
rpscala35-scala2.9.0
rpscala35-scala2.9.0rpscala35-scala2.9.0
rpscala35-scala2.9.0
 
ATN No.2 Scala事始め
ATN No.2 Scala事始めATN No.2 Scala事始め
ATN No.2 Scala事始め
 
PFI Seminar 2010/02/18
PFI Seminar 2010/02/18PFI Seminar 2010/02/18
PFI Seminar 2010/02/18
 
第1回勉強会スライド
第1回勉強会スライド第1回勉強会スライド
第1回勉強会スライド
 
Scheme to x86コンパイラ
Scheme to x86コンパイラScheme to x86コンパイラ
Scheme to x86コンパイラ
 
Lisp tutorial for Pythonista : Day 1
Lisp tutorial for Pythonista : Day 1Lisp tutorial for Pythonista : Day 1
Lisp tutorial for Pythonista : Day 1
 
TypeScript 言語処理系ことはじめ
TypeScript 言語処理系ことはじめTypeScript 言語処理系ことはじめ
TypeScript 言語処理系ことはじめ
 
Rake
RakeRake
Rake
 
Javaで簡単にgpgpu aparapi
Javaで簡単にgpgpu aparapiJavaで簡単にgpgpu aparapi
Javaで簡単にgpgpu aparapi
 
d-kami x86-1
d-kami x86-1d-kami x86-1
d-kami x86-1
 

Recently uploaded

論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 

Recently uploaded (9)

論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 

Proof and Emacs

  • 1. Proof and Emacs @dico leque 2014/09/06 於Proof Summit 2014 1 / 14
  • 2. 自己紹介 ▶ Twitter: @dico leque ▶ そこらへんにいるプログラマ ▶ お仕事では最近はJava, Objective-C, Haskell, ... ▶ Coq をちょっと触ったことがある程度 ▶ エディタはEmacs の中でvi をエミュレーションする系 2 / 14
  • 3. 今回のお話 ▶ 証明されたEmacs Lisp プログラムが欲しい ▶ Coq to Scheme を改造すれば簡単にできそう? ▶ Coq to Clojure: ▶ Coq 8.2 用に作ったことがある http://patch-tag.com/r/leque/coq-clojure-ext/home ▶ 最新版のCoq ではhttps://github.com/clarus/coq 3 / 14
  • 4. 方針 ▶ Scheme としてもEmacs Lisp としても実行できるようにし たい ▶ Coq のソースコードはできるかぎり触らない ▶ あわよくば他のLisp 方言にも対応したい 4 / 14
  • 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
  • 7. Scheme とEmacs Lisp の違い ▶ Lisp-1 vs. Lisp-2 ▶ Lexical scope vs. Dynamic scope ▶ シンボルの意味 ▶ (quasiquote の扱い) ▶ どちらもMaclisp の子孫なので言うほどの違いではない 7 / 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
  • 9. Lexical scope vs. Dynamic scope ▶ Emacs Lisp はDynamic scope ▶ 1980 年代では多数派の判断 ▶ ;; -*- lexical-binding: t -*- と書けばlexical scope になる(Emacs 24~) ▶ トップレベル変数は依然としてdynamic scope (スペシャル 変数) ▶ internal-make-var-non-special というundocumented な 関数を使って変数をnon-special (= lexical) にした 9 / 14
  • 10. シンボルの意味 ▶ Scheme のシンボルはただの記号 ▶ Emacs Lisp (伝統的なLisp)のシンボルはパッケージ情報や 属性リストを持っていたりしてよりリッチ ▶ Emacs Lisp では問題にならないが代わりにキーワードを使う ことにしておく ▶ キーワードは名前の前に: をつける ▶ Scheme では:S は依然としてただのシンボル 10 / 14
  • 11. quasiquote の扱い ▶ quasiquote の構文は方言によって異なる e.g. Clojure(Script), Wisp ▶ 帰納型の値S n のextract 結果を`(S ,n) と書くのに使っ ている ▶ 単純に(list ':S n) とする ▶ Emacs Lisp Extcation には必要なかった 11 / 14
  • 12. 補助関数・マクロ ▶ Coq to Scheme と同じく、Coq とEmacs Lisp のギャップは Emacs Lisp 側のライブラリで吸収する ▶ だいたい50 行くらいのライブラリ ▶ define → defvar + internal-make-var-non-special ▶ @ → funcall の入れ子 ▶ lambdas → lambda の入れ子 ▶ delay, force → 自前でpromise を実装する ▶ letrec → let + setq. See R7RS 7.3. Derived expression types ▶ match → 適当なマクロを書く 12 / 14
  • 13. おまけ: Coq to Common Lisp ▶ 補助ライブラリを書けばCoq to Emacs Lisp でextract した ものはCommon Lisp としても実行できる ▶ Common Lisp は基本lexical scope ▶ 問題になりそうな部分はCoq to Emacs Lisp の方で既に潰し てある ▶ トップレベル変数をlexical scope にするのは define-symbol-macro を使う方法がよく知られている ▶ こちらも関数とマクロを合わせてだいたい50 行くらい 13 / 14
  • 14. まとめ ▶ Coq to Scheme をちょっと改造したらCoq to Scheme / Emacs Lisp / Common Lisp ができた ▶ https://github.com/leque/coq/tree/lisp-extraction ▶ https://github.com/leque/coq-to-lisp/ ▶ S 式の力! ▶ Coq to Vim script は誰かにお任せします…… 14 / 14