2011-04-08
ローカル関数 flet と labels
xyzzy |
いわゆる、(defun ... の中だけで生きる関数なんだが、
flet と labels のどちらでも定義できる。が、微妙に振る舞いが違う。
| flet | let みたいに並列に定義する |
|---|---|
| labels | let* みたいに直列に定義する |
xyzzy で試してみた。
;; flet の場合 (defun test (a) (flet ((f1 (x) (+ x 1)) ; f1 と f2 は同時に定義されるので (f2 (y) (+ (f1 y) 10))) ; f2 を定義する時点で f1 は未定義 (f2 a))) ;; test (test 5) 関数が定義されていません: f1 ; エラる ;; labels の場合 (defun test (a) (labels ((f1 (x) (+ x 1)) ; f1 --> f2 の順に定義されるので (f2 (y) (+ (f1 y) 10))) ; f2 を定義する時点では、すでに f1 が定義済み (f2 a))) ;; test (test 5) 16 ; 実行できる
じゃあ、なんで labels は flet* じゃないのか。他に違いがあるんだろうか。なぞだ。
参考URL:
コメントを書く
トラックバック - http://d.hatena.ne.jp/gnrr/20110408/1302279922
リンク元
- 7 http://practical-scheme.net/wiliki/rssmix.cgi
- 1 http://d.hatena.ne.jp/
- 1 http://k.hatena.ne.jp/keywordblog/xyzzy
- 1 http://pipes.yahoo.com/pipes/pipe.info?_id=cd1c8b53a467958b474019a814a6496f
- 1 http://reader.livedoor.com/reader/
- 1 http://reader.www.infoseek.co.jp/reader/display.html?cid=85049&sid=0
- 1 http://search.minakoe.jp/rsss/rsss.asp?pid=229531&plp=0&pd=2008/09/29&lid=229176&nlp=0&sd=2008/09/29&base=20&bd=2008/09/29&multi=1&qry=domain:hatena
- 1 http://translate.googleusercontent.com/translate_c?hl=pt-BR&sl=ja&u=http://search.minakoe.jp/rsss/rsss.asp?qry=domain:hatena&multi=1&prev=/search?q=%E3%83%AB%E3%83%9E%E3%83%8B%E3%82%A2%E3%81%AE%E4%BA%BA%E3
- 1 http://www.google.co.jp/search?q="パス区切りが円記号"&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja-JP-mac:official&hl=ja&client=firefox-a
- 1 http://www.google.com/reader/igoogle-module?up_displayStreamId=user/07207573480185828061/label/blog&up_itemCount=5&up_ranking=d&up_readItemsVisible=0&up_linkTarget=new&lang=en&country=us&.lang=en&.country=us&synd=ig&mid=106&ifpctok=-2283141079762566485&ex
