Unset variables

If a variable is declared, but no value is assigned, its value is set to undefined.

var u;
println(u); // prints "undefined"

Type constraints

By default, a variable's type is unconstrained, and may change on assignment. A variable or constant may be declared to always be a certain type by adding the 'is' keyword and a type name following the variable name:

Any value may be used as a map key, and a deep copy of the value is used. String keys may be written with or without quotes. However, if a visible variable exists with the same name as a map key, this must be disambiguated, either by adding quotes (to indicate the string), or by adding parentheses (to indicate the variable).

defineFeature takes a lambda function as a parameter, and returns another lambda which calls the function passed in, along with some setup and cleanup.

Builtin

A builtin is a black box, whose contents cannot be accessed or changed directly in FeatureScript. A builtin is designed to be created by and passed into functions in the Onshape Standard Library. Examples of builtins are a Context, which stores the geometry of a Part Studio, and a Sketch, which stores the geometry of a sketch.

Undefined

undefined is a special type which can take only one value, also named undefined.

undefined is intended to be the FeatureScript representation of a value which does not exist. It is the result of a failed try() expression, an unset variable, or a nonexistent map entry.

Type tags

Custom types and enums exist throughout the standard library, and may be defined as top-level constructs. In addition to its standard type, a FeatureScript variable may have a type tag assigned, which represents a more specific contract that the variable should uphold.

A type tag may be checked with the is operator, which returns a boolean:

if (x is Vector)
{
// do something
}

Enums

An enum is an enumeration of a finite set of choices.

export enum LumberSize
{
TWO_BY_FOUR,
TWO_BY_SIX,
TWO_BY_EIGHT
}

An enum value is a string which is one of the enum's choices, tagged with the enum's type. For example, LumberSize.TWO_BY_FOUR is the string "TWO_BY_FOUR" of with the type tag LumberSize.

var size is LumberSize = LumberSize.TWO_BY_FOUR;

Custom types

A custom type defines the conditions for a member inside a typecheck, which must be defined as a top-level predicate.

A custom type generally exports a constructor from the same module which exports the type. The standard naming convention is for custom types to begin with an upper-case letter, and for the constructor name to match the type name with a lower-case first letter.

The as keyword, as used above, will attach the given type tag to any value. It should be used with caution, since it's possible to attach a type tag to a value which does not satisfy the type's typecheck.