2016-11-11 99 views
0

我使用emacs-request从网上获取一些json数据。下面是我想知道的回调函数,如:success如何可以访问ARG1和ARG2一个例子如何从回调函数访问其他参数

(defun test (arg1 arg2) 
    (request 
    "http://httpbin.org/get" 
    :params '(("key" . "value") ("key2" . "value2")) 
    :parser 'json-read 
    :success (cl-function 
      (lambda (&key data &allow-other-keys) 
       (message "I sent: %S" (assoc-default 'args data)))))) 

回答

1

您可以设置lexical-binding variablet,允许lambda来访问外部函数的参数,或者在lexical-let结合外部函数的参数为​​拉姆达包裹:success功能:

(defun test (arg1 arg2) 
    (request 
    "http://httpbin.org/get" 
    :params '(("key" . "value") ("key2" . "value2")) 
    :parser 'json-read 
    :success (lexical-let ((arg1 arg1) (arg2 arg2)) 
       (cl-function 
       (lambda (&key data &allow-other-keys) 
       (message "%s %s sent: %S" arg1 arg2 (assoc-default 'args data))))))) 
相关问题