* funny emacs-lisp macro behavior in org-babel related to lexical-binding
@ 2016-04-14 18:36 John Kitchin
2016-04-15 20:49 ` Nicolas Goaziou
0 siblings, 1 reply; 8+ messages in thread
From: John Kitchin @ 2016-04-14 18:36 UTC (permalink / raw)
To: emacs-orgmode
Hi all,
I was playing around with elisp macros in an org-file and came across a
behavior I didn't expect that is due to lexical binding.
Here is the code:
#+BEGIN_SRC emacs-lisp :results output :prologue
;; -*- lexical-binding: t -*-
;; you need this to make the binding.
(setq lexical-binding t)
;; 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))))))
(funcall N 3)
#+END_SRC
The last line should return (3 2 1), and it does if I use C-x C-e on
each form. If I try to run the block though, I get an error:
cons: Symbol’s value as variable is void: --cl-self--
I can see where that comes from. The macro expands to:
(lambda (n) (if (> n 0) (cons n (funcall --cl-self-- (- n 1)))))
This doesn't work because babel simply evals the body of the code. It
turns out you can use eval with lexical scoping:
(eval FORM &optional LEXICAL)
Evaluate FORM and return its value.
If LEXICAL is t, evaluate using lexical scoping.
So, I would like to propose adding the third argument to the eval
statement that reads
(assoc :lexical params)
to turn on lexical eval if you want it.
What do you think?
--
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: funny emacs-lisp macro behavior in org-babel related to lexical-binding
2016-04-14 18:36 funny emacs-lisp macro behavior in org-babel related to lexical-binding John Kitchin
@ 2016-04-15 20:49 ` Nicolas Goaziou
2016-04-16 13:41 ` John Kitchin
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2016-04-15 20:49 UTC (permalink / raw)
To: John Kitchin; +Cc: emacs-orgmode
Hello,
John Kitchin <jkitchin@andrew.cmu.edu> writes:
> So, I would like to propose adding the third argument to the eval
> statement that reads
>
> (assoc :lexical params)
>
> to turn on lexical eval if you want it.
>
> What do you think?
I assume you're talking about ob-emacs-lisp.el. This sounds like a good
idea. However, I suggest to make lexical binding the default value, to
be on par with the rest of Emacs.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: funny emacs-lisp macro behavior in org-babel related to lexical-binding
2016-04-15 20:49 ` Nicolas Goaziou
@ 2016-04-16 13:41 ` John Kitchin
2016-04-16 16:52 ` Nicolas Goaziou
0 siblings, 1 reply; 8+ messages in thread
From: John Kitchin @ 2016-04-16 13:41 UTC (permalink / raw)
To: John Kitchin, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 915 bytes --]
That sounds fine to me. Would you then use
:lexical nil
in a header to turn it off? or a new custom variable?
John
-----------------------------------
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
On Fri, Apr 15, 2016 at 4:49 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:
> Hello,
>
> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
> > So, I would like to propose adding the third argument to the eval
> > statement that reads
> >
> > (assoc :lexical params)
> >
> > to turn on lexical eval if you want it.
> >
> > What do you think?
>
> I assume you're talking about ob-emacs-lisp.el. This sounds like a good
> idea. However, I suggest to make lexical binding the default value, to
> be on par with the rest of Emacs.
>
>
> Regards,
>
> --
> Nicolas Goaziou
>
[-- Attachment #2: Type: text/html, Size: 1727 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: funny emacs-lisp macro behavior in org-babel related to lexical-binding
2016-04-16 13:41 ` John Kitchin
@ 2016-04-16 16:52 ` Nicolas Goaziou
2016-04-17 1:08 ` John Kitchin
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2016-04-16 16:52 UTC (permalink / raw)
To: John Kitchin; +Cc: emacs-orgmode
John Kitchin <jkitchin@andrew.cmu.edu> writes:
> That sounds fine to me. Would you then use
>
> :lexical nil
Sure. However, Babel uses "yes" and "no" as booleans so we also need to
support these. nil and t are fine too, obviously.
You would need to define a new defconst
`org-babel-header-args:emacs-lisp' to specify allowed values
for :lexical.
Also, this should probably be documented somewehere.
Regards,
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: funny emacs-lisp macro behavior in org-babel related to lexical-binding
2016-04-16 16:52 ` Nicolas Goaziou
@ 2016-04-17 1:08 ` John Kitchin
2016-04-17 8:18 ` Thomas S. Dye
2016-04-17 16:11 ` Charles C. Berry
0 siblings, 2 replies; 8+ messages in thread
From: John Kitchin @ 2016-04-17 1:08 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
I submitted a patch for this. I still am not sure I did it quite right.
Is there a page anywhere that outlines what to do?
e.g.
create a branch, make changes, how to make patches, and mail them etc...
or some other preferred method?
thanks,
Nicolas Goaziou writes:
> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> That sounds fine to me. Would you then use
>>
>> :lexical nil
>
> Sure. However, Babel uses "yes" and "no" as booleans so we also need to
> support these. nil and t are fine too, obviously.
>
> You would need to define a new defconst
> `org-babel-header-args:emacs-lisp' to specify allowed values
> for :lexical.
>
> Also, this should probably be documented somewehere.
>
>
> Regards,
--
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: funny emacs-lisp macro behavior in org-babel related to lexical-binding
2016-04-17 1:08 ` John Kitchin
@ 2016-04-17 8:18 ` Thomas S. Dye
2016-04-17 16:11 ` Charles C. Berry
1 sibling, 0 replies; 8+ messages in thread
From: Thomas S. Dye @ 2016-04-17 8:18 UTC (permalink / raw)
To: John Kitchin; +Cc: emacs-orgmode, Nicolas Goaziou
Aloha John,
John Kitchin writes:
> I submitted a patch for this. I still am not sure I did it quite right.
> Is there a page anywhere that outlines what to do?
>
> e.g.
>
> create a branch, make changes, how to make patches, and mail them etc...
> or some other preferred method?
Yes, create a branch, make your changes, add and commit them, then run
the following command to wrap up the latest commit on your new branch of
the repository into a file which can be attached to email messages
git format-patch -o ~/temp/ HEAD~1
after the command finished you will notice a new file in ~/temp
with a name like 0001-commit-message-stuff.patch
hth,
Tom
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: funny emacs-lisp macro behavior in org-babel related to lexical-binding
2016-04-17 1:08 ` John Kitchin
2016-04-17 8:18 ` Thomas S. Dye
@ 2016-04-17 16:11 ` Charles C. Berry
2016-04-17 23:03 ` John Kitchin
1 sibling, 1 reply; 8+ messages in thread
From: Charles C. Berry @ 2016-04-17 16:11 UTC (permalink / raw)
To: John Kitchin; +Cc: emacs-orgmode
On Sat, 16 Apr 2016, John Kitchin wrote:
> I submitted a patch for this. I still am not sure I did it quite right.
> Is there a page anywhere that outlines what to do?
>
> e.g.
>
> create a branch, make changes, how to make patches, and mail them etc...
> or some other preferred method?
http://orgmode.org/worg/org-contribute.html#patches
HTH,
Chuck
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: funny emacs-lisp macro behavior in org-babel related to lexical-binding
2016-04-17 16:11 ` Charles C. Berry
@ 2016-04-17 23:03 ` John Kitchin
0 siblings, 0 replies; 8+ messages in thread
From: John Kitchin @ 2016-04-17 23:03 UTC (permalink / raw)
To: Charles C. Berry; +Cc: emacs-orgmode
thanks, this is the page I was looking for.
Charles C. Berry writes:
> On Sat, 16 Apr 2016, John Kitchin wrote:
>
>> I submitted a patch for this. I still am not sure I did it quite right.
>> Is there a page anywhere that outlines what to do?
>>
>> e.g.
>>
>> create a branch, make changes, how to make patches, and mail them etc...
>> or some other preferred method?
>
>
> http://orgmode.org/worg/org-contribute.html#patches
>
> HTH,
>
> Chuck
--
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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-04-17 23:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-14 18:36 funny emacs-lisp macro behavior in org-babel related to lexical-binding John Kitchin
2016-04-15 20:49 ` Nicolas Goaziou
2016-04-16 13:41 ` John Kitchin
2016-04-16 16:52 ` Nicolas Goaziou
2016-04-17 1:08 ` John Kitchin
2016-04-17 8:18 ` Thomas S. Dye
2016-04-17 16:11 ` Charles C. Berry
2016-04-17 23:03 ` John Kitchin
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).