Search code examples
c#.netwolfram-mathematicamathlink

How to put options into functions in MathLink


This is sort of related to my earlier question, but different. I can't figure out how to give MathLink function options without using Evaluate(), etc. For example, I have the following C# code:

ml.PutFunction("Abs",1);
ml.PutFunction("Fourier",2);
ml.Put(data); //data = double[]
ml.Put("FourierParameters->{-1,1}");

It doesn't work. It puts the FourierParameters part as a literal string, and not an option. I tried creating an Expr with that string and putting that, but that failed too. Is this even possible to do in .NETLink?


Solution

  • Following this example page, seems the option must be entered with PutSymbol, and you need to add a "Rule" PutFunction.

    Resulting in something like (not tested):

    ml.PutFunction("EvaluatePacket", 1);
    ml.PutFunction("Abs",1);
    ml.PutFunction("Fourier",2);
    ml.Put(data); //data = double[]
    
    ml.PutFunction("Rule", 2);
    ml.PutSymbol("FourierParameters");
    ml.PutFunction("List", 2);
    ml.Put(-1); 
    ml.Put(1); 
    ml.EndPacket();