Overview
What is Plasma ?
- Plasma is a feature-rich strongly-typed scripting language that enables users to write complex programming logic in a user friendly manner
- It has a strong focus on type safety along with expressiveness. Basically we want our users to be able to write correct code without getting bogged down with the complexities of programming
- It can be used seamlessly across all of our products
Quick Links
- Types - A quick overview of types
- Predefined types - Predefined types
- User-defined types - User-defined types
- Operators - How to operate on your data ?
- Control-flow - How to control the flow of execution ?
- User-defined types - How to define your own data types ?
- Functions - Manipulating your data
- Overview - A quick overview of functions
- Functions on String type - Manipulating string values
- Functions on Numeric types - Manipulating integer and real values
- Functions on Date / Time / DateTime types - Manipulating date, time and date-time values
- Functions on List & Set type - Manipulating list and set types
- Functions on Map & MapEntry type - Manipulating map and map entry types
- Functions on File type - Manipulating file types
- Functions on Enum type - Manipulating Enums
- Functions on FutureResult type - Manipulating FutureResult
- Functions on Any type - Manipulating Any
- Writing Custom Functions Advanced - How to write your own functions ?
- Comments - How to comment your code ?
- Errors - What do different errors mean and how to resolve them ?
A note on expression vs scripts
You might have noticed that in Askribe, there are code-boxes which require expressions and code-blocks which require scripts.
Let's see what is the difference between the two.
- A script is an entire program. It can have variables, functions, expressions, control-flow statements etc.
- An expression is a piece of code that returns a value. It is a fragment of a script.
For example, the following is a script:
def int x = 10; // Here 10 is an expression
def int y = 20; // Here 20 is an expression
def int z = x + y; // Here x + y is an expression
Expressions vs. Statements: A More In-Depth Look
-
Expressions:
- An expression is a combination of values, variables, operators, and function calls that evaluates to a single value.
- Expressions can be nested within other expressions.
- They can be used as part of statements or stand alone in some contexts.
- Types of expressions:
a. Arithmetic:
(x + y) * zb. Logical:isRaining && !hasUmbrellac. Relational:age >= 18d. Function calls:max(a, b)e. New data creation:new List<string>() - Notice, that an expression always returns a valuee and DOES NOT end with a semicolon.
-
Statements:
- A statement is a complete unit of execution in programming.
- It typically ends with a semicolon in Plasma languages.
- Statements can contain expressions, but not all statements are expressions.
- Types of statements:
a. New variable declaration:
int count;b. Assignment:total = price * quantity;c. Control flow:if,while,for,switchd. Calling a function:log("Hello");
Key Differences:
-
Value vs. Action:
- Expressions produce a value.
- Statements perform an action or control program flow.
-
Use in code:
- Expressions can be used wherever a value is expected.
- Statements form the basic execution units of a program.
-
Side effects:
- Pure expressions don't have side effects (they don't change program state).
- Many statements have side effects (changing variables, I/O operations).
Example to illustrate the difference:
// Statement (declaration and assignment)
int result = 0;
// Statement containing expressions
if ((x > 5) && (y < 10)) {
// Statement with nested expressions
result = (x * 2) + (y / 3);
}
// Expression statement (a statement that consists of just an expression)
log(result);
In this example, (x > 5), (y < 10), (x * 2), and (y / 3) are all expressions. The if statement and the assignment to result are statements that incorporate these expressions.