Shang Features

Multi-faceted Data Structures
Instead of having a rigid hierarchical system of types and classes, in Shang a piece of data is usually multi-faceted --- meaning that it is not restricted to a single type-related functionality and can act as different roles. Conversely, concepts like functions, sets, and lists are not tied to certain data types and can be implemented in a variety of ways. For example, (almost) anything is a function, a function is also a set, a set is also a function, a class is also a set, and anything is a list (when it is not created as a list, it is a list of a single entry), etc. This often makes it possible to implement functionalities by the most convenient and concise ways, yet maintains a uniform interface to the client functions.

First-class object only
Every entity including a function is a first-class object. Functions can be used anywhere a value is expected. Function can be defined inside functions, can be passed to functions as input arguments, and returned by functions as result of function calls. Functions can be created at any time, and not not only be defined by code, but also as results of operations such as addition/subtraction, multiplication/division, composition, and function vector/matrix.

Function input and output arguments may have domains and the language interpreter automatically checks the value of the arguments and generates domain error if the value is not in domain. Shang combines the strengths of both statically and dynamically typed languages. It is as flexible as dynamically typed language, yet it can be more specific than statically typed language, because what it requires is the input argument is inside a domain, not just of a type. A domain is a set that can be defined by different ways, and can be very specific and can often completely ensure the validity of input data, while traditional statically typed languages are often inadequate in this respect.

Parameterized Functions
Functions can also have parameters (in addition to input/output arguments), which makes functions customizable after they are created, and can simplify the calling sequence in many cases. Functions with parameters act like a class-less object and spawn new functions like their own constructor.

Object Oriented
Shang is objected oriented and has full support for most of the OOP features including access control of member attributes and multi-inheritance. Each attribute of a class can have a domain so that public class attributes can be used yet object integrity is still protected. This can often eliminate the need of private attributes and set/get operations and made the class interfaces both safe and simplified.

Conditional Class
Traditional classes are suitable for representing essential and static identities of objects, but they may be too rigid and inflexible for describing nonessential and volatile characteristics of objects. A conditional class is a collection of loosely connected objects. Unlike a traditional class, it doesn't ``create'' new members using the constructor, but issues membership to members of other classes that satisfy certain conditions. Such membership may be cancelled once the condition is no longer satisfied. By using conditional classes, it is possible to avoid unnecessary programming complexity, too many levels of multiple inheritance, and frequent object creations and destructions.

Data types are vectorized on two levels. First, all the numerical data are in matrix format. A scalar is just a one by one matrix. Common matrix operations are supported directly. Second, any general data value can also be considered as an array (in other words, an array of a single entry is equivalent to that entry itself).

Minimized Implicit Behavior
Popular languages tend to use object references only and provides no way to directly handle objects. This promotes implicit behavior of programs and poses particular difficulties when implementing structures like sets which are supposed to maintain a constant state unless changed by the owner. In Shang data values instead of their references are stored in variables therefore a variable's status never changes unless a new value assigned to it, or explicit modifying operation performed on it, and therefore implicit behaviors of programs are reduced. On the other hand, safe pointers are implemented with easy readable syntax, to provide means to create dependencies between different variables, and build complicated data structures.

Built-in Power for Numerical Computation
With the extensive support for high-level numerical data structures, operations, and mathematical functions, efficient scientific computation can be realized without programmer involving too much on low level computation details and concentrate on the applications.

An automaton is a special data type that is a program with its own variables, whose execution can be halted and resumed. Automatons function as computers and can communicate with each other. They may help implement complicated control flows and event-driven programs.

Shang Home