外部パッケージのシンボルを intern したい
keyword を intern する - Shammerismでは、キーワード引数を文字列変数から intern するにはどうすればいいかをやった。普通に : を追加して intern すると、頭にバックスラッシュがついてしまう。この対策は、intern の実行時に :keyword を追加すればよかった。
そして、もう一つコロンが使用される場合がある。それはパッケージ。外部パッケージで定義された関数を動的に呼出す、とかいうのをやるときは以下のようにする。
? (defpackage "AAA") #<Package "AAA"> ? (in-package aaa) #<Package "AAA"> ? (defun test () (format t "This is a test.~%")) TEST ? (funcall (intern "TEST")) This is a test. NIL ? (in-package common-lisp-user) #<Package "COMMON-LISP-USER"> ? (funcall (intern "TEST")) > Error: Undefined function TEST called with arguments () . > While executing: CCL::TOPLEVEL-EVAL, in process Listener(4). > Type cmd-/ to continue, cmd-. to abort, cmd-\ for a list of available restarts. > If continued: Retry applying TEST to NIL. > Type :? for other options. 1 > q ? (funcall (intern "TEST" "AAA")) This is a test. NIL ?