MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Differential equations error with MathLink/JLink

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28053] Re: Differential equations error with MathLink/JLink
  • From: Ralph Gauges <ralph.gauges at eml.villa-bosch.de>
  • Date: Thu, 29 Mar 2001 03:24:18 -0500 (EST)
  • References: <98vh54$8sr@smc.vnet.net> <99chhr$8bi@smc.vnet.net> <99hcmk$eb8@smc.vnet.net> <%nEv6.8240$uR4.70938@ralph.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Todd Gayley wrote:

> Ralph,
>
> You cannot necessarily use MLGetFunction() to read what's on the link just because
> MLGetNext() returned MLTKFUNC. MLGetFunction() only works for functions with symbols as
> their head. You can write a function that does not have a symbol as its head, and a
> classic case is
>
>      Derivative[1][x][t]
>
> which is, coincidentally, exactly the return value of your computation. This expression is
> a function of one argument (t), with Derivative[1][x] as its head. (Note that this head is
> itself a function with a function, not a symbol, as _its_ head.)
>
> If you want to be able to read arbitrary expressions off a link, your handling of MLTKFUNC
> has to look like this:
>
>     if (MLGetNext(link) == MLTKFUNC) {
>         long argCount;
>         MLGetArgCount(link, &argCount);
>         // Read the head, first by checking MLGetNext() and then the correct get call
>         for (int i = 0; i < argCount; i++) {
>             // Read the args
>         }
>     }
>
> Take a look at the read_and_print_expression() function in the MathLink example program
> factor2.c to see general-purpose expression-reading code.
>
> This complexity is one reason why the Expr class in J/Link is so useful.

Yes, it really is, I like JLink, but I don't want to switch to Java right now.
Thank you very much for the hint. I will try to change the function reading method to something
that resembles this general purpose expression reading code in factor2.c,
Will there be a function for reading expressions in upcoming MathLink Versions, or even an
Expression class?


>
>
> One more thing. MLGetNext() is a destructive call--it advances the link position. You got
> MLTKFUNC twice in your example because the expression is a function, and its head also
> happens to be a function. In other words, the second time you called MLGetNext(), you were
> reading a new part of the result, not just reaffirming the first call.
>

I had feared that this might be the case, but since it was not the cause for the original error,
I did not investigate further.
Shame on me, I actually did read the manual, but at least the part in the mathematica book is
kept rather short considering dummies like myself.  )-:
For example it doesn't state anywhere that you can only use MLGetFunction when the head of the
function is a symbol! From the manual I assumed that when GetNext tells you that the next thing
will be a MLTKFUNC, you use MLGetFunction.
Sorry for having bothered you. Is there an more indepth API Documentation somewhere on the net,
something like the API for java would be nice?

Bye

Ralph



  • Prev by Date: Re: Sums
  • Next by Date: RE: Memory leak
  • Previous by thread: Re: Differential equations error with MathLink/JLink
  • Next by thread: Re: how to write output to another notebook?