Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 2 characters in body
Source Link
Shredderroy
  • 5.4k
  • 18
  • 28

I am trying to call Mathematica 10 from F#. Following the C# sample code found in the Mathematica directory, I have written the following F# code:

type TestClass() =
    member this.AddNumsWithWM (m : int) (n : int) : int =
        let ml = MathLinkFactory.CreateKernelLink()
        ml.WaitAndDiscardAnswer()
        ml.PutFunction("EvaluatePacket", 1)
        ml.PutFunction("testWMFunc""testFunc", 2) // IF BUILT-IN FUNCTION LIKE Plus, THEN NO ERROR
        ml.Put(m)
        ml.Put(n)
        ml.EndPacket()
        ml.WaitForAnswer() |> ignore
        let res = ml.GetInteger() // THE ERROR OCCURS HERE FOR CUSTOM FUNCTION
        ml.Close()
        res

The Mathematica function testFunc is simply:

testFunc[m_Integer, n_Integer] := m + 2 * n;

But when I call the function AddNumsWithWM 2 3, I get the following error at the line indicated above:

Wolfram.NETLink.MathLinkException was unhandled
Message: An unhandled exception of type 'Wolfram.NETLink.MathLinkException' occurred in Wolfram.NETLink.dll
Additional information: Error code: 3.

I don't understand, because the sample C#, from which this has been translated literally, works. Any idea why I would get the above error?

Thanks in advance for your help.

EDIT

I have verified something else. If I use a built-in function like Plus instead of my custom function testFunc, the code works.

So, then, I guess my question would be, Why does the code not work for a custom function? I would be very grateful for pointers on what I need to do differently in order to call a custom function.

I have edited the question accordingly.

I am trying to call Mathematica 10 from F#. Following the C# sample code found in the Mathematica directory, I have written the following F# code:

type TestClass() =
    member this.AddNumsWithWM (m : int) (n : int) : int =
        let ml = MathLinkFactory.CreateKernelLink()
        ml.WaitAndDiscardAnswer()
        ml.PutFunction("EvaluatePacket", 1)
        ml.PutFunction("testWMFunc", 2) // IF BUILT-IN FUNCTION LIKE Plus, THEN NO ERROR
        ml.Put(m)
        ml.Put(n)
        ml.EndPacket()
        ml.WaitForAnswer() |> ignore
        let res = ml.GetInteger() // THE ERROR OCCURS HERE FOR CUSTOM FUNCTION
        ml.Close()
        res

The Mathematica function testFunc is simply:

testFunc[m_Integer, n_Integer] := m + 2 * n;

But when I call the function AddNumsWithWM 2 3, I get the following error at the line indicated above:

Wolfram.NETLink.MathLinkException was unhandled
Message: An unhandled exception of type 'Wolfram.NETLink.MathLinkException' occurred in Wolfram.NETLink.dll
Additional information: Error code: 3.

I don't understand, because the sample C#, from which this has been translated literally, works. Any idea why I would get the above error?

Thanks in advance for your help.

EDIT

I have verified something else. If I use a built-in function like Plus instead of my custom function testFunc, the code works.

So, then, I guess my question would be, Why does the code not work for a custom function? I would be very grateful for pointers on what I need to do differently in order to call a custom function.

I have edited the question accordingly.

I am trying to call Mathematica 10 from F#. Following the C# sample code found in the Mathematica directory, I have written the following F# code:

type TestClass() =
    member this.AddNumsWithWM (m : int) (n : int) : int =
        let ml = MathLinkFactory.CreateKernelLink()
        ml.WaitAndDiscardAnswer()
        ml.PutFunction("EvaluatePacket", 1)
        ml.PutFunction("testFunc", 2) // IF BUILT-IN FUNCTION LIKE Plus, THEN NO ERROR
        ml.Put(m)
        ml.Put(n)
        ml.EndPacket()
        ml.WaitForAnswer() |> ignore
        let res = ml.GetInteger() // THE ERROR OCCURS HERE FOR CUSTOM FUNCTION
        ml.Close()
        res

The Mathematica function testFunc is simply:

testFunc[m_Integer, n_Integer] := m + 2 * n;

But when I call the function AddNumsWithWM 2 3, I get the following error at the line indicated above:

