Recommendations for a scripting language or plug-ins for highly dependent custom coding?

I started generosity for this matter

... because I really want a community. I can (and have) looked at several languages ​​/ and thought “well, it will probably work well”, but I would really appreciate advice based solely on the problem I am facing, and especially from anyone who has experience integration / using what you recommend.




I am working on scientific analysis software. It provides many tools for mathematical transformation of data. One tool allows the user to enter their own equation, which is performed over a data set (large two-dimensional or three-dimensional matrix of values) and evaluated.

This tool has a graphical equation editor that internally creates an object-oriented expression tree with a different object for each operation (for example, there will be an instance of the Logarithm class, which is a node in the tree to add the calculation of the logarithm of the value to the base, it has two children who are by its inputs.) Screenshot of its part:

enter image description here

You can see the tree that he is building on the left, and several of the many (fifty?) Potential operations in the menu on the right.

This has several disadvantages:

  • The graphical editor becomes awkward for complex equations
  • There are some operations that are difficult to represent graphically, for example, creating large matrices (for example, the kernel for convolution nxn)
  • It only solves equations: no branching or other logic

It was neat when it was much easier, but nothing more, for those things that our users want to have to do with it. If I wrote it now, I would have done it in a completely different way - and this is my chance :)

I would like to give the user something more powerful and let them write code - script or compiled - that can perform much more complex operations. I am looking for SO advice on what technology he should use or the best approach to it.

The rest of this question is quite long - sorry. I tried to describe the problem in detail. Thanks in advance for reading :)

Important limitations:

  • Our math works with large matrices. In the above equation, V1 represents an input (one of potentially many) and represents 2D or 3D, and each dimension can be large: on the order of thousands or hundreds of thousands. (We rarely calculate all of this at once, only fragments / segments. But if the answer includes something that requires sorting the data, pay attention to the size and speed of this consideration.)

  • The operations we provide allow us to write, say, 2 x V , which multiplies each element in V by 2. The result is another matrix of the same size. In other words, a scripting or programming language that includes standard math primitives is not enough: we need to be able to control which primitives are available or how they are implemented.

    These operations can be complicated: the input can be as simple as a number (2, 5.3, pi) or complicated as a 1, 2 or 3-dimensional matrix that contains a boolean or complex number (pair values). My modern thinking is a language powerful enough so that we can expand our data types as classes and implement standard operators. A simple appraiser will be inadequate.

    • Instead of just writing operations that are evaluated iteratively on one or more inputs to provide output, as is currently the case (which is easily implemented using an expression evaluator), I would like the user to be able to: provide outputs of different sizes to the inputs; to call other functions; etc. It would be useful for the host program to ask the user code which part or fragment of the inputs is needed to evaluate the fragment or part of the output. I think exposing some of our classes and using the OO language is probably the best way to achieve these goals.
  • Our audience is primarily academic researchers who are either not used for coding, or are probably used for a language such as Matlab or R.

  • We use Embarcadero C ++ Builder 2010 for development, with a small amount of Delphi. This may limit what we can use - simply because something C ++, say, does not mean that it will work if it is encoded only against VC ++ or GCC. It should also be suitable for use with commercial software.

  • Our software currently has a COM interface, and part of the application can be automated with our application, which is a COM server outside the process. We could add COM interfaces to some internal objects or, if necessary, make a second COM infrastructure.

  • Tools, including this one, are migrated to a multi-threaded environment. The final solution must be performed in any thread , and several instances of it in many threads at the same time . This can affect the runtime of a hosted language - Python 2.x, for example, has a global lock.

  • It would be great to use the language that comes with the libraries for mathematical or scientific use.

  • Backward compatibility with the old expression tool is not important. This is version 2: clean slate!

Current ideas:

  • RemObjects Pascal Script and DWScript are languages ​​that are easily associated with TObject tailored classes. I do not know if operator overload can be ensured.
  • Hosting .Net runtime and loading C # (say) based DLLs as plugins. I like this idea: I saw how this is done where the host program provides a syntax shortcut, debugging, etc. I understand that this was a huge amount of coding. This would allow the use of IronPython and F #.
    • RemObjects Hydra looks like an interesting way to achieve this. Unfortunately, he advertises himself for Delphi, not C ++ Builder; I am studying compatibility.
  • The hosting is something like Python, which can be done from RAD Studio
  • Providing a BPL interface and providing users with code directly against our program if they buy a copy of RAD Studio (i.e. provide a plug-in interface and expose classes via interfaces; it may be necessary that the plug-ins be compiled with a binary compatible version of our IDE)
  • ...

Thanks for your input! I appreciate all the answers, even if they are not quite perfect - I can investigate, I’m just after instructions on where to go and opinions (please, opinions for the reasons included in the answer: p) about how to approach it or what may be suitable. Each answer, no matter how short, will be appreciated. But if you recommend something in detail, and not just "use the X language," I will be very interested to read it :)

Greetings

David

Update:

