2014-11-13 30 views
1

我是新來的宏,並在JSON-RPC的宏中需求掙扎。Lisp宏 - 如何正確輸入類型

它是要求一個類型,我不知道如何正確輸入它。

(defmacro defun-json-rpc (name type lambda-list &body body) 
    "Defines a function and registers it as a json-rpc target." 
    (unless (json-rpc-encoding-p type)  
    (error "New version of defun-json-rpc requires a TYPE argument")) 
    `(progn  
    (defun ,name ,lambda-list ,@body) 
    (export-as-json-rpc ',name (lisp-to-camel-case (symbol-name ',name)) ,type))) 

一塊的樣本代碼,我發現如下,但它不包含類型參數:

(json-rpc:defun-json-rpc add (x y) 
    (+ x y)) 

我怎麼會進入類型?

+0

不應該是'(除非(json-rpc-encoding-p type)(error ...))'? – Sylwester

+0

更正了該問題。我使用的代碼在那裏。 – Mark

回答

0

找到它。它是一個JSON-RPC特定的關鍵字,而不是一個lisp類型。我只需要看看json-rpc-encoding-p,看看只有3個關鍵字是有效的。

(defgeneric json-rpc-encoding-p (keyword) 
    (:documentation "Is KEYWORD a valid JSON-RPC value encoding?") 
    (:method (keyword) 
    "Default is no." 
    (declare (ignore keyword)) 
     nil) 
    ;;; built-in methods 
    (:method ((keyword (eql :guessing))) 
    t) 
    (:method ((keyword (eql :streaming))) 
    t) 
    (:method ((keyword (eql :explicit))) 
    t)) 
+0

請務必將您的答案標記爲已接受。如果你可以詳細闡述它,它可能會幫助其他用戶。 –