emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] [PATCH] Make lexical eval default for elisp src blocks


From: John Kitchin
Subject: Re: [O] [PATCH] Make lexical eval default for elisp src blocks
Date: Mon, 18 Apr 2016 11:44:05 -0400
User-agent: mu4e 0.9.16; emacs 25.1.50.1

I don't think so. I haven't seen this be the case. A simple example like
this works as expected I think.

#+BEGIN_SRC emacs-lisp
(setq x 4)
#+END_SRC

#+RESULTS:
: 4


#+BEGIN_SRC emacs-lisp
(+ x 9)
#+END_SRC

#+RESULTS:
: 13


So far, I have only seen where this makes some new things possible. e.g.

This will not work unless evaluated with lexical-binding
#+BEGIN_SRC emacs-lisp :results value :lexical yes
;; Graham's alambda
(defmacro alambda (parms &rest body)
  `(cl-labels ((self ,parms ,@body))
     #'self))

(setq
 N
 (alambda (n)
          (if (> n 0)
              (cons
               n
               (self (- n 1))))))

(princ (funcall N 3))
#+END_SRC

#+RESULTS:
| 3 | 2 | 1 |

This just provides a different approach to :var I think.

#+BEGIN_SRC emacs-lisp :lexical '((x . 23))
(print x)
#+END_SRC

#+RESULTS:
: 23

I would be interested to see any counter examples though, where behavior
changes, or stops working.



Adam Porter writes:

> John Kitchin <address@hidden> writes:
>
> Forgive my ignorance--I haven't really dug into lexical scoping yet--but
> what is the basic effect will this change have on elisp code blocks?
> Say I'm doing some sort-of literate development and I have some code
> blocks that `setq' here and there, setting vars in the Emacs
> environment.  Will the scope of these vars now be limited to their code
> blocks?  Would I need to disable lexical scoping?  Thanks.


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



reply via email to

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