Re: a mathlink question

*To*: mathgroup at smc.vnet.net*Subject*: [mg89636] Re: a mathlink question*From*: David Bailey <dave at Remove_Thisdbailey.co.uk>*Date*: Mon, 16 Jun 2008 06:38:04 -0400 (EDT)*References*: <g32q5m$c2t$1@smc.vnet.net>

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. > Once loaded, your C code remains in memory - think of it as a set of functions, and of Mathematica as the main program. Therefore, all you need to do, is save information in static or file-scope variables, to be used on subsequent calls. You don't really want the C to keep executing - what would it typically do - what you want is for it to stay in memory, which it does. David Bailey http://www.dbaileyconsultancy.co.uk