Wolfram.NETLink.MathLinkException was unhandled
Message: An unhandled exception of type 'Wolfram.NETLink.MathLinkException' occurred in Wolfram.NETLink.dll
Additional information: Error code: 3.

I don't understand, because the sample C#, from which this has been translated literally, works. Any idea why I would get the above error?

Thanks in advance for your help.

EDIT

I have verified something else. If I use a built-in function like Plus instead of my custom function testFunc, the code works.

So, then, I guess my question would be, Why does the code not work for a custom function? I would be very grateful for pointers on what I need to do differently in order to call a custom function.

I have edited the question accordingly.

Tweeted twitter.com/#!/StackMma/status/512076639938035712
added 29 characters in body
Source Link
halirutan
  • 113.4k
  • 7
  • 266
  • 479
type TestClass() =
    member this.AddNumsWithWM (m : int) (n : int) : int =
        let ml = MathLinkFactory.CreateKernelLink()
        ml.WaitAndDiscardAnswer()
        ml.PutFunction("EvaluatePacket", 1)
        ml.PutFunction("testWMFunc", 2) // IF BUILT-IN FUNCTION LIKE Plus, THEN NO ERROR
        ml.Put(m)
        ml.Put(n)
        ml.EndPacket()
        ml.WaitForAnswer() |> ignore
        let res = ml.GetInteger() // THE ERROR OCCURS HERE FOR CUSTOM FUNCTION
        ml.Close()
        res
type TestClass() =
    member this.AddNumsWithWM (m : int) (n : int) : int =
        let ml = MathLinkFactory.CreateKernelLink()
        ml.WaitAndDiscardAnswer()
        ml.PutFunction("EvaluatePacket", 1)
        ml.PutFunction("testWMFunc", 2) // IF BUILT-IN FUNCTION LIKE Plus, THEN NO ERROR
        ml.Put(m)
        ml.Put(n)
        ml.EndPacket()
        ml.WaitForAnswer() |> ignore
        let res = ml.GetInteger() // THE ERROR OCCURS HERE FOR CUSTOM FUNCTION
        ml.Close()
        res
type TestClass() =
    member this.AddNumsWithWM (m : int) (n : int) : int =
        let ml = MathLinkFactory.CreateKernelLink()
        ml.WaitAndDiscardAnswer()
        ml.PutFunction("EvaluatePacket", 1)
        ml.PutFunction("testWMFunc", 2) // IF BUILT-IN FUNCTION LIKE Plus, THEN NO ERROR
        ml.Put(m)
        ml.Put(n)
        ml.EndPacket()
        ml.WaitForAnswer() |> ignore
        let res = ml.GetInteger() // THE ERROR OCCURS HERE FOR CUSTOM FUNCTION
        ml.Close()
        res
type TestClass() =
    member this.AddNumsWithWM (m : int) (n : int) : int =
        let ml = MathLinkFactory.CreateKernelLink()
        ml.WaitAndDiscardAnswer()
        ml.PutFunction("EvaluatePacket", 1)
        ml.PutFunction("testWMFunc", 2) // IF BUILT-IN FUNCTION LIKE Plus, THEN NO ERROR
        ml.Put(m)
        ml.Put(n)
        ml.EndPacket()
        ml.WaitForAnswer() |> ignore
        let res = ml.GetInteger() // THE ERROR OCCURS HERE FOR CUSTOM FUNCTION
        ml.Close()
        res
added 19 characters in body
Source Link
Shredderroy
  • 5.4k
  • 18
  • 28

I am trying to call Mathematica 10 from F#. Following the C# sample code found in the Mathematica directory, I have written the following F# code:

type TestClass() =
    member this.AddNumsWithWM (m : int) (n : int) : int =
        let ml = MathLinkFactory.CreateKernelLink()
        ml.WaitAndDiscardAnswer()
        ml.PutFunction("EvaluatePacket", 1)
        ml.PutFunction("testWMFunc", 2) // IF BUILT-IN FUNCTION LIKE Plus, THEN NO ERROR
        ml.Put(m)
        ml.Put(n)
        ml.EndPacket()
        ml.WaitForAnswer() |> ignore
        let res = ml.GetInteger() // THE ERROR OCCURS HERE! FOR CUSTOM FUNCTION
        ml.Close()
        res

