Next:
Contents
Contents
The Shang Programming Language
Xiaorang Li
Contents
Overview of Key Features of Shang
Multi-faceted Data
First-class object only
Domains
Function Parameters
Class and Members
Vectorization
Rich features for numerical computing
Minimized Implicit Behavior
Automaton
High Performance
The Interactive User Interface
The Shang Interpreter
The interactive mode
Use Shang as an arbitrary precision calculator
Define Variables
Define and call functions
Suppress the display using semicolon
Commenting
Single line comment
Multi-line comment
Run a script
Line continuation
Command editing and History
Data Type
Data value and attribute
Numerical Data
Scalar
Storage type of numerical values
Matrix
Matrix Indexing
Single Index
Two indices separated a comma
Two indices separated a semicolon
A[i; j]
Using backslash \ to reference diagonals
$
stands for the largest index
:
is equivalent to
1 : $
Index bound
Index expression as lvalue
Storage types of matrix elements
Sparse Matrix
Multi-dimensional matrix
Attributes of matrix
Character String
Index and substring
Attributes of a string
Use string as a function
Concatentation and other operations
Regular expression
Regular expression substitution
List
Fixed length list and variable length list
Hash Table
Set
Finite Sets
Intervals
Define a set using function
Set operations
Stack
Queue
Structure
Other Data Types
Operators
Arithmetic Operators
Addition and Subtraction:
+,-
Numerical Operands
Functional Operands
List Operands
Multiplication:
*
Division:
/
Back Division for solving linear system: \
Numerical Operands
Set Operands
Element-wise multiplication and division:
.*
,
./
Power:
^
Element-wise Power:
.^
Modulus
Unary
+
and
-
Prefix
+
and
-
Postfix
+
and
-
Transpose:
'
Relational Operators
Logical Operators
Logical Value
Logical
and
:
&&
Logical
or
:
||
Logical
not
:
!
Assignment Operator:
=
Lvalue: variable name
Multiple Assignments
Other Lvalues
Compound Assignments
Increment and Decrement Operators
Other Operators
Attribute Retrieval
Matrix
List Indexing
Function Parameter, Structure and Class Member Attribute
Hash Entry
Set
Pointer
Function
Precedence and Associativity of Operators
Flow Control Structures
if
statement
unless
statement
for
statement
while
statement
until
statement
do - while
statement
do - until
statement
break
and
continue
switch
statement
Function
Function definition
One Liner Functions
Functions defined by a sequence of code
Local variables
Global Variable
Return value of a function
return
statement
Calling a function
Pass Functions as Input and Output Arguments
Argument Passing
Return Multiple Output Arguments
Function Parameters
Parameter Syntax
public
parameter
private
parameter
common
,
auto
, and
readonly
parameters
Parameter Domain
Spawn a New Function
Recursion
Partial Substitution
Default value of arguments
Domain of Function Argument
Calling functions using named arguments
Built-in functions
Pseudo Functions
Operations on functions
Function Matrix
Everything is a function
Turn a matrix into a function
Class and Member
Class definition syntax
Access Control of Member attributes
public
private
common
auto
Domain of Attribute
Collective attribute
The Constructor
Multiple Constructors
Inheritance
Multiple Inheritance
Attribute name clash
Validation of member attribute modification
Class as a Set
Operator Overloading
Acquired Attributes and structure
Conditional Class
Defining a Conditional Class
Utility Attributes
Pointers
Pointer Syntax
Pointers and Function Arguments
Linked List
Returning a Pointer
Pointer and Class Member
Pointer and Program Efficiency
Use pointer to emulate reference
Errors and Exception Handling
Parsing Errors and Run-time Errors
Raising Exceptions
Handling Exceptions
File, Input, and Output
File
Output
Input
Formatted IO
printf
sprintf
sscanf
Automaton
Define Automaton
Port
Run Automaton
Connections between Automatons
Built-in Functions
System utility functions
run
with
pause
panic
clock
etime
time
Elementary Math functions
Trigonometric functions - vectorized
Exponential and power - vectorized
Polynomial
Matrix
Creation and initialization of matrices
Basic attributes of matrices
Other functions
Linear Algebra
String and regular expression
Math functions
Creation and initialization of data of other types
Data processing and statistics
Sorting and searching
Probability Distributions
Input and output
Sets
Sets of real numbers
Sets of integers
Sets of complex numbers
Sets of double precision floating point numbers
Sets of machine integers
Sets of byte integers
Sets of complex numbers
Sets of other numbers
Miscellaneous
System Commands
About this document ...
oz 2009-12-22