From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin Alsinet Subject: Re: C++ sessions for Babel with cling interpreter Date: Sun, 05 Nov 2017 23:42:12 +0000 Message-ID: References: <87po8wir9s.fsf@pc-117-162.i-did-not-set--mail-host-address--so-tickle-me> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a11469c62afab90055d44e312" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBUYe-00040V-L1 for emacs-orgmode@gnu.org; Sun, 05 Nov 2017 18:42:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBUYa-0003Oq-OT for emacs-orgmode@gnu.org; Sun, 05 Nov 2017 18:42:28 -0500 Received: from mail-wm0-f51.google.com ([74.125.82.51]:44316) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBUYa-0003OK-Cr for emacs-orgmode@gnu.org; Sun, 05 Nov 2017 18:42:24 -0500 Received: by mail-wm0-f51.google.com with SMTP id n74so8838912wmi.1 for ; Sun, 05 Nov 2017 15:42:23 -0800 (PST) In-Reply-To: <87po8wir9s.fsf@pc-117-162.i-did-not-set--mail-host-address--so-tickle-me> 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: garjola@garjola.net Cc: emacs-orgmode@gnu.org --001a11469c62afab90055d44e312 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Garjola: I have not used C++ source blocks, but I use them frequently with Javascript and Python, and I don't use sessions. The thing is, for literate programming, we want to include the code from one source block in others, and it would seem that sessions are the solution. However, I find that for me it is better to use tangle to export the code to source files and then include the tangled files from the other source blocks. Example: #+BEGIN_SRC js :tangle src/hello.js function hello(text) { console.log("hello " + text); } module.exports =3D hello; #+END_SRC First I have to run *org-babel-tangle* to export all source blocks to files, and then I can include them in other blocks. #+BEGIN_SRC js const hello =3D require("./src/hello.js"); hello("Martin"); #+END_SRC >From what I remember, it is possible to do the same in C++, including the source files you need from the filesystem. In my opinion, this approach is better than sessions, because the problem with sessions is that you have to make sure the blocks are executed secuentially in the right order to build the "state" that allows you to run your current block. This way each block is independent of all others, worst case you have to run org-babel-tangle to create the required files. Regards, Mart=C3=ADn On Sun, Nov 5, 2017 at 12:13 PM wrote: > Hi all, > > I use C++ source code blocks in babel frequently and I am very happy with > the results. As C++ is a compiled language, ob-C.el does not support > sessions. > > Unfortunately, this breaks a little my litterate programming workflow, > since I don't know how to use small code snippets without sessions. > > I have recently discovered cling [1], [2] a C++ interpreter which comes > with de Root package [3]. I have also found a cling inferior mode [4] to > interact with the interpreter in a comint buffer. > > I was wondering if it would be difficult to update ob-C.el to use cling > for session support. My elisp knowledge is too poor to understand what is > involved in doing such a thing, but I would be interested in trying or > helping somebody do it. Unfortunately, I have the impression that the > developers of ob-C.el are not around this list anymore? > > I would very much appreciate suggestions on how to proceed. > > Thank you. > > Garjola. > > Footnotes: > [1] https://root.cern.ch/cling > [2] https://www.youtube.com/watch?v=3DLbi7MLS03Yc > [3] https://root.cern.ch/ > [4] https://github.com/brianqq/inferior-cling > > -- > Dr. Dindi > Dad, Philosopher, Hacker > > --001a11469c62afab90055d44e312 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello Garjola:

I have not used C++ sour= ce blocks, but I use them frequently with Javascript and Python, and I don&= #39;t use sessions.
The thing is, for literate programming, we wa= nt to include the code from one source block in others, and it would seem t= hat sessions are the solution.
However, I find that for me it is = better to use tangle to export the code to source files and then include th= e tangled files from the other source blocks.

Exam= ple:

#+BEGIN_S= RC js :tangle src/hello.js
function hello(text) {
=C2=A0 =C2=A0 console.log("hello "=C2=A0+ text);
}
module.exports =3D hello;
#+END_SRC

Fir= st I have to run org-babel-tangle to export all source blocks to fil= es, and then I can include them in other blocks.

<= font face=3D"monospace" size=3D"2">#+BEGIN_SRC js
const hello =3D require("./src/hello.js&qu= ot;);
hello("Mart= in");
#+END_SRC

From what I remember, it is possible to do t= he same in C++, including the source files you need from the filesystem.
In my opinion, this approach is better than sessions, because the p= roblem with sessions is that you have to make sure the blocks are executed = secuentially in the right order to build the "state" that allows = you to run your current block. This way each block is independent of all ot= hers, worst case you have to run org-babel-tangle to create the required fi= les.

Regards,


<= div>Mart=C3=ADn


On Sun, Nov 5, 2017 at 12:13 PM <garjola@garjola.net> wrote:
Hi all,

I use C++ source code blocks in babel frequently and I am very happy with t= he results. As C++ is a compiled language, ob-C.el does not support session= s.

Unfortunately, this breaks a little my litterate programming workflow, sinc= e I don't know how to use small code snippets without sessions.

I have recently discovered cling [1], [2] a C++ interpreter which comes wit= h de Root package [3]. I have also found a cling inferior mode [4] to inter= act with the interpreter in a comint buffer.

I was wondering if it would be difficult to update ob-C.el to use cling for= session support. My elisp knowledge is too poor to understand what is invo= lved in doing such a thing, but I would be interested in trying or helping = somebody do it. Unfortunately, I have the impression that the developers of= ob-C.el are not around this list anymore?

I would very much appreciate suggestions on how to proceed.

Thank you.

Garjola.

Footnotes:
[1]=C2=A0 https://root.cern.ch/cling
[2]=C2=A0 https://www.youtube.com/watch?v=3DLbi7MLS03Yc=
[3]=C2=A0 https://root.cern.ch/
[4]=C2=A0 https://github.com/brianqq/inferior-cling

--
Dr. Dindi
Dad, Philosopher, Hacker

--001a11469c62afab90055d44e312--