Skip to main content

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

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

  1. 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) * z b. Logical: isRaining && !hasUmbrella c. Relational: age >= 18 d. 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.
  2. 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, switch d. Calling a function: log("Hello");

Key Differences:

  1. Value vs. Action:

    • Expressions produce a value.
    • Statements perform an action or control program flow.
  2. Use in code:

    • Expressions can be used wherever a value is expected.
    • Statements form the basic execution units of a program.
  3. 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.