2016-11-11 1 views
0

웹에서 json 데이터를 얻으려면 emacs-request을 사용하고 있습니다. 여기에 내가 같은 :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에를 설정하거나 람다에 대한 외부 함수의 인수를 결합하는 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))))))) 
관련 문제