[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*: [mg31905] Re: Trouble with Splice for Java (i.e. there is no JForm)
*From*: Albert Retey <albert.retey at visualanalysis.com>
*Date*: Tue, 11 Dec 2001 01:33:40 -0500 (EST)
*Organization*: Visual Analysis AG
*References*: <9uq9lu$afg$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
"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: coloring everything outside a circle**
Next by Date:
**Re: Backtrack**
Previous by thread:
**Trouble with Splice for Java (i.e. there is no JForm)**
Next by thread:
**Re: Trouble with Splice for Java (i.e. there is no JForm)**
| |