REPL using DWScript
Hello,
I am interested in creating a REPL using Object Pascal syntax and Delphi objects. Our software does quite a bit of math and I would like to use the math objects that we have created but then manipulate them interactively like one does with Python/Julia etc.
I see a post from StackOverflow that touches on this subject with no clear answer. The idea would be that I could assign an instance of a matrix object to the script (which I think I can do with the .Instances) field of dwsUnit. Then, one command at a time manipulate the matrix and see some output.
The idea would be that I capture the user entered command, compile and execute it somehow. DWScript would have to preserve the variable values/definitions from all the previous script runs.
Do you think that could work?
Comments (4)
-
repo owner -
reporter I am not sure how most scripting languages work, but I have been playing with Julia a bit and the following seems to be the workflow.
You write a bunch of functions and compile the code. Then you can go to REPL mode and call functions that were previously compiled. But if you need to change the original functions, you need to recompile the code one time.
If you just change a line of code in one of the functions, it does nothing until you recompile. At least in teh visual studio code editor that I have been using.
I do not think it common to redefine the function or create new functions on the command line. Maybe a 1 line function or something but you certainly are not going to write tons of code on the command line and expect it to become part of the larger program.
-
reporter @Eric Grange I think I may have some funds to fund this project. If you are interested, please contact me at david.novo@denovoresearch.org.
-
reporter @Eric Grange Hi Eric. I responded to your email a few days ago but did not get a reply. I wonder if it went into your spam?
- Log in to comment
Hi,
It could work to some extent, but has not been a use case that was investigated much, outside of debugging purposes.
One way would be to the RecompileInContext method of the Compiler. You pass it a snippet of code and a pre-existing IdwsProgram, it will compile the snippet and add it whatever is in it to the program, but it won’t run it. You could use the Evaluate method to evaluate and provide an answer.
The two main issues I foresee are:
The second issue would be most problematic if the users wants to define a small function, and later wants to overwrite it with an updated version.