Comment detail

メソッド名一覧の表示 (Nested Flatten)
Common Lispのメソッドはクラス内の概念ではないので「複数の関数への参照を持っているようなオブジェクト(たとえばパッケージとかモジュールとか)から"test_"で始まる関数をすべて呼び出す」 関数名はLisp的にはtest-なんだけどね~
1
2
3
4
5
6
7
(require :cl-ppcre)
(defun test_1 () 1)
(defun test_2 () 2)
(defun test_3 () 3)

(loop for f in (ppcre:regex-apropos-list "^test_" *package*)
   collect (cons f (funcall f)))        ; => ((TEST_1 . 1) (TEST_3 . 3) (TEST_2 . 2))
変数の定義でもシンボルはインターンされるので fboundp を。ついでに大文字小文字を区別する別回答。 funcall は関数を探しにいきますので symbol-function は不要ですがなんとなく。
1
2
3
4
(defun call-test (pakcage)
  (do-symbols (symbol pakcage)
    (when (and (fboundp symbol) (ppcre:scan "^test_" (symbol-name symbol)))
      (format t "~A => ~A~%" symbol (funcall (symbol-function symbol))))))
ぎゃぁ、fboundpが抜けてたorzorzorz
1
2
3
4
5
6
7
8
9
(require :cl-ppcre)
(defun test_1 () 1)
(defun test_2 () 2)
(defun test_3 () 3)
(defparameter test_var 0)

(loop for f in (ppcre:regex-apropos-list "^test_" *package*)
   when (fboundp f)
   collect (cons f (funcall f)))        ; => ((TEST_1 . 1) (TEST_3 . 3) (TEST_2 . 2))

Index

Feed

Other

Link

Pathtraq

loading...