10.23.9 Tips

  1. Most important tip: don't subvert the structs type system by looking inside foreign terms to get the address, or use functor/3 to get the type. This has two negative effects: firstly, if the structs package should change its representation of foreign terms, your code will not work. But more importantly, you are more likely to get type mismatches, and likely to get unwrapped terms or even doubly wrapped terms where you expect wrapped ones.
  2. Remember that a foreign term fred(123456) is not of type fred, but a pointer to fred. Looked at another way, what resides in memory at address 123456 is of type fred.
  3. The wrapper put on a foreign term signifies the type of that foreign term. If you declare a type to be pointer(opaque) because you want to view that pointer to be opaque, when you get something of this type, it will be printed as opaque(456123). This is not very informative. It is better to declare
              fred = opaque,
              thing = struct([...,
                          part:pointer(fred),
                          ...
                      ]).
    

    so that when you get the contents of the part member of a thing, it is wrapped as fred(456123).


Send feedback on this subject.