Lisp-optional-parameters
提供:Dev Guides
LISP-オプションのパラメーター
オプションのパラメーターを使用して関数を定義できます。 これを行うには、オプションパラメータの名前の前にシンボル*&optional *を置く必要があります。
受け取ったパラメーターを表示するだけの関数を作成しましょう。
例
main.lispという名前の新しいソースコードファイルを作成し、次のコードを入力します。
(defun show-members (a b &optional c d) (write (list a b c d)))
(show-members 1 2 3)
(terpri)
(show-members 'a 'b 'c 'd)
(terpri)
(show-members 'a 'b)
(terpri)
(show-members 1 2 3 4)
あなたがコードを実行すると、それは次の結果を返します-
(1 2 3 NIL)
(A B C D)
(A B NIL NIL)
(1 2 3 4)
上記の例では、パラメーターcおよびdはオプションのパラメーターであることに注意してください。