[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.7.13.5 Transfer

A particular interpretation is given to virtual code in the following form.

T26

[[transfer]] f = ((nil,nil),(nil,(nil,f)))

When code in this form is evaluated with an argument, the tree f is used as a state transition function, and the argument is used as a list to be traversed. The traversal begins with f being evaluated on nil to get the initial state and the initial output. Thereafter, each item of the list is paired with the current state to be evaluated with f, resulting in a list of output and the next state. The output resulting from the entire application is the cumulative concatenation of all outputs obtained in the course of evaluating f. The computation terminates when f yields a nil result. If the list of inputs runs out before the computation terminates, nil values are used as inputs.

This behavior is specified more precisely in the following property of the operator, which applies in the case of non-nil f.

P33

([[transfer]] f) x = ([[transition]] f) (nil,(f nil,x))

Much of the transfer semantics is implicit in the meaning of transition. For any given application f, [[transition]] f is the virtual code for a function that takes the list traversal from one configuration to the next. A configuration is represented as a tuple, usually in the form (previous outputs,((state,output),(next input,subsequent inputs))). A terminal configuration has the form (previous outputs,(nil,(next input,subsequent inputs))). A configuration may also have nil in place of the pair (next input,subsequent inputs) if no more input remains.

In the non-degenerate case, the meaning of [[transition]] f is consistent with the following equation.

E7

([[transition]] f) (y,((s,o),(i,x))) =
([[transition]] f) ((o,y),(f (s,i),x))

That is, the current output o is stored with previous outputs y, the next input i is removed from the configuration, and the next state and output are obtained from the evaluation of f with the state s and the next input i.

In the case where no input remains, the transition function is consistent with the following equation.

E8

([[transition]] f) (y,((s,o),nil)) =
([[transition]] f) ((o,y),(f (s,nil),nil))

This case is similar to the previous one except that the nil value is used in place of the next input. Note that in either case, nothing about f depends on the particular way configurations are represented, except that it should have a state as its left argument and an input as its right argument.

Finally, in the case of a terminal configuration, the transition function returns the cumulative output.

E9

([[transition]] f) (y,(nil,x)) = [[reduce(cat,nil)]] [[reverse]] y

The silly code reduce(cat,nil) has the effect of flattening a list of lists into one long list, which is necessary insofar as the transition function will have generated not necessarily a single output but a list of outputs on each iteration. The cat mnemonic stands for list concatenation and is explained in Cat. The reversal is necessary to cause the first generated output to be at the head of the list. List reversal is a built in operation of the virtual machine and is described in Reverse.

If such a function as transition seems implausible, its implementation in silly can be found in Transition.

It is usually more awkward to express a function in terms of a transfer than to code it directly using recursion or other list operations. However, this feature is provided by the virtual machine for several reasons.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on November 8, 2012 using texi2html 1.82.