To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Official ZPE/YASS documentationAssignment and variables

Variables are declared with a $ sign at the start of them, as with PHP, Perl, Bash and many other scripting languages, or as of ZPE 1.9.3/YASS 21 declared using the let keyword.

Variables should not be names of keywords, e.g. $is or $list is not a valid name for a variable.

$a = 43
$b = true
$c = false
$d = "Hello"
$e = $a || $b
$f = $c

As of version 1.5.3 the variable index syntax has been included, however, it should be avoided before version 1.6.3 since it was buggy.

$a = [43, 44, 45]

Non-standard values

Version 1.5.0 added support for hexadecimal and octal values straight from the compiler. The compiler works these out and transforms them to their integer equivalents during compile time.

The following sample shows this:

$hex = 0x43
$octal = 0o33

Hexadecimal numbers start with a 0 (zero) followed by an x followed by an hexadecimal values.

Octal numbers start with a 0 (zero) followed by an o and then octal numbers.

These styles were borrowed from C.

Data types and TYPO

ZPE 1.6.7 adds support for typing through the TYPO system. TYPO is a compiler-based typing system designed for educational use but also to add stricter programming practices to ZPE.

ZPE has 8 primitive types as of version 1.6.7 (prior to that it had several others, but most have since been combined into the object syntax such as the image type).

The types are as follows:

  • String
  • Integer
  • Real
  • Boolean
  • List
  • Map
  • Function
  • Object

ZPE does not distinguish the difference between an integer value and a double value until assignment has taken place. The same goes for lists and maps, which both come under the List type but are represented differently in memory.

$a as string = "Hello"
$b as number = 10
$c as number = 10.5
$d as boolean = true
$e as list = ["Hello", "World"]
$f as list = ["Hello" => "World"]
$g as function = function() { print("Hello world") }
$h as object = {name : "Jamie"}

As with all built-in ZPE keywords, types and the as keywords are all lowercase when using the case sensitive compiler.

Inline assignment

Version 1.6.7 also added inline assignment which was originally thought to be a complicated procedure but ended up being relatively simple. This syntax allows declarations to take place within other expressions, e.g. an if statement:

$f = new ZPESequentialFile()

while (($check = $f->has_next()) == true)
end while

Notice that the assignment is bracketted! This is so important to prevent the compiler parsing it as a boolean assignment.

$x = get_input("Insert a value.")

if (($v = $x + 3) == 10)
end if

This type of assignment was added in ZPE 1.6.7 and improved over time.

Multiple assignments

Actually seen as an odd side effect of the compiler (and I'm not entirely sure which version added support for it as of yet), multiple assignment in ZPE/YASS is very easy:

$w = $x = $y = $z = 10

As mentioned above, I am not sure which version this was added in since it is a side-effect of some other compiler feature and was not intentional.

Using the let keyword in ZPE 1.9.3+/YASS 21+

Using the let keyword you can easily assign variables:

let $x = 10

ZPE 1.9.3 (Hawick) brought one of the most desired features to ZPE/YASS, variable names that do not need preceeded by a $ sign.

It does this without using any late inference to determine variables but does it during compile time. It's important to note that the create_variable function creates variables that have the $ sign at the start of them since those variables cannot effectively be checked at compile time.

let x = 10

This also works where variables can be assigned, e.g. in a for loop:

for (let x = 0 to 10)
end for
The let keyword can also be substituted with the var, making the syntax more like ES6 and JavaScript.

Variable name tester

Use this form to test a variable name.

Variable name tester

Use this tool to test a variable name for validity.


There are no comments on this page.

New comment
Comments are sent via email to me.