Adaptive Framework 0.9.0

Language Features

In this section, you will be guided through the features of Adaptive Script and how they compare and contrast to other languages, such as ECMAScript.

Variables

Variables in Adaptive Script are used to indentify a memory location, and are declared using the let or const keywords. Unlike ECMAScript, Adaptive Script does not support the var keyword, which has semantics surrounding its scope that are not compatible with how Adaptive Script processes variables.

Classes

Adaptive Script does not have support for classes. This means that the ECMAScript classes such as Array, Object, Integer, String, Boolean, Symbol, Map, Error, Exception, etc. cannot be used in Adaptive Script.

Importing modules

At this time, Adaptive Script does not support importing code from other locations. The only way to share code between scripts is to store them in qualified variables that would be accessible to scripts.

Types and Type Casting

Adaptive Script has a type system that has more in common with Typescript. For instance, in ECMAScript, you can add values of different types together without runtime errors, often resulting in some unexpected results. In Adaptive Script, these will be caught at compile-time, preventing the script from being loaded.

Prototypal Inheritance

Adaptive Script does not have support for prototypal inheritance.

Closure

ECMAScript has a feature called closure, which allows a function to access variables that are defined outside of its scope, and retain the values that were bound to those variables at the time of its scope creation.

At this time, Adaptive Script does not provide closure features.

let x = 1;
let foo;
{
    let x = 2;
    foo = function() {
        return x;
    }
}

// in ECMAScript, foo() will return 2, but in Adaptive Script, it will return 1
foo();

Statements

There are two import differences between Adaptive Script and ECMAScript as it relates to statements. In ECMAScript, semicolons are optionally used to separate statements. In Adaptive Script, they are required.

Furthermore, in ECMAScript, any expression can be used as statements and in Adaptive Script, this is not allowed.

// ECMAScript
let x = 1 // invalid in Adaptive Script (missing ;)
let y = 2;
'abc' // invalid in Adaptive Script (expression as statement)

Exception Handling

Adaptive Script provides try/throw/catch/finally exception handling, but the syntax and the objects are different than those in ECMAScript.

In Adaptive Script, throw is a statement that requires a string (the error message) and an optional data to allow users to pass along contextual data to the exception handler.

In ECMAScript, the catch statement accepts any value that was thrown, including an Error object, but in Adaptive Script, a single object is always caught, which contains the message and data that was thrown.

try {
    throw "Something bad happened" { "code": 123 };
} catch (e) {
    print(e.message);
    print(e.data.code);
}

Working with objects and lists

Because Adaptive Script does not have classes, it does not have all of the Object and Array methods, that are included in ECMAScript, accessible as object properties.

Object properties in Adaptive Script do not currently support computed names.

let x = { 
    a:   1, // valid in Adaptive Script 
    "b": 2, // valid in Adaptive Script
    [y]: 3, // invalid in Adaptive Script
};

Keywords new and delete

Adaptive Script does not support the new and delete keywords.

Iterators and Generators

At this time, Adaptive Script does not support generators. Although objects and lists can be iterated over using the for-of statement, creating iterators as you can in ECMAScript is not supported.

Asynchronous Operations

At this time, Adaptive Script does not support asynchronous operations.

The this keyword

The this keyword in ECMAScript has no meaning in Adaptive Script.

The eval function

The eval function in ECMAScript allows a programmer to execute a string as if it were code. In Adaptive Script, this is accomplished using the evaluate function, which has some differences.

In Adaptive Script, any code inside an evaluate call may not access or change any variables outside of its scope.

The for .. in statement

Adaptive Script does not support the for .. in and all of its semantics.

The switch statement

Adaptive Script supports the ECMAScript switch statement and even has some additional features, such as the ability to use functions to compare values matching a case.