0

(疑似コード) のようなループから COND 句を動的に構築できるかどうか疑問に思います。

(defvar current-state 1)

(defmacro mymacro ()
  (cond
    `(loop (state . callback) in possible-states
      do ((eq current-state ,state)
          (funcall ,callback)))))

LOOP はリストから句を作成し、次のようなものを生成します。

(cond
  ((eq current-state 1)
   (funcall func-1))
  ((eq current-state 2)
   (funcall func-2))
  ((eq current-state 3)
   (funcall func-3)))
4

1 に答える 1