How to define functions in Jupyter?

Just wondering what the proper way is to define functions/classes in Jupyter. I tried the sample notebook, but .rawInput (in fact, all the “.” commands) seem not to work in Jupyter. If I try to use .rawInput, I get

input_line_11:2:2: error: expected expression .rawInput ^

In general, is there any documentation on the Jupyter kernel? I’ve tried reading the source, but without much success.

Thanks!

Hi,

just to be sure: are you referring to the cling kernel?
In case you are dealing with the ROOT kernel, the way of injecting functions is to use the %cpp magic:

%%cpp -d
void f(){};

For having the options of the cpp magic displayed:

%%cpp ?

Cheers,
D

Hi,

For cling we are “waiting” for an automatic separation of declarations and statements.

Until that’s there, please do

extern "C++" int func() { return 42; }

The “extern” triggers the declaration mode of cling; the cell will be assumed to only contain declarations.

Cheers, Axel.