Hello,
Is there any way to redefine previously defined function in ROOT environment?
Let’s say I input function :
root[0].rawInput 1
root[1] Double_t foo(Double_t *x, Double_t *p) { return p[0]*sin(x[0]) ; }
root[2].rawInput 0
And then I want to change foo to be f.e cos or remove it from known functions.
[quote=“Zimny”]Hello,
Is there any way to redefine previously defined function in ROOT environment?
Let’s say I input function :
root[0].rawInput 1
root[1] Double_t foo(Double_t *x, Double_t *p) { return p[0]*sin(x[0]) ; }
root[2].rawInput 0
And then I want to change foo to be f.e cos or remove it from known functions.
Cheers,
Zimny.[/quote]
Hm, I’m surprised that you can define a function in a command line, I have an error.
Anyway, if you have a file with a function declaration, you can load this file(s) and (re)define the same function, well, I think, that’s one of reasons we need an interpreter after all.
I don’t have function declaration in file so I can’t reload it.
I use gCling in my class to input these lines, and then using TMethodCall i can execute it.
Second question, is there any better way to achive same but not using gCling->ProcessLine function?
better way to achive same but not using gCling->ProcessLine function?[/quote]
The better way is to seriously re-think and re-design. Something is definitely SERIOUSLY wrong if you need such a functionality from the C++ programming language.
[quote=“tpochep”]
The better way is to seriously re-think and re-design. Something is definitely SERIOUSLY wrong if you need such a functionality from the C++ programming language.[/quote]
This topic isn’t about design and idea of my class. I need to execute c++ code from string using TMethodCall, i can achive that if function is known inside Cling. If you know better way to do it, please be kind and tell me how.
At the moment, unloading declaration (so that you can change them) is not supported in ROOT 6. We will partially support unloading for the release planned in May 2014.
In the meantime, you will need to use a different name for each of the function your need to (re)define.
For very simple function, you might be able to use a TF1 instead of using TMethodCall.
[quote]Second question, is there any better way to achive same but not using gCling->ProcessLine function?
[/quote]That depends … ‘better’ in which metrics? … Can you elaborate on the higher level problem you are trying to solve?