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

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 should be avoided before version 1.6.3 since it was buggy.

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

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:

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.

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.

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.

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:

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 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:

YASS
$w = $x = $y = $z = 10
print($w)
print($x)
print($y)
print($z)
  

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.

Variable name tester

Use this form to test a variable name.

Variable name tester

Use this tool to test a variable name for validity.

Comments

There are no comments on this page.

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