在 Common Lisp 中将结构传递给宏的类型错误



我有这个结构:

(defstruct (endpoint (:constructor create-endpoint (name tags values)))
name tags values)

而这个宏:

(defmacro build-get-endpoint (server db-uri db endpoint)
"constructs a get endpoint that returns all records in the measurement"
(with-gensyms (uri-sym path-sym query-sym route-sym fields)
`(let ((,fields (cons "time" (append (endpoint-tags ,endpoint)
(endpoint-values ,endpoint))))
(,uri-sym (quri:uri ,db-uri))
(,path-sym (format nil "/~a" ,(endpoint-name endpoint)))
(,query-sym (format nil "SELECT ~{~a~^, ~} FROM ~a"
,fields ,(endpoint-name endpoint))))
(setf (quri:uri-path ,uri-sym) "/query")
(setf (quri:uri-query-params ,uri-sym)
(list (cons "q" ,query-sym) (cons "db" ,db)))
(define-route ,server ,path-sym :get
(defview ,route-sym ()
(vom:debug "sending query (~a) to influx" (quri:render-uri ,uri-sym))
(call-influx (dex:get ,uri-sym)
(:no-error (body &rest args)
(declare (ignore args))
(respond (parse-get-response body)
:type "application/json" :status 200))))))))

但是当我尝试通过以下方式实际运行代码时:

(build-get-endpoint server (start-opts-db-uri starts)
(start-opts-db-name starts)
(create-endpoint "mood" nil '("value")))

我收到一个类型错误,说(create-endpoint "mood" nil '("value"))不属于ENDPOINT类型。

我做错了什么?

参见:,(endpoint-name endpoint)

这看起来像是在宏观膨胀时评估表达式。endpoint是代码,尚未计算。

相关内容

最新更新