16
$\begingroup$

I have never seen an example use for the mysterious Raw function:

Raw[h, "hexstring"]
constructs a raw data object with head h, and with contents corresponding to the binary bit pattern represented by the string hexstring, interpreted as a hexadecimal number.

The documentation also makes clear that it must be used carefully:

  • Raw should be used only under very special circumstances.

  • It is possible to crash Mathematica by creating a fundamental Mathematica data object with Raw, and specifying illegal internal data for it. If you create an object with head Real, but with internal data incompatible with Mathematica Real numbers, you may end up crashing your whole Mathematica session.

In fact it also states: As of Version 6.0, Raw is no longer supported. Pre-v6.0 documentation gives some indication of application, no details, and more admonition:

As an optimization for some special kinds of computations, the raw data in Mathematica atomic objects can be given explicitly using Raw[head, "hexstring"]. The data is specified as a string of hexadecimal digits, corresponding to an array of bytes. When no special output form exists, InputForm prints special objects using Raw. The behavior of Raw differs from one implementation of Mathematica to another; its general use is strongly discouraged.

Nevertheless I regularly find use for other deprecated functions such as Compose and ToHeldExpression, and I am curious. How can one use this function?

$\endgroup$
10
  • $\begingroup$ Is Raw related to RawArray? Whenever I look at the FullForm of an image, it starts with: Image[RawArray["Byte", List[List[List[101, 133, 184],... $\endgroup$
    – bill s
    Commented Jan 23, 2014 at 19:34
  • $\begingroup$ @bills I believe that was added after version 7, which I use, so I don't know. $\endgroup$
    – Mr.Wizard
    Commented Jan 23, 2014 at 19:37
  • $\begingroup$ When I try ?Raw* there are several entries (ver. 9): Raw, RawArray, RawBoxes, RawData, and RawMedium. All seem equally opaque! $\endgroup$
    – bill s
    Commented Jan 23, 2014 at 19:40
  • $\begingroup$ My naive guess is that this may have been useful for exchanging data with other programs through MathLink. E.g. you write a C program that uses a special data structure that Mathematica itself will never use directly, only indirectly through calling your C program. However, it is still useful to be able to store this data in Mathematica (and not just some kind of handle to the data structure that exists solely in the memory of the other process). It might be useful for this. All this is a naive guess and it was probably used for something very different ... $\endgroup$
    – Szabolcs
    Commented Jan 23, 2014 at 20:39
  • $\begingroup$ Another idea for why one would want to keep some data that can only be handled by a C program in the Mathematica kernel's memory: if you choose to manage the data on the C side, and only send handles to Mathematica, then on the Mathematica side you need to handle creation and destruction of these data structures explicitly. This is unusual and inconvenient for a high level language like Mma. This is exactly what happens in TetGenLink: there's TetGenCreate and TetGenDelete. On the other hand, most complex data structures are likely to rely on pointers, so they will need ... $\endgroup$
    – Szabolcs
    Commented Jan 23, 2014 at 20:53

1 Answer 1

8
$\begingroup$

The short answer is, you can't. The only function that can really consume these objects is not exposed at the language level but only in the kernel's own C code. To be honest, am not sure why it is even in the system. My best guess is that there a few obscure case where it might be generated by internal code. Given that we don't even document it anymore (not even as Obsolete), I think that's a sign of its place in the system.

RawBoxes is a compeltey unrelated function, which is documented. You can think of it as the modern replacement for DisplayForm, which only deals with boxes and has no confusing heuristics.

RawData (also documented) is a representation of a cell after using "Show Cell Expression". Compare

CellPrint@Cell[BoxData[RowBox[{"a", "+", "b"}]], "Input"]

and

CellPrint@Cell[RawData@BoxData[RowBox[{"a", "+", "b"}]], "Input"]

RawMedium is an implementation detail of ToString and related functions, and how they move between the $PrintForms.

RawArray is something we've been steadily working many versions (and if you poke at the internals of large data blobs like Image and Audio, you can probably guess basically what it is). It will be documented in an upcoming release.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.