IvoryScript further reading

Names and types are first class

Names normally occur as part of the static structure of a program. A compiler uses them to identify variables, functions, types and other declarations, and their meaning is established from the surrounding context.

In IvoryScript, a name can also be a value. For example:

      #alice
   

denotes a value of type:

      Name
   

A name value can therefore be passed as an argument, returned as a result, stored within another value or retained in a closure.

Types can similarly be values. The type:

      Type
   

is the type of a type value. Thus a type can participate dynamically as a value as well as being used statically by the type system.

Why not strings?

A name might superficially appear to be little more than a string. The two, however, carry different information.

A string is text. A Name is a name within the language model. It requires no interpretation of text to establish that distinction.

This becomes important because the meaning associated with a name depends upon an environment. The same Name value can therefore acquire different meanings in different environments without changing the name itself.

The same distinction applies to Type. A type value is not, say, its type signature as a string. It is the type itself as a first-class value.

Binding names to expressions

IvoryScript provides a compact syntax for associating a name with an expression:

         alice:42
      

This is transformed to:

         Bind #alice 42
      

The name in the source form therefore corresponds to the first-class Name value #alice, rather than merely providing a textual label.

Collections of such bindings can themselves form values. For example:

         PropertySet [alice:42, bob:17]
      

contains associations between name values and expressions without requiring the names to be fixed fields of a statically defined record.

Using names

There is corresponding syntactic sugar for applying a name to a value:

         e.alice
      

which is transformed to:

         (.) e #alice
      

As a class method of Select, (.) allows type-specific behaviour. The familiar-looking dot notation is an application in which #alice is an ordinary value.

The more general form:

         (.) e n
      

can consequently be used where:

         n :: Name
      

enabling selection by a variable.

Names and environments

A name alone does not determine the value associated with it. Its meaning depends upon the environment in which it is interpreted.

The same Name value may consequently have different meanings in separate environments. The name remains unchanged; the environment supplies the association which gives it meaning there.

This distinction is particularly significant because IvoryScript is not restricted to a single environment. Transient, persistent and other environments can provide separate contexts in which the same names participate.

Static names and types describe the structure of a program. First-class Name and Type values allow names and types also to participate in the values of the program.