Map
, that can apply any other star (or galaxy) to the sequence(s) at its inputs. Many other useful higher-order functions are also provided by this domain. The HOF domain provides a collection of stars designed to be usable in all other Ptolemy domains. To preserve this generality, not all interesting higher-order functions can be implemented in this domain. As a consequence, some individual domains may also define higher-order functions. In fact, any higher-order function with domain-specific behavior must be implemented in its respective domain. The HOF domain is included as a subdomain by all other domains. In Ptolemy 0.7 and later, HOF can be used in both graphical and non-graphical Ptolemy Tcl interpreters.
A common feature shared by all the stars in this domain is that they perform all of their
preinitialize
method. Moreover, their basic operation is always Many of the HOF stars will replace themselves with one or more instances of another star or galaxy, called the replacement block. Replacement blocks generally go into the graph in the same position originally occupied by the HOF star, but different HOF stars will connect these replacement blocks in different ways.
Some HOF stars have no replacement block. Before they self destruct, they will typically only alter the connections in the graph without adding any new blocks. An example is the
BusMerge
block, which merges two busses into one wider bus. These stars are called bus manipulation stars.The experienced reader may have some difficulty connecting the concept of higher-order functions, as implemented in this domain, to that used in functional programming. This issue is covered in some depth in [Lee95], but we can nonetheless give a brief motivation here. In functional languages, there is no syntactic difference between a function argument that is a data value, one that is a stream (an infinite sequence of data values), and one that is a function. In visual programming, however, functions typically have two very different syntaxes for their arguments. Ptolemy is no exception. Stars and galaxies in Ptolemy are functions with two kinds of arguments: input streams and parameters. The HOF domain only contains stars where a parameter may be function. It does not contain any stars that will accept functions at their input portholes as part of an input stream, or produce functions at their output portholes. Although in principle such higher-order functions can be designed in Ptolemy, their behavior would not be independent of their domain, so the HOF domain would be the wrong place for them.