Re: a mathlink question
- To: mathgroup at smc.vnet.net
- Subject: [mg89652] Re: a mathlink question
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Mon, 16 Jun 2008 06:41:18 -0400 (EDT)
- Organization: Uni Leipzig
- References: <g32q5m$c2t$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
Hi,
something like:
#include "mathlink.h"
static int prev=0;
void add_to_previous_sum(int x) {
prev+=x;
return prev;
}
:Begin:
:Function: add_to_previous_sum
:Pattern: AddToPreviousSum[x_Interger]
:Arguments: {x}
:ArgumentType: {Integer}
:ReturnType: Integer
:End:
int main(int argc, char *argv[]) {
return MLMain(argc,argv);
}
Regards
Jens
GS wrote:
> I would like to call a C-program from Mathematica. All the examples in
> the MathLink tutorials (like AddTwo[i,j]) work like this: they are
> called from Mathematica, are executed, send the result to Mathematica
> and exit.
>
> I would like a C-program to not exit after the execution, and keep the
> memory of the previous inputs. Say, I want an external C-program, to
> be called as AddToPreviousSum[x]. When it is first called, it returns
> x. When it is called the second time AddToPreviousSum[y], it returns x
> +y. When it is called the third time AddToPreviousSum[z], it returns x
> +y+z, and so on.
>
> How do I implement this in C using MathLink?
>
> Thanks.
> GS.
>