So far, the following has been recommended:

  • Python: 2.6 has a global lock that sounds like a game killer. 3 (apparently) does not yet have broad support from useful libraries. It sounds to me (and I know that I am a proponent of the Python community), as if it is fragmenting a bit - is it really safe?

  • Lua: It seems to be not a direct OO, but it provides "meta-mechanisms for implementing functions, and does not provide many functions directly in the language . " It sounds very cool from a programmer’s point of view, but it’s not aimed at programmers who need to play around with cool things. I'm not sure how well this will work with the target audience - I think a language that provides a more basic foundation will be better.

  • MS script / ActiveScript. We already provide an external COM interface that our users use to automate our software, usually in VBScript. However, I need a more powerful (and, frankly, better developed) language than VBS, and I don’t think JScript is suitable. I’m also not sure what problems may be associated with COM data - we have a lot of data that is often printed very accurately, so the speed and persistence of these types are important.

  • Lisp: I didn’t even think about this language, but I know that he has a lot of fans.

  • Hosting Pure plugins: no one is mentioned. Isn't that a good idea? You get C #, F #, Python ... Does it have the same problems with COM sorting? (Does CLR work through COM?)

A few clarifications: on the "matrix", I mean the matrix in the sense of the Matlab variable, i.e. a huge table of values ​​- not, say, a 4x4 transformation matrix, as you could use for 3D software. This data was collected over time, thousands and thousands of values ​​often many times per second. We are also not after a computer algebra system, but something where users can write complete plugins and write their own mathematics - although a system with the ability to process complex mathematics, like a computer algebra system, can be useful. I would take a “full language” over “algebra”, though if they don't mix to allow complex branches / paths in user code, as well as an OO interface.

+49
c ++ design api plugins delphi
Jun 01 2018-11-11T00:
source share
12 answers

According to your needs, here are some recommendations:

  • Make a distinction between a language and a library - you can have math languages ​​(like MATLAB) or math libraries written from a high-level language (like Python);
  • A language (or library) must be developed by mathematicians for mathematicians;
  • The language used must already exist (do not reinvent the wheel);
  • You should be able to exchange script content with existing software;
  • You should not start such a complex project (mathematical scripting) from scratch.

So, I think this can reduce the list of candidates:

  • JavaScript was not developed (not used) for such use;
  • Delphi scripts (DWS or PascalScript) were made primarily for automation and not for computation (and are widely used);
  • I don’t know why you are talking about using the Delphi IDE in a client application, but you should not use the Delphi IDE for such proprietary development: a primitive user IDE will be more productive than a full RAD;
  • Lua may need to be considered: you can do whatever you want with this script mechanism, but there is no huge community of mathematicians using Lua, unlike Python ...

In the open source world, you can find many very interesting solutions. See http://blog.interlinked.org/science/open_source_math_programs.html

I think Octave could be considered. It is simple, powerful, mature, well-known, used by many software tools and a cross-platform.

As far as I know, you can call the Octave library from C / C ++ code. This can be done from Delphi IMHO after translating the associated .h files.

But keep in mind the GPL license. If your software is proprietary, it is not possible to distribute Octave as part of your software. But you can name the Octave library or any other GPL materials (like Python) from your software if you clearly distinguish between your software and the GPL software .

Implementing Python can be a good solution. This language can be called from Delphi, and you should have a good architecture without the need to directly invoke some C libraries, such as Octave. Python can be your main gateway to all other computing libraries from your Delphi application. For example, Octave can be called from some Python libraries. And you can also use Python scripts to automate your application. And you have the Python IDE in Delphi around. Of course, an open source license for each component is secure. The more I think about it, the more I like this latest solution ...

Just my two cents. :)

+18
Jun 01 2018-11-11T00:
source share

There is no final answer, but a few other suggestions: -

  • Take a look at LMD Innovative ScriptPack , which supports native Pascal scripts, as well as ActiveScripting-based languages. Caution: I use a lot of LMD tools and components, but I personally have not used Scriptpack.

  • LMD also has an IDE-Tools package that can really simplify the task of creating a simple custom “RAD” tool if you need to go this route

  • Another vote for Lua. I used Lua as a script language in C ++ Builder2010 applications, and it works well. You can use C ++ Builder / Delphi RTTI to help integrate between Lua script and your C ++ code.

Re. Lua: We have a product that for many years has had an ultramodern "home" scripting system. There are no loops, conventions or procedures - just a sequence of parameterized commands. We wanted to extend this to something more powerful, and choosing a third-party solution seemed a lot less pain than reinventing the wheel. The main reasons for choosing Lua for this were: -

  • Fast
  • Published books available ( Lua Programming )
  • Written in C
  • Integrates directly into our project with static layout
  • MIT License
  • C ++ code can call Lua code and access Lua variables
  • Lua code can call C ++ functions
  • Small deployment size. Lua and standard libraries added up to 200K to our .EXE before compression.

I'm sure other languages ​​could be equally good, but it was the “light” character of Lua that knocked it over for me.

