【问题标题】:type error passing struct to macro in common lisp在通用 lisp 中将结构传递给宏的类型错误
【发布时间】:2020-05-26 06:05:10
【问题描述】:

我有这个结构:

(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 类型。

我做错了什么?

【问题讨论】:

    标签: struct macros common-lisp typeerror


    【解决方案1】:

    见:,(endpoint-name endpoint)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-03
      • 2013-07-26
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多