Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Mathematica supports an exact list of compilable functions:

They are listed here: List of compilable functions.

However, I would need to add the following functions: ToExpression, StringFreeQ, StringReplace, BinaryRead and BinaryWrite...

Is it possible?

I know that BinaryRead and BinaryWrite have simple C++ equivalents but how can I add this functionality to the Compile function?

Furthermore, Compile only accepts Integer, Floats and Lists and Nested Lists as input. Can it be modified to accept Strings?

Could reimplementing the Compile Function work?

share|improve this question
1  
These functions can be used in Compile and can be part of a compiled functions. However, when they're run, the byte-code interpreter will fall back to standard evaluation which mean that these functions won't get a performance boost from compilation. The rest of your program will get a performance icrease, just not these particular functions. –  Szabolcs May 29 at 18:48
    
Does the standard evaluation call the MathKernel or can the generated code be used standalone? Can I also add support for strings or would a string be a Integer list representing ASCII codes? –  user13675 May 29 at 20:25
    
It calls MathKernel. I'm not sure how exactly LibraryLink functions interact with compiled functions. It may be possible to implement these I/O functions using LibraryLink to make it possible to integrate them into a standalone program. Unfortunately I don't have experience translating Mma into standalone C code (though the docs suggest it's possible to an extent), so I'll leave this for others to answer ... –  Szabolcs May 29 at 20:27

1 Answer 1

As far as I know there is no way to extend the Compile system in the way you describe, but you can often work around specific problems. For example, for handling strings you can write an outer function that converts strings to a packed vector of integers using ToCharacterCode, then pass this to your compiled function. However, I would encourage you not to take this approach as the string tools already make use of compiled libraries (including PCRE).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.