From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: (9.2) Noweb blocks not expanded in Python blocks : it should be a bug... Date: Mon, 4 Feb 2019 08:50:42 -0500 Message-ID: References: <0d423cc9589a5b74bbdbbc9a63501ae8d5325a24.camel@free.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000000eaf4c058111c86e" Return-path: Received: from eggs.gnu.org ([209.51.188.92]:60615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqeeI-0005Qc-9O for emacs-orgmode@gnu.org; Mon, 04 Feb 2019 08:50:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqeeG-0007QE-BL for emacs-orgmode@gnu.org; Mon, 04 Feb 2019 08:50:58 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:50706) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gqeeF-0007PF-Ss for emacs-orgmode@gnu.org; Mon, 04 Feb 2019 08:50:56 -0500 Received: by mail-wm1-x32c.google.com with SMTP id z5so5310121wmf.0 for ; Mon, 04 Feb 2019 05:50:55 -0800 (PST) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Emmanuel Charpentier Cc: org-mode-email --0000000000000eaf4c058111c86e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I doubt it is Python specific, and I don't know why it would work in some places and not others. For me, the two character name does not work in elisp, but 1 or 3 does. I agree that seems buggy. The origin of the problem is here: #+BEGIN_SRC emacs-lisp (list (string-match (org-babel-noweb-wrap) "<>") (string-match (org-babel-noweb-wrap) "<>") (string-match (org-babel-noweb-wrap) "<>")) #+END_SRC #+RESULTS: | 0 | nil | 0 | my regex fu is not adequate to identify the problem: #+BEGIN_SRC emacs-lisp (org-babel-noweb-wrap) #+END_SRC #+RESULTS: : <<\([^ : ].+?[^ ]\|[^ : ]\)>> That function is used in org-babel-expand-noweb-references. It is somewhat luck that I found that, I was tracing org-babel-expand-noweb-references to see where it was failing, and walked through that line to see it failed on "Ah", and worked on longer names. 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 Mon, Feb 4, 2019 at 8:40 AM Emmanuel Charpentier wrote: > Le lundi 04 f=C3=A9vrier 2019 =C3=A0 08:11 -0500, John Kitchin a =C3=A9cr= it : > > The problem may be the name is only two characters long. Try Ahh instead. > That works for me. > > > Indeed. Nice catch ; how did you find this ? > > Since this doesn't happen with emacs-lisp or Sage, and since nothing in > the docs I've read so far suggests anything about the length of a block > identifier, I consider this a bug in the Python language support code. Wh= at > do you think ? Any hint ? > > Thanks a lot ! > > -- > Emmanuel Charpentier > > 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 Mon, Feb 4, 2019 at 7:00 AM Emmanuel Charpentier < > emm.charpentier@free.fr> wrote: > > Seen in `org-mode' version `9.2'. > > Using `noweb' syntax works OK with `emacs-lisp': > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 #+name: a > =E2=94=82 #+begin_src emacs-lisp > =E2=94=82 (setq L (append L (list i))) > =E2=94=82 #+end_src > =E2=94=82 > =E2=94=82 #+name: b > =E2=94=82 #+begin_src emacs-lisp :noweb yes :exports both > =E2=94=82 ;; Lisp version > =E2=94=82 (setq L nil) > =E2=94=82 (dotimes (i 5) <>) > =E2=94=82 L > =E2=94=82 #+end_src > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > This gives : > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 (setq L (append L (list i))) > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 ;; Lisp version > =E2=94=82 (setq L nil) > =E2=94=82 (dotimes (i 5) ) > =E2=94=82 L > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > The `noweb' syntax also works with `Sage' (a symbolic maths oriented > Python derivative): > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 #+name: Aaarghhh > =E2=94=82 #+begin_src sage > =E2=94=82 L.append(i) > =E2=94=82 #+end_src > =E2=94=82 > =E2=94=82 #+name: Berde > =E2=94=82 #+begin_src sage :noweb yes :exports both > =E2=94=82 ## Python version > =E2=94=82 L=3D[] > =E2=94=82 for i in range(1,6): > =E2=94=82 <> > =E2=94=82 L > =E2=94=82 #+end_src > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > wich gives : > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 L.append(i) > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 ## Sage version > =E2=94=82 L=3D[] > =E2=94=82 for i in range(1,6): > =E2=94=82 > =E2=94=82 L > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > But using the same syntax in Python fails miserably: > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 #+name: Ah > =E2=94=82 #+begin_src python > =E2=94=82 L.append(i) > =E2=94=82 #+end_src > =E2=94=82 > =E2=94=82 #+name: Beee > =E2=94=82 #+begin_src python :noweb yes :exports both > =E2=94=82 ## Python version > =E2=94=82 L=3D[] > =E2=94=82 for i in range(1,6): > =E2=94=82 <> > =E2=94=82 L > =E2=94=82 #+end_src > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 L.append(i) > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 ## Python version > =E2=94=82 L=3D[] > =E2=94=82 for i in range(1,6): > =E2=94=82 <> > =E2=94=82 L > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 [] > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > > It *seems* that the "Ah" block is not expanded. > > The code itself should be sound *if* it expanded: > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 #+name: B0 > =E2=94=82 #+begin_src python :exports both > =E2=94=82 L=3D[] > =E2=94=82 for i in range(1,6): > =E2=94=82 L.append(i) > =E2=94=82 L > =E2=94=82 #+end_src > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 L=3D[] > =E2=94=82 for i in range(1,6): > =E2=94=82 L.append(i) > =E2=94=82 L > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81 > 1 2 3 4 5 > =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81 > > During the compilation of the source of this mail, the following is > printed in the `*Python*' buffer: > > =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > =E2=94=82 >>> L.append(i) > =E2=94=82 >>> > =E2=94=82 >>> open('/tmp/babel-OJSsxf/python-dVESY4', 'w').write(str(_)) > =E2=94=82 >>> > =E2=94=82 >>> > =E2=94=82 >>> 'org_babel_python_eoe' > =E2=94=82 'org_babel_python_eoe' > =E2=94=82 >>> ## Python version > =E2=94=82 ... L=3D[] > =E2=94=82 >>> for i in range(1,6): > =E2=94=82 ... <> > =E2=94=82 File "", line 2 > =E2=94=82 <> > =E2=94=82 ^ > =E2=94=82 SyntaxError: invalid syntax > =E2=94=82 >>> > =E2=94=82 >>> L > =E2=94=82 [] > =E2=94=82 >>> > =E2=94=82 >>> open('/tmp/babel-OJSsxf/python-9NR46u', 'w').write(str(_)) > =E2=94=82 >>> > =E2=94=82 >>> > =E2=94=82 >>> 'org_babel_python_eoe' > =E2=94=82 'org_babel_python_eoe' > =E2=94=82 >>> L=3D[] > =E2=94=82 >>> for i in range(1,6): > =E2=94=82 ... L.append(i) > =E2=94=82 ... > =E2=94=82 >>> L > =E2=94=82 [1, 2, 3, 4, 5] > =E2=94=82 >>> > =E2=94=82 >>> open('/tmp/babel-OJSsxf/python-fW5gK0', 'w').write(str(_)) > =E2=94=82 >>> > =E2=94=82 >>> > =E2=94=82 >>> 'org_babel_python_eoe' > =E2=94=82 'org_babel_python_eoe' > =E2=94=82 >>> > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > > The source code of this mail is attached. > > -- > Emmanuel Charpentier > > --0000000000000eaf4c058111c86e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I doubt= it is Python specific, and I don't know why it would work in some plac= es and not others. For me, the two character name does not work in elisp, b= ut 1 or 3 does. I agree that seems buggy.

