In C / C++ languages one can use macros or as called "per-processor directives" to instruct the compiler how the code should be read. The simple commands of #def
, #ifdef
, #ifndef
, #else
, #endif
... give the compiler the ability to check for Operating system, compiler and other environment information. I know Octave and Scilab are interpreted languages, but I'm wondering if is there any way to tell the interpreter to replaces parts of script while loading it? For example can I write a code which is commented based on Scilab syntax //
and then instruct the interpreter to read them as Octave's commenting sytax as #
or %
? This seems to be one of the main issues for Scilab Octave inter compatibility.
If there is a way to instruct the interpreters to check for the interpreter's info Scilab/ScicoLab/Octave/FreeMat,Julia... and the version... and then based on that information there are some #ifdef
#endif
blocks... then one can write a code which is compatible with multiple of the above interpreters. I would appreciate if you could let me know if load time directives are possible, and if not if/how one can write code which is compatible with both Octave and Scilab?
P.S.1 Different approaches are:
- to have conventional
if then elseif else end
statements including a valid syntax across different interpreters with distinctive results. as suggested in the answers below. - use
gets
,exec
,execstr
from the Scilab side to load the.m
files. Some regex could be done to clean the code. Octave does have the xml like#<include>...</include>
- to have a tailor made
import
function like this one made to import MATLAB code into Octave
P.S.2 Octave has the version()
function, Scilab /ScicosLab have getversion()
, Julia has versioninfo
and VERSION
, FreeMat
also has the version
function. maybe that could also be used.
P.S.3 there is already Matlab/Octave Compatibility toolbox for scilab. And there is also Sci cosim to import variables from Scilab workspace into Octave using TCP port.