1
$\begingroup$

Here is a piece of my code

using System;
using Wolfram.NETLink;

namespace ns_01_Wolfram
{
public class Test
{
    private IKernelLink ml;

    public Test()
    {
        ml = MathLinkFactory.CreateKernelLink();
        ml.WaitAndDiscardAnswer();

        // Map[Plus[1, #] &, {1, 2, 3}]
        byte[] array = { 1, 2, 3 };
        Expr exprMap = new Expr(ExpressionType.Symbol, "Map");        // Map
        Expr exprPlus = new Expr(ExpressionType.Symbol, "Plus");      // Plus
        Expr exprSharp = new Expr(ExpressionType.Symbol, "#");        // #
        Expr exprAnd = new Expr(ExpressionType.Symbol, "&");          // &
        Expr exprPlusParam = new Expr(exprPlus, 5, exprSharp);        // Plus[5,#]
        Expr exprPlusParamAnd = new Expr(exprPlusParam, exprAnd);     // !!! HERE I NEED => Plus[5,#] & <= INSTEAD OF => Plus[5,#] [&]
        Expr exprFinal = new Expr(exprMap, exprPlusParamAnd, array);  // Map[Plus[5,#] &, {1,2,3}]}
        String result = ml.EvaluateToOutputForm(exprFinal, 0);        // Result = {2, 3, 4}

On 3rd line from bottom I NEED TO GET {Plus[5,#] &} INSTEAD OF Plus[5,#] [&].

Any idea ?

$\endgroup$
  • $\begingroup$ I don't have experience with this but it seems you are building the pure function incorrectly. See FullForm@{Plus[5, #] &} $\endgroup$ – Kuba Oct 11 '17 at 17:14
  • $\begingroup$ I don't have experience with NET/Link, but when using MathLink from C, you can send an expression as a string. If the expression is constant, this is much easier than building it programmatically. $\endgroup$ – Szabolcs Oct 11 '17 at 17:50
  • $\begingroup$ Finally solved using Table[] instead of pure function. $\endgroup$ – Emilio Oct 13 '17 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.