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


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

Re: Print bug with -script? (quotes display)

Started byPatrick Scheibe <pscheibe@trm.uni-leipzig.de>
First post2011-09-05 11:17 +0000
Last post2011-09-07 09:47 +0000
Articles 5 — 2 participants

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Print bug with -script? (quotes display) Patrick Scheibe <pscheibe@trm.uni-leipzig.de> - 2011-09-05 11:17 +0000
    Re: Print bug with -script? (quotes display) Alan <alan.isaac@gmail.com> - 2011-09-06 07:59 +0000
    Re: Print bug with -script? (quotes display) Alan <alan.isaac@gmail.com> - 2011-09-06 08:00 +0000
    Re: Print bug with -script? (quotes display) Alan <alan.isaac@gmail.com> - 2011-09-06 08:07 +0000
    Re: Print bug with -script? (quotes display) Patrick Scheibe <pscheibe@trm.uni-leipzig.de> - 2011-09-07 09:47 +0000

#4758 — Re: Print bug with -script? (quotes display)

FromPatrick Scheibe <pscheibe@trm.uni-leipzig.de>
Date2011-09-05 11:17 +0000
SubjectRe: Print bug with -script? (quotes display)
Message-ID<j42b57$rsl$1@smc.vnet.net>
Hi,

same here in Linux but I don't consider this as a bug. It's just that
the Mathematica frontend usually displays strings without the quotes: 

{DisplayForm[#], InputForm[#], FullForm[#]} &["Hello you"]


In console script mode this seems to get lost. Isn't there in Vista a
way to write directly to the stdout-stream? Here, something like

PrintToConsole[str_String]:=WriteString[OutputStream["stdout",1],str<>"\n"];
PrintToConsole[obj_]:=PrintToConsole[ToString[obj]];

PrintToConsole["Sheldor is back online"];

can be used. Maybe you want to check the output of Streams[] on your
system.

Hope this helps.

Cheers
Patrick

On Sun, 2011-09-04 at 18:06 -0400, Alan wrote:
> I am using Mathematica under Windows Vista.  To run Mathematica commands as a script, my understanding is that I should invoke
>     math.exe -script <scriptname>
> This is working, but if I print a string
>     Print["Test"]
> it prints surrounded by quotes (as written literally).
> I find this highly undesirable: can the quotes be suppressed?
> 
> Also, this behavior seems to conflict with the documentation:
> http://reference.wolfram.com/mathematica/tutorial/PropertiesOfStrings.html 
> 
> Is it a bug?
> 
> Thanks,
> Alan Isaac
> 


[toc] | [next] | [standalone]


#4774

FromAlan <alan.isaac@gmail.com>
Date2011-09-06 07:59 +0000
Message-ID<j44jsf$91c$1@smc.vnet.net>
In reply to#4758
On Monday, September 5, 2011 7:17:59 AM UTC-4, Patrick Scheibe wrote:
> I don't consider this as a bug. It's just that
> the Mathematica frontend usually displays strings without the quotes: 


I'm not sure I follow.

Can you name another language where printing a string
to standard out will print the delimiters used to
create a string literal?  I cannot.  This is at least
unexpected, and I suspect is should be considered a bug.
Can you make an argument that a user should expect InputForm
rather than DisplayForm when printing to standard out
(i.e., when using the -script option)?

Btw, you cannot just convert to DisplayForm to Print the string;
that does not work at the console.  In short, the behavior of
Print is quite odd, unexpected, and I claim buggy when running
with the -script option.  (But I'm new to Mathematica and willing to
listen to reasons for this surprising behavior.)

Related: I do not understand why one must use ToString
on a StringForm when printing it in a console script.  The
behavior in a notebook is what is expected, and imo it should
be what one sees at the console.

If I understand correctly, the -script option is new, and it looks
like not enough of the Mathematica output behavior has been adjusted to
this flag.

Alan Isaac

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


#4776

FromAlan <alan.isaac@gmail.com>
Date2011-09-06 08:00 +0000
Message-ID<j44juc$930$1@smc.vnet.net>
In reply to#4758
On the other hand, it is hard to call it a bug when the behavior is documented:
http://reference.wolfram.com/mathematica/ref/program/math.html

"In a script mode the kernel prints no banner and no In or Out labels, and generates all output in InputForm, with the PageWidth option effectively set to Infinity."

So I should be more careful and say that I hope Wolfram will reconsider the behavior of Print in scripts: current behavior is surprising and undesirable.

Alan Isaac

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


#4790

FromAlan <alan.isaac@gmail.com>
Date2011-09-06 08:07 +0000
Message-ID<j44kbq$96k$1@smc.vnet.net>
In reply to#4758
Someone wrote:
> Unprotect[Print]; Print[s_String]:=WriteString["stdout",s];


Yes, that seems to work.

Thanks,
Alan

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


#4808

FromPatrick Scheibe <pscheibe@trm.uni-leipzig.de>
Date2011-09-07 09:47 +0000
Message-ID<j47eju$l5d$1@smc.vnet.net>
In reply to#4758
Hi,

> Can you name another language where printing a string
> to standard out will print the delimiters used to
> create a string literal?  I cannot.

What you forget is that in other languages usually *only* strings get
printed. When you need to print a number you have to convert it to a
string. In Mathematica you print *Expressions* which is why you can do 

Print[Sqrt[3]]

or

Print[Image[{{0, 1}, {1, 0}}]]

in a notebook. Did you ever complain about that? If you try these two
examples in console-mode you get different results.

> (But I'm new to Mathematica and willing to
> listen to reasons for this surprising behavior.)

The surprising behavoir I see is that in console-mode (you open a
console, type "math" and get an interactive Mathematica session) you can
of course do Print["hello"] and you get the hello without quotes.
I assume one has just to accept that console-mode makes more formating
than the -script mode. Look at Print[1/2]. In console-mode you get a
nice rational form, in -script mode just the 1/2 is printed.

Look at the bright side: Although very surprising, it can be fixed for
you with one simple line of code.

Cheers
Patrick  

[toc] | [prev] | [standalone]


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


csiph-web