There are some common ways to exploit var
objects in applications:
- As global changeable constants For example, consider an application
that wants to log progress and events of its computation. It might be
desirable to send the log info sometimes to a file, sometimes to a view
object or to the main window. In this case one could declare a global
var object @log_output
and rebind it if the destination of the output has to be (temporary)
changed.
- As context parameters A good example is @event,
which provides access to the currently executing events.
- As local variables in code fragments In the two applications
mentioned above, the var
object with normally have a global (named) object reference. When used
as a local variable, the object reference is normally anonymous. In the
following example, Chain is a chain of chains of graphical
objects. The task is to display the graphicals of each chain on a
separate device and display all these devices on a (common) device.
new(Dev, device),
send(Chain, for_all,
and(assign(new(SubDev, var),
?(@pce, instance, device)),
message(@arg1, for_all,
message(SubDev, display, @arg1)),
message(Dev, display, SubDev)))
- See also
- class assign