Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Official ZPE/YASS documentationReference functions

Chainable functions or reference functions are functions that can be run on an element or value. For example, a lot of languages expose a toString() or similar function on elements or values. ZPE also adds this too, and it's easy to do:

They are known as reference functions simply because they act much like normal functions except instead of taking in a value they work on the value they are 'chained' to.

YASS
$a = 43
print($a.to_string())
$b = [43, 49]
print($b.get(1))
  

This example is pretty poor, since the print function already transforms it's input to a string. However, the second example will correctly select an element from the list.

The decision to use reference pointer (the dot .) instead of the arrow (->) was based on the confluence of different language concepts and to keep everything object-oriented syntactically similar - lists and associative arrays are not objects but they have underlying functions so the dot suits them whereas the arrow suits objects.

Reference functions only work on a few data types presently:

  • List
  • Map
  • String

There is more information under each data type.

ZPE 1.8.11

ZPE 1.8.11 made a huge number of changes to both the performance and features of reference functions. One of the first changes made was that all reference functions now expose internal native methods. Another major change was to add the to_string method to all reference types by default.

Reference functions will continue to get more support as time goes on with the string type recieving the same treatment as the list and map types.

Comments

There are no comments on this page.

New comment

Comments are welcome and encouraged, including disagreement and critique. However, this is not a space for abuse. Disagreement is welcome; personal attacks, harassment, or hate will be removed instantly. This site reflects personal opinions, not universal truths. If you can’t distinguish between the two, this probably isn’t the place for you. The system temporarily stores IP addresses and browser user agents for the purposes of spam prevention, moderation, and safeguarding. This data is automatically removed after fourteen days.

Comments powered by BalfComment

Feedback 👍
Comments are sent via email to me.