开发者

How to put options into functions in MathLink

开发者 https://www.devze.com 2023-03-02 15:35 出处:网络
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:

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?


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();


I would do this using high level wrappers. For example, one could write a Mathematica function called MyFunction, using all the conveniences of Mathematica, that calls one of several low level, mathlink functions say myFunction1, myFunction2, etc. Which mathlink function to call would be based on standard option handling techniques within Mathematica.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号