<= div dir=3D"ltr">The origin of the problem is here:

<= div>#+BEGIN_SRC emacs-lisp
(list
=C2=A0(string-match (o= rg-babel-noweb-wrap) "<<A>>")
=C2=A0(string= -match (org-babel-noweb-wrap) "<<Ah>>")
=C2= =A0(string-match (org-babel-noweb-wrap) "<<Ahh>>"))
#+END_SRC

#+RESULTS:
| 0 | nil = | 0 |

my regex fu is not adequate to identify the = problem:

#+BEGIN_SRC emacs-lisp
(or= g-babel-noweb-wrap)
#+END_SRC

#+RESULTS:=
: <<\([^
: ].+?[^ ]\|[^
: ]\)>>

That function is used in=C2=A0org-babel-expand-noweb-references.=C2=A0


It is somewhat luck that I found tha= t, I was tracing org-babel-expand-noweb-references to see where it was fail= ing, and walked through that line to see it failed on "Ah", and w= orked on longer names.

Le lundi 04 f=C3=A9= vrier 2019 =C3=A0 08:11 -0500, John Kitchin a =C3=A9crit=C2=A0:
The problem may be the= name is only two characters long. Try Ahh instead. That works for me.=C2= =A0

Indeed. Nice ca= tch ; how did you find this ?

