Google Группы больше не поддерживают новые публикации и подписки в сети Usenet. Опубликованный ранее контент останется доступен.

Cell["\<\ ... \>", ... ; TextData[...]

8 просмотров
Перейти к первому непрочитанному сообщению

kj

не прочитано,
15 дек. 2010 г., 07:51:1115.12.2010

When I examine the source code of Mathematica notebooks, I often
see Cell objects whose first argument is preceded by

"\<\

and followed by

\
\>"

E.g.

Cell["\<\
Yet another undocumented item.\
\>", "Text"...

What do these delimiters mean? And how do they differ from the
TextData symbol? (The latter is also undocumented, but at least
I've seen "cameo appearances" of it in the documentation.)

TIA!

~kj

Albert Retey

не прочитано,
16 дек. 2010 г., 05:53:2016.12.2010

there is something that is called short box form, which lets you enter
2d box input in just linear strings. I think it is nothing that you
would actually ever have need for and is mostly used just internally, at
least nowadays. I think there was some documentation about it in earlier
versions but I didn't find anything in newer versions (except for the
ShowShortBoxForm option). Instead of these cryptic forms you can almost
everywhere use the explicit Boxes-expressions, so I wonder why you are
interested in these?

hth,

albert

John Fultz

не прочитано,
16 дек. 2010 г., 05:53:4716.12.2010
Cell[_String] is equivalent to Cell[TextData[{_String}]] as far as the front end
is concerned. The former is just an abbreviation of the latter syntax, which is
necessarily used when the contents are more complex (e.g., contain styles or
buttons).

The \<\> business dates back to a hoarier day (in my opinion) in the design of
strings in Mathematica. Once upon a time, Mathematica had an odd interpretation
of newlines which I probably made more sense in the days of 80 character
terminal usage. You'll have to forgive me...my memory is fuzzy here, and I
don't have an old Mathematica text to double-check this from my current
location...but I believe the issue was something like this...

"abc\
d"

...with the newlines and spaces as shown, being equivalent to "abc d" (with just
the single space). The \<\> business forced everything inside the string to
really be interpreted literally, with backslash at the end of a line meaning to
simply escape the newline, and do nothing special to leading spaces. Since the
Mathematica notebook format generally wraps at about 70 characters, the
non-literal interpretation would have made the representation of more than 70
consecutive spaces difficult.

The modern Mathematica notebook format (introduced in 1996) was always made to
be interpreted properly as a Mathematica expression should you call Get[] on it
from the kernel. So this syntax was standardized, and is still used today.
Now, the kernel simply ignores the \<\> delimiters as you can see below:

In[1]:== StringLength["\<x\>"]

Out[1]== 1


Sincerely,

John Fultz
jfu...@wolfram.com
User Interface Group
Wolfram Research, Inc.


On Wed, 15 Dec 2010 07:51:11 -0500 (EST), kj wrote:
>
>
> When I examine the source code of Mathematica notebooks, I often
> see Cell objects whose first argument is preceded by
>
> "\<\
>
> and followed by
>
> \
> \>"
>
> E.g.
>
> Cell["\<\
> Yet another undocumented item.\
> \>", "Text"...
>
> What do these delimiters mean? And how do they differ from the
> TextData symbol? (The latter is also undocumented, but at least
> I've seen "cameo appearances" of it in the documentation.)
>

> TIA!
>
> ~kj


kj

не прочитано,
17 дек. 2010 г., 03:28:0117.12.2010

John, Albert, thanks for the info. Very useful.

In <iecr30$bn0$1...@smc.vnet.net> Albert Retey <aw...@gmx-topmail.de> writes:

>Instead of these cryptic forms you can almost
>everywhere use the explicit Boxes-expressions, so I wonder why you are
>interested in these?

Well, the simplest answer to that is that, in general, for all x,
if I don't know at all what x is, I have no way of knowing whether
x is something that would be useful (or harmful) to me.

A less flippant answer is this: even though I've been using
Mathematica on and off since the late 80s, I am still *routinely*
puzzled by its behavior. Not "a little puzzled", mind you, but
*utterly and absolutely mystified*, at least once, usually multiple
times per Mathematica sesssion. And I've spent countless of
frustrating hours trying to figure out some bewildering bug in my
Mathematica code. I happen to be quite familiar with several
programming languages and computing environments, and Mathematica
is the only one for which I have this problem after such a long
acquaintance. Therefore, I can't ascribe my difficulties with
Mathematica to my general stupidity, but to the fact that Mathematica
is basically an undocumented box of mysteries. What passes for
"documentation" in Mathematica is, in my opinion, just a few
carefully chosen scraps flung to us by Wolfram to keep appearances.
This is a longwinded explanation for why, over the years, I've
developed what can only be described as paranoia over anything that
the Mathematica documentation chooses to gloss over, based on the
belief (borne out of painful experience) that some time-devouring
bug in the future could hinge on one of these undocumented details.

I have already given up hope that Wolfram will document Mathematica
properly, but I still cling to the hope that someday I'll learn
the internal rationale for their "documentation" policies. That
remains for me the biggest mystery of all.

~kj

Derek Yates

не прочитано,
17 дек. 2010 г., 03:28:5417.12.2010
I did find a reference to this in some of the legacy Mathematica
(version 5.2) documentation.

2.8.7 Advanced Topic: Newlines and Tabs in Strings
http://reference.wolfram.com/legacy/v5_2/book/section-2.8.7

John Fultz mentioned that the kernel simply ignores the delimiters,
however I noticed that the kernel's interpretation of a raw string is
still affected. As he mentioned, it is essentially legacy, as the
front-end no longer inserts raw strings into cells the way the 5.2
documentation mentions, but you can still see the behaviour if you try
editing a Cell expression (Cell > Show Expression) as follows:

type a few characters (I entered qwerty) in an empty cell in the front-
end, and then do Cell > Show Expression, and you will see something
like this:
Cell[BoxData["qwerty"], "Input"]

replace it with:

Cell["qw
erty","Input"]

where you have put the new line in using the Return key. Now when you
revert the Show Expression, you will see

qw erty

in the cell.

If you edit the cell expression again so that it is
Cell["\<qw
erty\>","Input"]

Then you will see

qw
erty

in the cell.

Here is an excerpt from the documentation. Note that the example they
show does not work in new versions of Mathematica, but my example
above showed how to create it artificially.

"When you enter a long string in Mathematica, it is often convenient
to break your input across several lines. Mathematica will by default
ignore such breaks, so that if you subsequently output the string, it
can then be broken in whatever way is appropriate.

Mathematica ignores the line break and any tabs that follow it.
In[3]:= "A string on
two lines."

Out[3]= A string on two lines

There is no newline in the string.
In[4]:= InputForm[%]
Out[4]//InputForm=
"A string on two lines."

Input forms for strings:
"text" line breaks in text are ignored
"\<text\>" line breaks in text are stored explicitly as \n

Here Mathematica keeps the newline
In[5]:= "\<A string on
two lines.\>"

Out[5]=
A string on
two lines

In InputForm, the newline is shown as an explicit \n.
In[6]:= InputForm[%]

Out[6]//InputForm=
"a string on\ntwo lines."


kj

не прочитано,
20 дек. 2010 г., 00:40:4620.12.2010
In <ief706$po2$1...@smc.vnet.net> Derek Yates <yat...@me.com> writes:

>I did find a reference to this in some of the legacy Mathematica
>(version 5.2) documentation.

Derek, thanks for the added clarification, and for making me aware
of the availability of legacy Mathematica documentation. It may
come in handy.

~kj

0 новых сообщений