2016-11-11 55 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))))))) 
相關問題