Since this doesn'= ;t happen with emacs-lisp or Sage, and since nothing in the docs I've r= ead so far suggests anything about the length of a block identifier, I cons= ider this a bug in the Python language support code. What do you think ? A= ny hint ?

Thanks a lot !

= --
Emmanuel Charpentier

John

-----------------------------------
Professor John Kitchin= =C2=A0
Doherty Hall A207F
Department of Chemical Engineering
Carne= gie Mellon University
Pittsburgh, PA 15213
412-268-7803


On Mon, Feb 4, 2019 at 7:00 AM Emmanuel Charpentier <<= a href=3D"mailto:emm.charpentier@free.fr" target=3D"_blank">emm.charpentier= @free.fr> wrote:
= Seen in `org-mode' version `9.2'.

Using `noweb' syntax works OK with `emacs-lisp':

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 #+name: a
=E2=94=82 #+begin_src emacs-lisp
=E2=94=82=C2=A0 =C2=A0(setq L (append L (list i)))
=E2=94=82 #+end_src
=E2=94=82
=E2=94=82 #+name: b
=E2=94=82 #+begin_src emacs-lisp :noweb yes :exports both
=E2=94=82=C2=A0 =C2=A0;; Lisp version
=E2=94=82=C2=A0 =C2=A0(setq L nil)
=E2=94=82=C2=A0 =C2=A0(dotimes (i 5) <<a>>)
=E2=94=82=C2=A0 =C2=A0L
=E2=94=82 #+end_src
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80

This gives :

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 (setq L (append L (list i)))
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 ;; Lisp version
=E2=94=82 (setq L nil)
=E2=94=82 (dotimes (i 5) )
=E2=94=82 L
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80

The `noweb' syntax also works with `Sage' (a symbolic maths oriente= d
Python derivative):

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 #+name: Aaarghhh
=E2=94=82 #+begin_src sage
=E2=94=82=C2=A0 =C2=A0L.append(i)
=E2=94=82 #+end_src
=E2=94=82
=E2=94=82 #+name: Berde
=E2=94=82 #+begin_src sage :noweb yes :exports both
=E2=94=82=C2=A0 =C2=A0## Python version
=E2=94=82=C2=A0 =C2=A0L=3D[]
=E2=94=82=C2=A0 =C2=A0for i in range(1,6):
=E2=94=82=C2=A0 =C2=A0 =C2=A0 =C2=A0<<Aaarghhh>>
=E2=94=82=C2=A0 =C2=A0L
=E2=94=82 #+end_src
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80

wich gives :

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 L.append(i)
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 ## Sage version
=E2=94=82 L=3D[]
=E2=94=82 for i in range(1,6):
=E2=94=82
=E2=94=82 L
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80

