help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use a variable from outer scope in the success function of a


From: Iñigo Serna
Subject: Re: How to use a variable from outer scope in the success function of a request call?
Date: Sat, 29 Aug 2015 11:11:01 +0200

Answering myself...

Iñigo Serna writes:
> And to learn more myself, do you have any hint why `fn3' or `fn4' don't work 
> and how to make
> it work?

Using `lexical-let' with a dummy variable works:

(setq lexical-binding t)
(defun fn4 (c2)
  (lexical-let ((c c2))
    (my-request2 "https://api.stackexchange.com/2.1/questions";
                 #'(lambda (data &optional d)
                     (let* ((item (elt (assoc-default 'items data) 0))
                            (title (assoc-default 'title item))
                            (tags (assoc-default 'tags item)))
                       (message "PARAMS: %S" d)
                       (message "=> %s %S" title tags)
                       (message "LAST: %S" (nth 2 d))))
                 (list "OOOO" "AAAA" c))))
(fn4 "TEXT")

Btw, any solution to mark that c2 function parameter as "lexical" to
avoid using the intermediate variable and 'lexical-let' ?


This link has been of much help to understand what happened,
specially the "Another example which shows the difference" section:
    http://emacswiki.org/emacs/DynamicBindingVsLexicalBinding


Thanks for all the help,
Iñigo Serna



reply via email to

[Prev in Thread] Current Thread [Next in Thread]