# 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) <>)
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) <>)
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):
<>
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):
<>
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):
<>
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):
<>
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):
... <>
File "", line 2
<>
^
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