But using the same syntax in Python fails miserably:

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 #+name: Ah
=E2=94=82 #+begin_src python
=E2=94=82=C2=A0 =C2=A0L.append(i)
=E2=94=82 #+end_src
=E2=94=82
=E2=94=82 #+name: Beee
=E2=94=82 #+begin_src python :noweb yes :exports both
=E2=94=82=C2=A0 =C2=A0## Python version
=E2=94=82=C2=A0 =C2=A0L=3D[]
=E2=94=82=C2=A0 =C2=A0for i in range(1,6):
=E2=94=82=C2=A0 =C2=A0 =C2=A0 =C2=A0<<Ah>>
=E2=94=82=C2=A0 =C2=A0L
=E2=94=82 #+end_src
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 L.append(i)
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 ## Python version
=E2=94=82 L=3D[]
=E2=94=82 for i in range(1,6):
=E2=94=82=C2=A0 =C2=A0 =C2=A0<<Ah>>
=E2=94=82 L
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 []
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80


It *seems* that the "Ah" block is not expanded.

The code itself should be sound *if* it expanded:

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 #+name: B0
=E2=94=82 #+begin_src python :exports both
=E2=94=82=C2=A0 =C2=A0L=3D[]
=E2=94=82=C2=A0 =C2=A0for i in range(1,6):
=E2=94=82=C2=A0 =C2=A0 =C2=A0 =C2=A0L.append(i)
=E2=94=82=C2=A0 =C2=A0L
=E2=94=82 #+end_src
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 L=3D[]
=E2=94=82 for i in range(1,6):
=E2=94=82=C2=A0 =C2=A0 =C2=A0L.append(i)
=E2=94=82 L
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80

=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2= =94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81
=C2=A01=C2=A0 2=C2=A0 3=C2=A0 4=C2=A0 5
=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2= =94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81

During the compilation of the source of this mail, the following is
printed in the `*Python*' buffer:

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 >>> L.append(i)
=E2=94=82 >>>
=E2=94=82 >>> open('/tmp/babel-OJSsxf/python-dVESY4', '= ;w').write(str(_))
=E2=94=82 >>>
=E2=94=82 >>>
=E2=94=82 >>> 'org_babel_python_eoe'
=E2=94=82 'org_babel_python_eoe'
=E2=94=82 >>> ## Python version
=E2=94=82 ... L=3D[]
=E2=94=82 >>> for i in range(1,6):
=E2=94=82 ...=C2=A0 =C2=A0 =C2=A0<<Ah>>
=E2=94=82=C2=A0 =C2=A0File "<stdin>", line 2
=E2=94=82=C2=A0 =C2=A0 =C2=A0<<Ah>>
=E2=94=82=C2=A0 =C2=A0 =C2=A0 ^
=E2=94=82 SyntaxError: invalid syntax
=E2=94=82 >>>
=E2=94=82 >>> L
=E2=94=82 []
=E2=94=82 >>>
=E2=94=82 >>> open('/tmp/babel-OJSsxf/python-9NR46u', '= ;w').write(str(_))
=E2=94=82 >>>
=E2=94=82 >>>
=E2=94=82 >>> 'org_babel_python_eoe'
=E2=94=82 'org_babel_python_eoe'
=E2=94=82 >>> L=3D[]
=E2=94=82 >>> for i in range(1,6):
=E2=94=82 ...=C2=A0 =C2=A0 =C2=A0L.append(i)
=E2=94=82 ...
=E2=94=82 >>> L
=E2=94=82 [1, 2, 3, 4, 5]
=E2=94=82 >>>
=E2=94=82 >>> open('/tmp/babel-OJSsxf/python-fW5gK0', '= ;w').write(str(_))
=E2=94=82 >>>
=E2=94=82 >>>
=E2=94=82 >>> 'org_babel_python_eoe'
=E2=94=82 'org_babel_python_eoe'
=E2=94=82 >>>
=E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80

The source code of this mail is attached.

--
Emmanuel Charpentier
--0000000000000eaf4c058111c86e--