To use a package foo's messages, declare a dependency on it in the package.xml file, and a dependency on foo-msg in the ASDF system definition. In what follows, we also assume for simplicity that

(use-package :foo-msg)

has been called in the current Lisp package.

Messages are CLOS objects. They should be treated as immutable.

Creating

$ (defvar m (make-msg "foo/Bar" :a 3 (:x :position) 4))
[<Bar>
  :A 3
  :POSITION
    [<Point>
      :X 4.0
      :Y 0.0
      :Z 0.0]]

Note that make-msg can take primitive as well as nested field specifications. Unmentioned fields are initialized to default values (0, false or the empty string).

Printing

As seen above, messages know how to print themselves.

Accessing fields

$ (with-fields ((a a) (x (x position)))
    (+ a x))
7.0

Note the nested field descriptions. In the special case where the variable and field names are the same, you can simplify:

$ (with-fields (a (x (x position)))
    (+ a x))

Modifying

Message objects are immutable, so make a copy:

(defvar m2 (modify-message-copy m (y position) 3.0 a 4))

To modify in place:

(setf-msg m2 (z position) 4.0)

This does not violate the immutability requirement, because it actually assigns a new object to m2 rather than modifying the existing one.

Wiki: roslisp/Overview/Messages (last edited 2014-08-26 15:28:43 by GayaneKazhoyan)