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 Programming Environment documentationAssignment

Variables are declared with a $ sign at the start of them, as with PHP, Perl, Bash and many other scripting languages.

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

YASS
$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 is advised that is avoided before version 1.6.3 since it was buggy.

YASS
$a = [43, 44, 45]
print($a[1])
    

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:

YASS
$hex = 0x43
$octal = 033
        

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

Octal numbers start with a 0 followed by any octal numbers.

These styles were borrowed from C.

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 6 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
  • Number
  • Boolean
  • List
  • 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.

YASS
$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.

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:

YASS
$f = new ZPESequentialFile()
$f->open("list.txt")

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

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

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

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

This function of assignment is still being reviewed so it may be as of version 1.6.7 that it is not perfect. It is therefore in experimental stages and should not be used in production.

Comments

There are no comments on this page.

New comment
Reply
Provide feedback on this page
Comments are sent via email to me.