From: Emmanuel Charpentier <emm.charpentier@free.fr>
To: emacs-orgmode@gnu.org
Subject: (9.2) Noweb blocks not expanded in Python blocks.
Date: Mon, 04 Feb 2019 12:32:56 +0100 [thread overview]
Message-ID: <0d423cc9589a5b74bbdbbc9a63501ae8d5325a24.camel@free.fr> (raw)
[-- Attachment #1: Type: text/plain, Size: 3072 bytes --]
Seen in `org-mode' version `9.2'.
Using `noweb' syntax works OK with `emacs-lisp':
┌────
│ #+name: a
│ #+begin_src emacs-lisp
│ (setq L (append L (list i)))
│ #+end_src
│
│ #+name: b
│ #+begin_src emacs-lisp :noweb yes :exports both
│ ;; Lisp version
│ (setq L nil)
│ (dotimes (i 5) <<a>>)
│ L
│ #+end_src
└────
This gives :
┌────
│ (setq L (append L (list i)))
└────
┌────
│ ;; Lisp version
│ (setq L nil)
│ (dotimes (i 5) )
│ L
└────
The `noweb' syntax also works with `Sage' (a symbolic maths oriented
Python derivative):
┌────
│ #+name: Aaarghhh
│ #+begin_src sage
│ L.append(i)
│ #+end_src
│
│ #+name: Berde
│ #+begin_src sage :noweb yes :exports both
│ ## Python version
│ L=[]
│ for i in range(1,6):
│ <<Aaarghhh>>
│ L
│ #+end_src
└────
wich gives :
┌────
│ L.append(i)
└────
┌────
│ ## Sage version
│ L=[]
│ for i in range(1,6):
│
│ L
└────
But using the same syntax in Python fails miserably:
┌────
│ #+name: Ah
│ #+begin_src python
│ L.append(i)
│ #+end_src
│
│ #+name: Beee
│ #+begin_src python :noweb yes :exports both
│ ## Python version
│ L=[]
│ for i in range(1,6):
│ <<Ah>>
│ L
│ #+end_src
└────
┌────
│ L.append(i)
└────
┌────
│ ## Python version
│ L=[]
│ for i in range(1,6):
│ <<Ah>>
│ L
└────
┌────
│ []
└────
It *seems* that the "Ah" block is not expanded.
The code itself should be sound *if* it expanded:
┌────
│ #+name: B0
│ #+begin_src python :exports both
│ L=[]
│ for i in range(1,6):
│ L.append(i)
│ L
│ #+end_src
└────
┌────
│ L=[]
│ for i in range(1,6):
│ L.append(i)
│ L
└────
━━━━━━━━━━━━━━━
1 2 3 4 5
━━━━━━━━━━━━━━━
During the compilation of the source of this mail, the following is
printed in the `*Python*' buffer:
┌────
│ >>> L.append(i)
│ >>>
│ >>> open('/tmp/babel-OJSsxf/python-dVESY4', 'w').write(str(_))
│ >>>
│ >>>
│ >>> 'org_babel_python_eoe'
│ 'org_babel_python_eoe'
│ >>> ## Python version
│ ... L=[]
│ >>> for i in range(1,6):
│ ... <<Ah>>
│ File "<stdin>", line 2
│ <<Ah>>
│ ^
│ SyntaxError: invalid syntax
│ >>>
│ >>> L
│ []
│ >>>
│ >>> open('/tmp/babel-OJSsxf/python-9NR46u', 'w').write(str(_))
│ >>>
│ >>>
│ >>> 'org_babel_python_eoe'
│ 'org_babel_python_eoe'
│ >>> L=[]
│ >>> for i in range(1,6):
│ ... L.append(i)
│ ...
│ >>> L
│ [1, 2, 3, 4, 5]
│ >>>
│ >>> open('/tmp/babel-OJSsxf/python-fW5gK0', 'w').write(str(_))
│ >>>
│ >>>
│ >>> 'org_babel_python_eoe'
│ 'org_babel_python_eoe'
│ >>>
└────
The source code of this mail is attached.
--
Emmanuel Charpentier
[-- Attachment #2: PythonNowebProblem.org --]
[-- Type: text/plain, Size: 2819 bytes --]
# Syntaxe noweb ?
#+title:
#+date:
#+author:
#+options: toc:nil
#+property: header-args:python :session
#+property: header-args:sage :session
Seen in ~org-mode~ version src_emacs-lisp{org-version}.
Using ~noweb~ syntax works OK with ~emacs-lisp~:
#+begin_example
#+name: a
#+begin_src emacs-lisp
(setq L (append L (list i)))
#+end_src
#+name: b
#+begin_src emacs-lisp :noweb yes :exports both
;; Lisp version
(setq L nil)
(dotimes (i 5) <<a>>)
L
#+end_src
#+end_example
This gives :
#+name: a
#+begin_src emacs-lisp
(setq L (append L (list i)))
#+end_src
#+name: b
#+begin_src emacs-lisp :noweb yes :exports both
;; Lisp version
(setq L nil)
(dotimes (i 5) <<a>>)
L
#+end_src
The ~noweb~ syntax also works with ~Sage~ (a symbolic maths oriented
Python derivative):
#+begin_example
#+name: Aaarghhh
#+begin_src sage
L.append(i)
#+end_src
#+name: Berde
#+begin_src sage :noweb yes :exports both
## Python version
L=[]
for i in range(1,6):
<<Aaarghhh>>
L
#+end_src
#+end_example
wich gives :
#+name: Aaarghhh
#+begin_src sage
L.append(i)
#+end_src
#+name: Berde
#+begin_src sage :noweb yes :exports both
## Sage version
L=[]
for i in range(1,6):
<<Aaarghhh>>
L
#+end_src
But using the same syntax in Python fails miserably:
#+begin_example
#+name: Ah
#+begin_src python
L.append(i)
#+end_src
#+name: Beee
#+begin_src python :noweb yes :exports both
## Python version
L=[]
for i in range(1,6):
<<Ah>>
L
#+end_src
#+end_example
#+name: Ah
#+begin_src python
L.append(i)
#+end_src
#+name: Beee
#+begin_src python :noweb yes :exports both
## Python version
L=[]
for i in range(1,6):
<<Ah>>
L
#+end_src
It *seems* that the "Ah" block is not expanded.
The code itself should be sound *if* it expanded:
#+begin_example
#+name: B0
#+begin_src python :exports both
L=[]
for i in range(1,6):
L.append(i)
L
#+end_src
#+end_example
#+name: B0
#+begin_src python :exports both
L=[]
for i in range(1,6):
L.append(i)
L
#+end_src
During the compilation of the source of this mail, the following is
printed in the ~*Python*~ buffer:
#+begin_example
>>> L.append(i)
>>>
>>> open('/tmp/babel-OJSsxf/python-dVESY4', 'w').write(str(_))
>>>
>>>
>>> 'org_babel_python_eoe'
'org_babel_python_eoe'
>>> ## Python version
... L=[]
>>> for i in range(1,6):
... <<Ah>>
File "<stdin>", line 2
<<Ah>>
^
SyntaxError: invalid syntax
>>>
>>> L
[]
>>>
>>> open('/tmp/babel-OJSsxf/python-9NR46u', 'w').write(str(_))
>>>
>>>
>>> 'org_babel_python_eoe'
'org_babel_python_eoe'
>>> L=[]
>>> for i in range(1,6):
... L.append(i)
...
>>> L
[1, 2, 3, 4, 5]
>>>
>>> open('/tmp/babel-OJSsxf/python-fW5gK0', 'w').write(str(_))
>>>
>>>
>>> 'org_babel_python_eoe'
'org_babel_python_eoe'
>>>
#+end_example
next reply other threads:[~2019-02-04 11:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-04 11:32 Emmanuel Charpentier [this message]
2019-02-04 13:11 ` (9.2) Noweb blocks not expanded in Python blocks John Kitchin
2019-02-04 13:40 ` (9.2) Noweb blocks not expanded in Python blocks : it should be a bug Emmanuel Charpentier
2019-02-04 13:50 ` John Kitchin
2019-02-04 14:33 ` Robert Pluim
2019-02-04 17:03 ` Nicolas Goaziou
2019-02-05 6:51 ` Emmanuel Charpentier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0d423cc9589a5b74bbdbbc9a63501ae8d5325a24.camel@free.fr \
--to=emm.charpentier@free.fr \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.