emacs-devel
[Top][All Lists]
Advanced

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

Evaluate a closure in a subprocess?


From: Klaus-Dieter Bauer
Subject: Evaluate a closure in a subprocess?
Date: Sun, 9 Aug 2015 18:06:18 +0200

Hello!

Currently `lambda' forms evaluate to a `closure' form in lexical environments, where the first element after the 'closure symbol represents the lexical environment. 

The documentation clearly states that this form shouldn't be relied on, so e.g. extracting the lexical environment from the closure form is not future-proof (i.e. using (cadr (lambda ())) as an equivalent to python's locals() function). 

However, the current implementation also allows passing a closure, or even its byte-code representation, as a string to a different emacs process and evaluate it there, preserving the values of the captured lexical environment, e.g. 

    (call-process "emacs" nil (current-buffer) nil "--batch" "--eval" 
      (format "(print (funcall (quote %S)))" 
        (let ((lp load-path)) 
          (lambda () lp))))

I currently use a similar construct for compiling emacs lisp files in a clean emacs session (since a long-running session may contain artifacts that mask or cause errors). 

So I was wondering if this is an intended behaviour or also a side-effect of the current implementation that may change at any time. 


regards, Klaus

reply via email to

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