Messaging Apps powered by Machine Learning

A variable can be thought of as a container that can hold something. Variables in pez start with either a letter or underscore followed by alphanumeric character or underscore. Here are examples of valid variable names in pez:

  • my_variable
  • myVariable
  • _my_variable
  • myVariable1
  • myVariable1
  • MY1VARIABLE2

Although these are all valid formats for variable names, try to avoid all caps because it’s a bit obnoxious.

Let’s move on to what’s not allowed. Names that start with numbers, such as 1myVariable or 12_ are not valid names. If you insist on naming a variable like that, you’ll get back an error message.

Assignment

Variables are useful when they hold some value. We say that a variable is assigned a value, meaning it represents that value. When assigning a value to a variable, use the following syntax.

Expressions can be thought of as pieces of code that evaluate to a specific value. Here are some simple examples that you can try within Slack. In the code samples below, only type the line starting with !pez. The result is displayed on the following line(s).

Here is what it looks like within Slack:
variables_x5

Here’s a slightly more complicated example, where we assign the variable y to a vector with three elements.

And this is what it looks like in Slack.
variables_y

When assigning a variable, its value is printed into the Slack channel. This is particularly useful when applying a function to some arguments.

The rnorm function returns n normally distributed variables. We don’t know the exact values until the expression is evaluated, which is why it’s useful for the result to be printed to the channel.

Mutability

Variables are mutable, so we can reassign their value as much as we like. Let’s verify this by typing the name of a variable into Panoptez.

Every time a variable changes, its new value is accessible to everyone in your team. As part of Panoptez, variables are persisted automatically on assignment.

What’s Next?

With the basics of variables under your belt, you can choose your own adventure for what to read next.