The Mathematica function testFunc is simply:

testFunc[m_Integer, n_Integer] := m + 2 * n;

But when I call the function AddNumsWithWM 2 3, I get the following error at the line indicated above:

Wolfram.NETLink.MathLinkException was unhandled
Message: An unhandled exception of type 'Wolfram.NETLink.MathLinkException' occurred in Wolfram.NETLink.dll
Additional information: Error code: 3.

I don't understand, because the sample C#, from which this has been translated literally, works. Any idea why I would get the above error?

Thanks in advance for your help.

EDIT

I have verified something else. If I use a built-in function like Plus instead of my custom function testFunc, the code works.

So, then, I guess my question would be, Why does the code not work for a custom function? I would be very grateful for pointers on what I need to do differently in order to call a custom function.

I have edited the question accordingly.

I am trying to call Mathematica 10 from F#. Following the C# sample code found in the Mathematica directory, I have written the following F# code:

type TestClass() =
    member this.AddNumsWithWM (m : int) (n : int) : int =
        let ml = MathLinkFactory.CreateKernelLink()
        ml.WaitAndDiscardAnswer()
        ml.PutFunction("EvaluatePacket", 1)
        ml.PutFunction("testWMFunc", 2) // IF BUILT-IN FUNCTION LIKE Plus, THEN NO ERROR
        ml.Put(m)
        ml.Put(n)
        ml.EndPacket()
        ml.WaitForAnswer() |> ignore
        let res = ml.GetInteger() // THE ERROR OCCURS HERE!
        ml.Close()
        res

The Mathematica function testFunc is simply:

testFunc[m_Integer, n_Integer] := m + 2 * n;

But when I call the function AddNumsWithWM 2 3, I get the following error at the line indicated above:

Wolfram.NETLink.MathLinkException was unhandled
Message: An unhandled exception of type 'Wolfram.NETLink.MathLinkException' occurred in Wolfram.NETLink.dll
Additional information: Error code: 3.

I don't understand, because the sample C#, from which this has been translated literally, works. Any idea why I would get the above error?

Thanks in advance for your help.

EDIT

I have verified something else. If I use a built-in function like Plus instead of my custom function testFunc, the code works.

So, then, I guess my question would be, Why does the code not work for a custom function? I would be very grateful for pointers on what I need to do differently in order to call a custom function.

I have edited the question accordingly.

I am trying to call Mathematica 10 from F#. Following the C# sample code found in the Mathematica directory, I have written the following F# code:

type TestClass() =
    member this.AddNumsWithWM (m : int) (n : int) : int =
        let ml = MathLinkFactory.CreateKernelLink()
        ml.WaitAndDiscardAnswer()
        ml.PutFunction("EvaluatePacket", 1)
        ml.PutFunction("testWMFunc", 2) // IF BUILT-IN FUNCTION LIKE Plus, THEN NO ERROR
        ml.Put(m)
        ml.Put(n)
        ml.EndPacket()
        ml.WaitForAnswer() |> ignore
        let res = ml.GetInteger() // THE ERROR OCCURS HERE FOR CUSTOM FUNCTION
        ml.Close()
        res

The Mathematica function testFunc is simply:

testFunc[m_Integer, n_Integer] := m + 2 * n;

But when I call the function AddNumsWithWM 2 3, I get the following error at the line indicated above:

Wolfram.NETLink.MathLinkException was unhandled
Message: An unhandled exception of type 'Wolfram.NETLink.MathLinkException' occurred in Wolfram.NETLink.dll
Additional information: Error code: 3.

I don't understand, because the sample C#, from which this has been translated literally, works. Any idea why I would get the above error?

Thanks in advance for your help.

EDIT

I have verified something else. If I use a built-in function like Plus instead of my custom function testFunc, the code works.

So, then, I guess my question would be, Why does the code not work for a custom function? I would be very grateful for pointers on what I need to do differently in order to call a custom function.

I have edited the question accordingly.

added 344 characters in body
Source Link
Shredderroy
  • 5.4k
  • 18
  • 28
Loading
Source Link
Shredderroy
  • 5.4k
  • 18
  • 28
Loading