lambda-listのキーワードで別名をつける

2 views
Skip to first unread message

Ryohei Ueda

unread,
Dec 11, 2010, 11:33:11 AM12/11/10
to clap-...@googlegroups.com
garaemonです

(hoge :key1 1)と(hoge :key2 1)を同じ振る舞いにしたいと思っているのですが,
lambda-listでかっこいい書き方ってあるのでしょうか?

おもいつくのは
(defun hoge (&key (key1 nil key1-p) (key2 nil key2-p))
(cond (key1-p key1) (key2-p key2) (t key1)))
みたいにすることですが, もっと良い方法はあるのでしょうか?

-- ryohei

Shiro Kawai

unread,
Dec 11, 2010, 3:36:49 PM12/11/10
to clap-...@googlegroups.com
「key1もkey2も与えられなかった場合」を区別しないので良いなら、

(defun hoge (&key (key1 'default) (key2 key1))
key2)

というのも。

2010/12/11 Ryohei Ueda <gara...@gmail.com>:

Ryohei Ueda

unread,
Dec 12, 2010, 12:21:08 PM12/12/10
to clap-...@googlegroups.com
garaemonです

> (defun hoge (&key (key1 'default) (key2 key1))
> key2)

ああ, なるほど, lambda-listはlet*的な束縛がされるからそれがスマートですね

ありがとうございmす

-- ryohei

2010/12/12 Shiro Kawai <shiro...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages