|
[Date Index]
[Thread Index]
[Author Index]
Re: Trouble with Splice for Java (i.e. there is no JForm)
- To: mathgroup at smc.vnet.net
- Subject: [mg31938] Re: Trouble with Splice for Java (i.e. there is no JForm)
- From: "Robert Nowak" <robert.nowak at ims.co.at>
- Date: Thu, 13 Dec 2001 01:08:42 -0500 (EST)
- References: <9uq9lu$afg$1@smc.vnet.net> <9v49e4$n0p$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
you forgot ToString[]
actually you need
StringReplace[ToString[CForm[ yourexpression ]],"Power"->"Math.pow"]
Regards Robert
--
---
Robert Nowak (robert.nowak at ims.co.at)
IMS Nanofabrication GmbH
A-1020 Wien, Schreygasse 3, Austria
Phone: (+43 1)2144894-32, Fax: (+43 1)2144894-99
"Albert Retey" <albert.retey at visualanalysis.com> wrote in message
news:9v49e4$n0p$1 at smc.vnet.net...
> "Matthew D. Langston" wrote:
> >
> > Hello all,
> >
> > I can't figure out how to output Java language constructs using Splice,
like
> > I can for Fortran and C/C++ files.
> >
> > For example, here is how x^2 is represented in different languages:
> >
> > C/C++ : Power(x,2)
> > Fortran: x**2
> > TeX : x^2
> > Java : Math.pow(x,2)
> >
> > Since there is no JForm command in Mathematica, I have been trying to
use
> > CForm. However, I can't figure out how to output the Java syntax. If
I
> > try something like this:
> >
> > x^2/.Power->Math.pow
> >
> > then the CForm comes out like this:
> >
> > Dot(Math,pow)(x,2)
> >
> > If I try something like this:
> >
> > x^2/.Power->"Math.pow"
> >
> > then the CForm comes out like this:
> >
> > "Math.pow"(x,2)
> >
> > Can someone help me understand how to get x^2 to output as Math.pow(x,2)
> > please? Thank you.
>
> StringReplace[CForm[ yourexpression ],"Power"->"Math.pow"]
>
> should do what you want. If your expression is huge and the above
> command is slow you can use any other system that can do efficient
> string replacements (e.g. perl, sed,...) for the task...
>
> An alternative would be to define your own Output Format for Power, but
> that would probably get more complicated.
>
> Hope that helps.
>
> Albert
>
Prev by Date:
Re: Re: scope all wrong? in Mathematica 4.1
Next by Date:
symbolic calculations with complex numbers
Previous by thread:
Re: Trouble with Splice for Java (i.e. there is no JForm)
Next by thread:
Fit[] versus Regress[] inconsistent behahiour
|