This looks quite interesting. Since I don't have the time to delve into it right now, would you mind answering a few questions?
Do I understand it right that this is syntactic sugar for putting expressions onto a MathLink/WSTP link?
Does it only work with wstp.h
or also mathlink.h
? I believe LibraryLink (which is usually the best way to extend Mma) still requires MathLink and won't work with the WSTP headers. I might be wrong though as I have not investigated this in 11.3.
Based on the example you posted, it would appear that you implemented an independent way to store Mma expressions. These expressions are built at runtime, then sent to the link. Is this correct? If yes, what is the overhead from building them at runtime?
I was always wondering if it was possible to use some C++ template magic to do the same at compile time, i.e. create convenient syntax that effectively translates directly to MathLink code. E.g. something like
link << expr("Plus", 42, expr("Times", 2, symbol("x"));
would directly translate to the equivalent of
MLPutFunction(link, "Plus", 2);
MLPutInteger(link, 42);
MLPutFunction(link, "Times", 2);
MLPutInteger(link, 2);
MLPutSymbol(link, "x");
at compile time without the need to build an intermediate representation at runtime.
It is not clear to me if it is technically possible to do something like this. Have you seen the mlstream
header of my LTemplate tool? It would be a lovely extension. Currently, mlstream
handles putting/getting basic types (including arrays), with a focus on performance. It does not handle generic expressions.
While we're at the topic of performance, does it handle large numerical array efficiently, e.g. MLPutReal64List
or MLPutReal64Array
?