+7
Jun 03 2018-11-11T00:
source share

I like a lot of the answers there and, well, I am a biased Delphi developer :), but I would suggest you use a combination: RO Pascal Script + ESBPCS for VCL.

I don’t know if this looks like you, but I would go from him.

On the website, I extracted this link about the matrix non-visual part of the library. There are many more, you may want to give it away!

+5
Jun 03 2018-11-11T00:
source share

With Python, you get NumPy and SciPy “for free.” Yes, there is a GIL, but it is only active when your Python interpreter starts multiple threads. I believe that you can run multiple Python hosts in separate threads without problems (did not try, thought).

In addition, there are things like multiprocessing .

Python 3 still catches, NumPy started supporting Python 3 in version 1.5.0, and SciPy launched support in version 0.9.0.In addition, the GIL is still with Python 3, although it has been redone, so it should be better. NumPy also releases locks during operations.

+5
Jun 09 2018-11-11T00:
source share

We have successfully used Microsoft script automation (active scripts). Basically you need to implement a host that will run scripts. Scripts can be written in any language that is installed on the current computer. We use JavaScript for our scripts, but you are not limited to this. There are many script implementations (even python).

For your part, you will have to provide a framework for the script to run. Not simple, but with a basic understanding of COM it is also not difficult. There are versions made for Delphi. There are several resources here: http://www.torry.net/pages.php?id=280 , but you can find resources around the world.

Good luck

+4
Jun 01 2018-11-11T00:
source share

I would suggest Lua. This is one of the most used scripting languages, there are many tools such as debuggers, syntax-highlighted editors, etc. Many people have used it, it is one of the fastest scripting languages ​​that you can easily connect to ac / C ++. engine. It is very easy to extend C functions (especially if you use LuaJIT plus FFI). There is no really good way to multithread in lua, but you can easily run multiple instances of lua in separate threads to run multiple scripts.

+4
Jun 03 2018-11-11T00:
source share

Since you need a math-oriented scripting language, can I recommend you take a look at Common Lisp . This is a LISP dialect that was originally developed as a common mathematical notation for computer programs. Computer algebra systems such as Maxima and Axiom are written in Common Lisp. The most notable implementation of the Common List ECL , which is released under the LGPL license. Of course, there are many other open source implementations.

There is also a GNU Guile interpreter for the Schema programming language (Lisp dialect). Their site claims that

Guile is an efficient virtual machine that executes a portable instruction set created by its optimizing compiler and integrates very easily with C and C ++ application code. In addition to Scheme, Guile includes compilers for ECMAScript and Emacs Lisp (Lua support continues) ...

However, I have never used this library myself, so I cannot guarantee how easy it would be to embed it in your application.

+4
Jun 08 '11 at 15:53
source share

No one mentioned PaxCompiler , which can compile Pascal, Javascript and Basic into native code and can be easily configured to access objects in your Delphi projects. It has many advantages:

  • Compiled code will run faster than interpreted
  • It provides 3 different programming languages ​​so that almost any developer can feel at home.
  • As a Delphi developer, you have access to the source code and it is tightly integrated with your project.
  • The price is very interesting.

Disadvantages and problems for a popular project:

  • Make sure that 3 languages ​​are handled the same way: from my tests, it looks like JavaScript is lagging behind in sample size
  • If you decide to combine all 3 programming languages, you can provide almost all of your samples in all languages, and you will need to support all three of them.
+4
Jun 14 2018-11-11T00:
source share

I suggest you take a look at the wx-based GUI shell (C ++) around a classic open source math program called Maxima called wxMaxima on Windows. However, this is a GPL license, not an LGPL, so derivative work must also be open source.

You should be able to use this application and its algebra mechanism, and perhaps you could write your own Delphi shell for this C ++ UI around the MACSYMA / MAXIMA (LISP) mechanism. The source code for their system includes several things that you might also want to wrap and provide as a service:

  • A method of encoding mathematical equations in a display format from a user-entered format that is well defined and which can then be documented.

  • A simple “language” that you could use to compose your WYSIWYG equation tools.

Maxima can handle graphs, matrices, linear algebra and basic calculations, and the engine can be solid.

Since you already do a lot of things in C ++, I would think about making your WHOLE APPLICATION using wxWidgets, using wxMaxima as the base. I'm not sure that you can make wx + VCL hybrids in C ++ Builder, but you definitely have to try. If you can’t, I would say by making the main application in VC ++ using wxWidgets and creating plugins for it in Delphi (like DLLs).

enter image description here

+3
Jun 08 2018-11-11T00:
source share

My ideas:

+3
Jun 09 '11 at 18:29
source share

You mentioned that the audience is probably used for R. You should look at integrating your product with R, either as an extension of R, or to call R from your product. See Writing R-Extensions . , R- , R.

+3
10 . '11 2:07
source share

GIL python showstopper, , . , ​​, , , , python. Python ? script , -. , GIL , , .

+3
10 . '11 7:57
source share



All Articles