Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13682 > unrolled thread

Splice fails (Mathematica 9; Windows)

Started byAlan <alan.isaac@gmail.com>
First post2013-03-03 07:21 +0000
Last post2013-04-05 02:30 +0000
Articles 4 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Splice fails (Mathematica 9; Windows) Alan <alan.isaac@gmail.com> - 2013-03-03 07:21 +0000
    Re: Splice fails (Mathematica 9; Windows) Alan <alan.isaac@gmail.com> - 2013-03-06 03:13 +0000
    Re: Splice fails (Mathematica 9; Windows) a.a.almasy@gmail.com - 2013-04-03 08:07 +0000
      Re: Splice fails (Mathematica 9; Windows) Roland Franzius <roland.franzius@uos.de> - 2013-04-05 02:30 +0000

#13682 — Splice fails (Mathematica 9; Windows)

FromAlan <alan.isaac@gmail.com>
Date2013-03-03 07:21 +0000
SubjectSplice fails (Mathematica 9; Windows)
Message-ID<kgutm5$nsl$1@smc.vnet.net>
Clear[a, b, c]
a = b*c
file = "C:\\temp\\temp.mf";
Write[file, OutputForm["a = <* a *>"]];
Write[file, OutputForm["y = <* D[x^x,x] *>"]]
Close[file];
Splice[file];

produces as output

a = <* a *>
y = <* D[x^x,x] *>

Is Splice broken?

Thanks,
Alan Isaac

[toc] | [next] | [standalone]


#13723

FromAlan <alan.isaac@gmail.com>
Date2013-03-06 03:13 +0000
Message-ID<kh6c8j$b20$1@smc.vnet.net>
In reply to#13682
Can someone please try this on Matheaamtica 9 on Windows and confirm the file output?

Thanks,
Alan Isaac

[toc] | [prev] | [next] | [standalone]


#14036

Froma.a.almasy@gmail.com
Date2013-04-03 08:07 +0000
Message-ID<kjgo0g$pub$1@smc.vnet.net>
In reply to#13682
I have a similar problem. I am trying to Splice a file but all Mathematica would do is delete the two delimiters <* and *>. The code is:

MyFortranForm[exp_, name_] := Module[{rules, file, out, frm, form},
   rules = {};
   file = name <> ".mf";
   out = OpenWrite[file];
   WriteString[out, name <> " = <* form *> "];
   Close[out];
   form = 
    StringJoin @@ 
     Riffle[With[{splits = 
         StringSplit[ToString@FortranForm[exp //. rules], " "]}, 
       Fold[If[StringLength[Last@#1] + StringLength[#2] > 60, 
          Join[#1, {#2}], 
          Join[Most[#1], {StringJoin[Last[#1], #2]}]] &, {First@
          splits}, Rest[splits]]], "  &\n"] ;
   On[frm];
   Splice[name <> ".mf", PageWidth -> 120];
   FilePrint[name <> ".f"];
   Return[]
   ];

Now when I am using this on an expression:

MyFortranForm[A+B+C, "test"]

it returns:

test = form 

Does anyone has any ideas? I cannot find the problem. Internally form has the right form but it won't get sliced into the file.

Thanks,
Andrea

[toc] | [prev] | [next] | [standalone]


#14067

FromRoland Franzius <roland.franzius@uos.de>
Date2013-04-05 02:30 +0000
Message-ID<kjld0e$b76$1@smc.vnet.net>
In reply to#14036
Am 03.04.2013 10:07, schrieb a.a.almasy@gmail.com:
> I have a similar problem. I am trying to Splice a file but all Mathematica would do is delete the two delimiters <* and *>. The code is:
>
> MyFortranForm[exp_, name_] := Module[{rules, file, out, frm, form},
>     rules = {};
>     file = name <> ".mf";
>     out = OpenWrite[file];
>     WriteString[out, name <> " = <* form *> "];
>     Close[out];
>     form =
>      StringJoin @@
>       Riffle[With[{splits =
>           StringSplit[ToString@FortranForm[exp //. rules], " "]},
>         Fold[If[StringLength[Last@#1] + StringLength[#2] > 60,
>            Join[#1, {#2}],
>            Join[Most[#1], {StringJoin[Last[#1], #2]}]] &, {First@
>            splits}, Rest[splits]]], "  &\n"] ;
>     On[frm];
>     Splice[name <> ".mf", PageWidth -> 120];
>     FilePrint[name <> ".f"];
>     Return[]
>     ];
>
> Now when I am using this on an expression:
>
> MyFortranForm[A+B+C, "test"]
>
> it returns:
>
> test = form
>
> Does anyone has any ideas? I cannot find the problem. Internally form has the right form but it won't get sliced into the file.


Your output in StringWrite is the string
    name <> " = <* form *> "
You have to replace it by

name <> " = <*"<> form <>" *> "

and evaluate the construction part for <form>

   form = StringJoin @@
        Riffle[With[{splits = ..... ;

before writing, preferably outside the module as a definition

form[text_,rules_]:=  StringJoin @@
        Riffle[With[{splits = ..... ;

-- 

Roland Franzius

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web