Variables and Constants (coming soon)

Variables

Using a #+var block, you can declare a variables and assign values to them. Those variables could be then used as an interpolation expressions to substitue value inside a code, be used in loops and conditions statements or be passed as arguments to other blocks.

Variables declared in this way are considered top-level and defined in the scope of the package. If name of the variable starts from capital letter then this variable is exported from the package as part of its public API and could be referenced from other packages.

CoginitiScript hash following built-int data types:

Integers
Integer values, like 1, 2, 3, etc… up to max 64bit integer value.
Floats
Float values, like 0.75, 2.5, etc… up to max 64bit float value.
Strings
String values
Keywords
Symbolic identifiers that evaluate to themselves. They provide very fast equality tests and recommend to be used as keys in Maps. Examples: :name:doc.
Lists
List of elements
Maps
Key / value pairs stored as a hash map.
#+var
  fields = ["name", "email", "postal_code"];
  num_users = 100;
  email_domain = "gmail.com";
  maps = { :key "value" };
#+end

SELECT
#+for f : fields separator "," do
  {{ f }}
#+end
FROM
  customers
WHERE
  email LIKE "%@{{ email_domain }}"
LIMIT
  {{ num_users }}
;

 

Constants

Constants are identifiers which have an assigned value. The constant’s value cannot be changed and value must be a constant expressions which CoginitiScript could evaluate at compile time.

#+const
  CompanyDomain = "acme.com";
  AdminEmail = "admin@" + CompanyDomain;
#+end

 

Public / Private variables and constant

Variables and constants could be defined as public to be used outside of the given package in the same way as blocks and variables, by having their name defined with capital letter.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request