Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
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],... –  bill s Jan 23 at 19:34
    
@bills I believe that was added after version 7, which I use, so I don't know. –  Mr.Wizard Jan 23 at 19:37
    
When I try ?Raw* there are several entries (ver. 9): Raw, RawArray, RawBoxes, RawData, and RawMedium. All seem equally opaque! –  bill s Jan 23 at 19:40
    
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 ... –  Szabolcs Jan 23 at 20:39
    
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 ... –  Szabolcs Jan 23 at 20:53
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.