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

#### 2.7.8.1 Field

The virtual machine supports a generalization of the `left` and `right` deconstruction operations that is applicable to deeply nested structures. Use of this feature is conducive to code that is faster and more compact than is possible by relying on the primitive deconstructors alone. It may also be easier for a code optimizer to recognize and transform.

The general form of a virtual code application to perform deconstruction is that it is a pair with a `nil` left side, and a non-`nil` right side. The right side indicates the nature of the deconstruction to be performed when the function is evaluated on an argument.

To make the expression of deconstruction functions more readable in `silly`, the standard library contains the declaration

    field = couple(constant nil,identity)

which implies the following theorem.

T13

  [[`field`]] `w` = `(nil,w)`

The virtual machine recognizes an application in this form and evaluates it according to the following properties, where `u` and `v` are other than `nil`, but `x`, `y`, and `z` are unrestricted.

P10

  ([[`field`]] `(u,nil)`) `(x,y)` = ([[`field`]] `u`) `x`

P11

  ([[`field`]] `(nil,v)`) `(x,y)` = ([[`field`]] `v`) `y`

P12

  ([[`field`]] `(u,`v`)`) `z` = `((`[[`field`]] `u) z,(`[[`field`]] `v) z)`

One might also add that ([[`field`]] `(nil,nil)`) `z` = `z`, but this statement would be equivalent to P0.

A suitable choice of the `field` operand permits the implementation of any deconstruction function expressible in terms of `compose`, `couple`, `identity`, `left` and `right`. For example, the application `couple(compose(right,right),left)` has an equivalent representation in `field((nil,(nil,(nil,nil))),((nil,nil),nil))`. The latter looks longer in `silly` but is smaller and faster in virtual code.

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

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