Skip to content

Variable

Paul Lipkowski edited this page Dec 18, 2021 · 9 revisions

Variable is a structure used in PapajScript, that allows storing entities. Variables were introduced on November 8, 2018, along with the release of RPN Calculator 0.4.1.

Structure

Up to the version 0.5.0 of RPN Calculator the variables were stored in a simple database, where every variable had its label and value. Since September 2020 the variables engine was rebuilt, adding variables' scopes for functions and global variables. Global variables (available since 0.5.1, their prefix is global.) are available throughout entire program and they change their values globally, unlike other variables that their values are changed only in a scope of function where it happens.

Usage

  • "abc" "xyz" vset or abc >xyz or abc ->xyz or abc -> xyz or abc -> $xyz – Move an "abc" to a var "xyz" (note that "xyz" is a String entity in vset). If the variable does not exist, then create it with this value.
  • "xyz" vget or $xyz – Put either the var "xyz" or NULL on the stack, depending if the variable exists or not.
  • "xyz" vexists or ?xyz – Return true or false, depending if var "xyz" exists.
  • "xyz" vdestroy or ~xyz – Destroy a variable "xyz" if exists.
  • "xyz" vcall or @@xyz – If the var is a function, then call it directly.

Notes:

  • Calling xyz without any prefix or command does the following:
    • if xyz is a function, then call it (act like @@xyz)
    • otherwise (if xyz is not a function) put the variable on the stack (act like $xyz) This feature is available since 0.5.0.
  • If you are running RPN Calculator 0.5.2 (or newer) with runtime parameters, then all these params are stored in the array variable called Params. Note that this variable is an array of strings.
  • The -> arrow is available since 0.5.1.
  • Global variables have global. prefix, e.g. global.var. They are available since 0.5.1.
  • From 0.4.3 version quotes the variable names must be quoted, if using long syntax (vset, vget, vexists, vdestroy and vcall) functions. It does not apply to short syntax ($var, >var, ->var, ?var, ~var, @@var, var).
Clone this wiki locally