System overview Using the editor The Exotool language HTML templates The diagram The element catalog Deploying an app
The Exotool Language — Reference Manual
This is a reference for the Exotool language: the small language you write inside activities to give your app its behavior. It covers the core language and the explicit JavaScript/PHP code blocks.
Scope. This manual documents the core activity language and explicit blocks. The Handlebars-style HTML templates are a separate syntax documented in the templates reference (
exotool_docs("templates")).Exotool itself is a visual RMAD platform; this manual covers only the activity-code language you write inside it. For the big picture — how the visual editor, diagrams, and the compiler fit together — start with the System Overview (
exotool_docs("overview")), and for building apps in the editor see Using the Exotool Editor (exotool_docs("editor")).
Contents
- What the language is
- How a program is structured
- Lexical structure
- Expressions
- Statements
- Subroutines
alwaysstatements- Declarations
- Client/server conditional statements
- Macros (deprecated)
- Explicit JS and PHP blocks
- Debug instrumentation
- Built-in functions
- Quick reference
1. What the language is
The Exotool language is the code you write inside activities — the behavior layer of an Exotool app. You do not run it directly. When you build your app, the Exotool compiler translates it into the program that actually runs: a mix of client-side JavaScript (on the device) and server-side PHP (on the server).
The defining feature of the language is location transparency: you write one body of logic, and the compiler decides which parts run on the device and which run on the server, generating the communication that moves data between them for you. Constructs like declarations, client/server conditionals, and explicit JS/PHP blocks exist to influence or override that decision when you need to.
Where code runs, where values live
There is no such thing as a server activity or a client activity. The code of successive activities is merged into one chain, and the compiler cuts that chain wherever a server step is needed, generating a server-side call for each cut. The server-side code is custom-built for the app at compile time.
Some functions run only on the server. Session and user functions, mail and payment functions, every cloud-object fetch and delete, and every set function are server-only; alerts, prompts, form reads and page control are the device-only mirror. Each function's page in the online Function Reference says where it runs (Runs on); the line is generated from the compiler's own table, so it is the complete list. A statement that uses a server-only function runs on the server, whatever else it contains.
Every value has a side. A value is server-side when it is a cloud set, a cloud object or one of its fields, or the result of a server-only function or of a subroutine that runs on the server. A server-side value is set only on the server; the device never writes it. A client-side value is set on the device and copied to the server when a server statement needs it.
The server keeps its variables. Server-side variables persist across the cuts of a chain, and across activities, so a value computed in one server call is still there for the next and for every later activity: variables are global to the app, each living on one side. A server-side value is copied to the device only when a device-side statement reads it. A variable that only server statements read or write never reaches the device at all, however many places use it. So a permission, a password hash, a token, another user's record: keep them in variables that only server statements touch, and they exist nowhere on the device.
A side is sticky. adminp = is_admin_user() runs on the server because
is_admin_user is server-only, so adminp is a server-side variable, the server
remembers it, and every later statement that writes it is forced to the server
too. A conditional connector with the expression adminp takes its branch only
when the server says true, in this activity and in every later one, and because
activities chain, everything downstream of that connector runs under the same
gate. The same holds for any server-only function or server subroutine whose
result you gate on.
The one way to defeat this is to copy. declare_location flag client
followed by flag = adminp makes a device-side copy, and a connector gated on
flag trusts the device. So compute each permission once, into a variable the
server owns, and gate connectors on that variable or directly on the server call.
Never gate on a client-declared copy, and never feed a permission into an
always statement, which is device-side by nature and so pulls its inputs to the
device.
Data access is a set. Cloud objects reach the device only by being pulled
from a cloud set, and later updates are sent to the device only for objects a set
once delivered. So define one cloud set of what the current user may see, and
derive every other set from it with further subset calls. Then only objects
the user may see are ever copied to the device, and only those can be modified,
always on the server. Keep the chain in cloud sets: a subset over a list
already on the device filters on the device and proves nothing. A fetch by id
(locate_cloudobject, expect_cloudobject) is server-only too, but it is
outside the set fence, so guard the activity that does it. The bytes of a stored
file or image (fileprompt, imageprompt, store_file) follow the same fence:
the address in its url, as a device receives it, carries a token of the session
the object was handed to, and the server serves the bytes only for a token of a
live session that was handed that object: an address with another id, or without
the token, opens nothing. The token is the whole check, so the address works for
whoever holds it for as long as that session lives. Treat it as a secret of that
session: never store it in a field, show it to another user or put it in a mail.
A url read on the server has no token in it and opens nothing at all, for
anyone.
To give a file to someone outside the app (a photo or a PDF linked in a mail
to a customer), make a public link: link = public_link(file, 30) returns a
complete address that opens that one file for whoever has it, for the number of
days given (30 by default, 365 at most), and for an image
public_link(photo, 30, "thumbnail") names the size. The address is signed with
a secret of the app, so the file it names and its expiry cannot be changed; it
ends at its expiry or when the file is deleted and cannot be withdrawn sooner.
It is the only address of a stored file that works without a session, and it is
made on the server, from the stored object. Make one only for a file that may be
seen by whoever the address reaches.
To show one user's upload to another user, keep the stored object, not its
address: put the object itself in a field of the record it belongs to
(job.photo = imageprompt()), and let each device receive the record through a
cloud set or a list built from one. Every device then gets the object with an
address of its own session ({{photo.thumbnail_url}} in a template).
When you save a diagram, the editor also inserts debugging markers into the copy of your code that the compiler builds (see Debug instrumentation) so the visual debugger can follow execution.
2. How a program is structured
An activity is either a sequence of statements or, in a few places, a single expression. Statements are the usual case.
A program is one or more statements separated by whitespace. There is no
statement terminator — statements are separated by spaces and newlines, not by
;.
count = 3
price = 10
total = count * price
If a program cannot be parsed, the editor reports the line and position where it stopped — usually at or just after the mistake.
3. Lexical structure
Whitespace
Whitespace — spaces, tabs, and newlines — separates tokens and statements. Comments (below) also count as whitespace. In most places a newline is interchangeable with a space.
Comments
Two comment forms, both treated as whitespace:
// line comment — runs to end of line
/* block comment —
may span multiple lines */
Block comments do not nest.
Identifiers
An identifier — a name for a variable, function, subroutine, macro, or macro parameter — starts with a letter or underscore, followed by any number of letters, digits, or underscores. The first character may not be a digit.
x total customer_name _tmp item2
Reserved names
Three kinds of name are taken, and the compiler does not warn when you reuse one:
- Keywords and constants —
always,if,else,foreach,in,declare_location,declare_type,allocate,deallocate,if_on_client,if_on_server,subroutine_def,return,defmacro,null,true,false, and the block openersJS<,JS<P,PHP<. - Built-in function names — every function of §13
and of the generated Function Reference, and the compiler's own
(
DBpos,DBsource,_DBpos,_DBsource,_send_signal_to_other,_send_signal_toself,Padd5,ss_id). A subroutine you define with one of these names replaces the built-in wherever it is called. - Variable names — on the client every variable becomes a member of the app's
Envobject, so these names collide with the runtime's own:action,async_foreach,cloudname,delayshow,forms,last_opened_page,logged_in,login_error,new_field_value,position_error,sessionid,upload_error,user_billing_info,user_email,user_id,user_is_admin,user_name,user_organization,user_type; anything beginning__(the compiler's flags and lists, and__exotool_timezone, whichset_timezonewrites and the date functions read); the key of any element of the diagram (an element's own variables live under its key, see@elementvarin the templates reference); and<key>_errorfor any element key (its error variable).
Numbers
A numeric literal is a sequence of digits 0–9, optionally followed by a dot
and one or more digits: 2134, 80.4, 0.5. A leading minus sign is the
prefix operator -, not part of the number.
There is no leading-dot form (
.5is a syntax error: write0.5) and no exponent form (1e5: write100000). A dot that is not followed by a digit is not part of the number, so1.stops the parser at the dot.
Strings
String literals come in double- and single-quoted forms:
"a double-quoted string with \"escapes\" and \n \t \r"
'a single-quoted string with \'escapes\''
Recognized escapes are \n, \t, \r, the escaped quote, and \ itself.
Special constants
null true false always default
null, true and false may appear anywhere a constant is expected. An if
evaluated on null behaves as on false. always and default are connector
conditions only: on a sequence_connector, always takes the branch
unconditionally and default takes it when every other branch's condition fails.
They are not values to use inside activity code. (always is also a
statement keyword; which meaning applies depends on
context.)
4. Expressions
An expression produces a value. Exotool expressions are:
- constants — numbers, strings, and the special constants
null/true/false/always - variable references —
x,user.email,items[0] - function calls —
add(1, 2) - parenthesized expressions —
(a + b) - prefix-operator expressions —
-x,!done - binary-operator expressions —
a + b,x < limit - conditional expressions —
qty > 0 ? "In stock" : "Sold out" - object literals —
{name: item.name, price: item.price} - array literals —
["S", "M", "L"],[] - explicit JS/PHP block expressions (see §11)
Constants
A constant is one of the special constants, a number, or a string (see §3).
Variable references
Setting an element of an array or a member of a structure that has not been initialized (
a[3] = 1orp.x = 1beforeaorpholds a value) can give unpredictable results: assign the whole value first.
A variable reference names a value. It is a plain name, or a name followed by one or more modifiers:
.name— a dotted field access[expression]— an indexed access
So all of these are valid variable references:
alpha
alpha.beta
alpha.beta.gamma
items[0]
matrix[row][col]
record.fields[i].name
Function calls
A function call is a name followed by a parenthesized, comma-separated list of argument expressions (zero or more arguments):
doThing()
add(1, 2)
format(name, makeTitle(x), 42)
A function call is valid both as an expression and as a statement.
Parenthesized expressions
Use parentheses to group sub-expressions:
(a + b)
Binary-operator expressions
A binary-operator expression joins two expressions with an operator:
a + b
count * price
x >= 0 && x < limit
The available binary operators are:
+ - * / && || <= < >= > == != & |
Precedence and associativity. Binary operators have the conventional precedence levels, the same as JavaScript and PHP, and operators of equal precedence associate to the left. From tightest to loosest:
*/+-<<=>>===!=&|&&||So
2 * 3 + 1is(2 * 3) + 1,5 - 2 - 1is(5 - 2) - 1, anda + b > c && dis((a + b) > c) && d. Parentheses override the grouping. A prefix operator binds tighter than any binary operator:-a + bis(-a) + b(see Prefix operators).Note (2026-10-28): earlier editions of this reference said there were no precedence levels and that a chain associated to the right. That described the compiler's parse tree, not the code it generated: the generated JavaScript and PHP spelled a chain out as written, so both runtimes applied their conventional precedence all along. The parse tree now agrees with them. Code that parenthesized every grouping, as the old rule advised, is unaffected.
Conditional expressions
condition ? value_if_true : value_if_false
The value of one expression or the other, by a condition, as in JavaScript and
PHP; only the chosen value is evaluated (since 2026-11-01; since 2026-11-18 also
when a value calls a function or a subroutine: before, the arguments of such a
call were computed ahead of the statement whatever the condition, so
n == 0 ? 0 : round(100 * done / n) divided by zero). The condition is any
expression but another conditional, so a + b ? x : y is (a + b) ? x : y; the
two values may themselves be conditionals, which group to the right:
n < 10 ? "small" : n < 100 ? "medium" : "large". To nest a conditional in the
condition, parenthesize it: (a ? b : c) ? 1 : 2.
label = qty > 0 ? "In stock" : "Sold out"
who = item.owner == me ? "You" : item.owner
Object literals
{name: expression, name2: expression}
{}
A record written in place (since 2026-11-01): field names and their values in
curly braces. A field name is an identifier or a string ({"first name": "Ann"});
a value is any expression, a nested literal included; the members may be written
on several lines, and a trailing comma is allowed. The record is a plain value,
not a cloud object: pass it to a function, return it from a subroutine, keep it
in a variable, read it with the dot (r.name) or with get_field, write it as
JSON with json_encode, show it with a data list. On the server it is an
associative array, on the device a plain object, and it crosses between the two
like any other value. An empty record compiled on the server reaches the device
as [] (see the Sets section of §13).
row = {
title: item.name,
price: format_number(item.price, 2),
mine: item.owner == me
}
set_form_values("order_form", {quantity: 1, note: ""})
Array literals
[expression, expression]
[]
A list written in place (since 2026-11-01): values in square brackets, any
expression each, nested literals included, on one line or several, a trailing
comma allowed. A list is read with count, contains, join,
get_field(list, position), sum and the other list functions, grown with
append (items = append(items, item)), and shown by a data list. On the server
it is an array with keys 0, 1, 2...; on the device a JavaScript array.
sizes = ["S", "M", "L"]
rows = [{t: "a", n: 1}, {t: "b", n: 2}]
photos = []
Prefix operators
The prefix operators are - (negation) and ! (logical not). A prefix operator
applies to the single term that follows it: a constant, a variable reference,
a function call, a parenthesized expression, a block, or another prefix
expression. It does not reach across a binary operator:
-x
!done
-a + b is (-a) + b
!done && ready is (!done) && ready
-(a + b) negates the whole sum
!(done && ready)
To negate a whole expression, parenthesize it. (Before 2026-10-28 a prefix
operator took the entire expression that followed it, so -1 + 2 was -(1 + 2);
apps compiled since then get the term-only reading.)
5. Statements
A statement is one of the following:
| Statement | Form |
|---|---|
always block |
always <exp-or-assignment> { ... } |
always statement |
always <exp-or-assignment> |
| client/server conditional | if_on_client <stmt> / if_on_server <stmt> |
| explicit JS / server block | JS< ... >JS, PHP< ... >PHP |
| declaration | declare_location / declare_type / allocate / deallocate |
| assignment | lhs = expression |
| block | { ... } |
| if / if-else | if (cond) stmt [else stmt] |
| subroutine definition | subroutine_def name(params) { ... } |
| return | return expression (the last statement of a subroutine) |
| function call | name(args) |
| bare variable reference | name |
Assignment
The left-hand side is any variable reference, including modified ones; the right-hand side is any expression.
x = 5
total = count * price
record.name = "Ada"
items[i] = compute(i)
Blocks
A block groups statements inside braces. It is itself a statement, so blocks may
be nested and used anywhere a statement is expected (notably as the body of an
if).
{
a = 1
b = 2
doSomething(a, b)
}
if and if/else
if (condition) statement
if (condition) statement else statement
The condition must be parenthesized. The body is a single statement — use a block for more than one statement.
if (total > 20) {
show(total)
}
if (ready)
go()
else
wait()
An
elseclause always binds to the nearestif, so it attaches when present.
foreach
foreach (variable in set_or_list) {
<statements>
}
Runs the block once for each member of a set or a list, the variable holding
the member (since 2026-11-01). The body must be a block in braces; there is no
break or continue, and no return inside a loop. After the loop the
variable keeps the last member.
total = 0
foreach (row in rows) {
total = total + row.amount
}
rows = []
foreach (item in subset(cloudobjects_of_type("item"), "kind", "book")) {
rows = append(rows, {title: item.name, price: format_number(item.price, 2)})
}
Speed. A loop could potentially run slowly when its body has to go back and
forth with the server once per member. When that is so, the compiler warns and
marks the statement concerned: moving that statement out of the loop would let
it run more efficiently. A body that waits (alert, sleep) visits the members
one after the other, each after the previous wait ends.
One variable per loop. A variable keeps one type in the whole app, so a loop
variable that ran over a cloud set in one foreach cannot run over a list (a
literal, an append result, a lookup) in a later one, nor the other way round:
the compiler refuses the second loop (the loop variable "x" runs over a set of
cloud objects in an earlier foreach and over a list here). Give each loop its own
variable, foreach (h in habits) and foreach (row in rows), as the examples do.
In detail: the compiler places a loop as it places an if, as a whole, on the
server when its body needs the server (it creates or changes cloud objects, say)
or its list is a cloud set, and on the device otherwise; a device list is sent
along when the loop runs on the server. A body that mixes a step that can only
happen on the device (an alert, a prompt, a form read, a JavaScript block)
with work that needs the server keeps the loop on the device, and each member's
server work becomes a server call of its own, made in order. The warning marks
the device-only statement: do that step before or after the loop, and the loop
runs on the server in one request.
What the language does not have
There is no while loop and no exponent operator. Iterate with foreach,
the set functions (subset, ordered, count, First, a data_list2 over a
set) and the aggregates (sum, avg, max_of, min_of), or with the repeat
element for timed repetition; build a record or a list with a literal ({name: x},
[a, b], §4) and append; choose a value with cond ? a : b;
convert a form's text to a number with number(s); format, parse and move dates
with the date functions (§13). For what the language
still cannot express (a power, a device API), use a JS< … >JS block, which may
read the activity's device-side variables as Env.<name> and return a value:
balance = JS< Env.p * Math.pow(1 + Env.r, Env.n) >JS.
Bare variable reference as a statement
A lone variable name is a valid statement. It does nothing on its own; it is accepted for the sake of generated and substituted code.
6. Subroutines
subroutine_def <name> ( <parameters> ) { <statements> }
subroutine_def greet(who, times) {
message = concat("hello ", who)
count = times
}
greet("Ann", 2)
greet(user_name, count + 1)
subroutine_def area(w, h) {
return w * h
}
a = area(3, 4)
Subroutines are defined with the subroutine_def keyword and called like an
ordinary function. The definition may name parameters: a comma-separated
list of plain variable names (an expression, a string or a.b is a compile
error), each named once. A body that ends with return <expression> gives the
subroutine a value, and a call of it can then be used as a value (see
Return values).
Arguments
A parameter is an ordinary variable of the activity, not a local of the
subroutine. A call assigns its arguments to the parameters, in order, and then
runs the body: the compiler rewrites greet("Ann", 2) into who = "Ann",
times = 2, greet(who, times), and those assignments are placed like any
other assignment (on the device or on the server, waiting for a pending server
value, updating what depends on the parameter). What follows from this:
- A call passes exactly as many arguments as the definition names
parameters. Any other number is a compile error
(
subroutine "greet" takes 2 arguments, the call passes 1). - After the call each parameter still holds the argument it was given, and it can be read like any variable.
- Two subroutines that name the same parameter share that variable, and a
parameter that has the name of another variable of the app is that
variable. Choose parameter names that are used nowhere else, unless sharing
is wanted. In particular, when one subroutine runs its body on the server
and another on the device, a parameter name they share is placed on the
server by the first and the device-side call of the second is refused
(
attempt to write a server-side variable): give them distinct names, or declare the variable's location. - A subroutine cannot call itself.
- Where a subroutine runs follows its body, like any other code. A body of plain
work (arithmetic, dates, text,
append, a loop over a list, areturn) and a body that needs the server (a cloud object write, alookup) can both be called from the server as well as from the device, so aforeachover a set that calls such a subroutine stays on the server, one request for the whole loop. A body with a statement that can run only on the device (analert, a form read, aJS< >JSblock) makes the subroutine device-side, and a loop over a set that calls it goes back and forth with the server once per member (the compiler warns). Keep the device-only step out of a subroutine that a server loop calls. - An argument that is the parameter itself (
greet(who, times)) assigns nothing. - When an argument reads a parameter that an earlier argument assigns
(
swap(b, a)forsubroutine_def swap(a, b)), the arguments are evaluated first, through temporaries, so that the values do not overwrite one another. - A cloud object may be passed. The parameter then refers to the same object, and the assignment runs on the server, as every cloud-object assignment does.
- Inside a
JS< … >JSblock a parameter is reached asEnv.<name>when it lives on the device, under the same rules as every variable (see JavaScript blocks).
Before 2026-10-29 the parameter list was accepted but ignored, and data went in and out of a subroutine through variables. That code still compiles: a definition without parameters is called without arguments.
Return values
subroutine_def name(parameters) {
<statements>
return <expression>
}
return <expression> ends the body with a value, from anywhere in it (since
2026-11-01; before, only as the last statement of the body or of an if or else
branch that ends it): the statements that follow it, at every level, are not run.
A call of the subroutine can then be used as a value, in an assignment, an
argument, a condition or another return; a subroutine with no return cannot be
used as a value. The value lives in an activity variable named after the
subroutine, a server-side variable when the body ran on the server: like any
other, it reaches the device when a device-side statement reads it, and not
otherwise.
subroutine_def validate(order) {
if (order.qty < 1) {
return {ok: false, msg: "Enter a quantity"}
}
if (order.qty > 99) {
return {ok: false, msg: "At most 99"}
}
return {ok: true, msg: ""}
}
v = validate(get_form_values("order_form"))
if (!v.ok) {
alert(v.msg)
}
- A
returnneeds a value; areturnis allowed only inside a subroutine, and not inside aforeachloop, nor inside anif_on_clientorif_on_serverblock. - A call as a statement runs the body and drops the value.
- No call is allowed in a connector condition.
- The compiler rewrites a return into an assignment of the result variable; when the return is not the last statement, a flag skips the rest of the body.
7. always statements
always declares a reactive binding: the associated logic re-runs whenever
any variable in its source expression changes. (Until 2026-11-01 the statement was
rewritten by the editor alone, so code saved through the MCP got a syntax error on
it; the compiler now does the rewrite for every path.)
always <exp-or-assignment>
always <exp-or-assignment> { ... }
where <exp-or-assignment> is either an assignment or a plain expression.
Reactive assignment
always beta = alpha + 5
beta is kept equal to alpha + 5: the assignment re-executes whenever alpha
(any variable referenced on the right-hand side) changes.
Reactive block
An optional block runs on every update as well:
always beta = alpha + 5 {
log("beta updated to", beta)
}
If the part after always is a bare expression (not an assignment), the
block is mandatory — the expression only names the variables to watch, and
the block is what runs.
always rules and caveats
- A reactive assignment must target a simple named variable (not
a.bora[i]). - The assignment/block runs at least once when the
alwaysstatement is first executed. Analwaysdoes nothing until it is executed: change detection starts only when the flow reaches the statement. Start it on purpose, for example in the entry activity of the page it serves or at app start; analwaysthat no activity ever reaches never fires. - Change detection and the update logic run on the device side only. This
means watched logic is effectively client-side, and the values it depends on
are made available on the device — so do not feed sensitive data (such as
passwords) into an
always. - Recursion is not detected, there is no debounce for rapid updates, and
the debugger does not currently step into
alwaysbodies. Use with care.
8. Declarations
The language infers a variable's type and location wherever it can: an assignment gives the variable the type of the expression assigned to it, and the compiler places each statement, and the variables it uses, on the device or the server from what the statement needs. Declarations supply this information where inference is not available or incomplete, primarily where a variable lives and what type it holds. A declaration advises the compiler; it does not necessarily override a type or location the compiler has inferred, so it is not a way to change what later code implies.
Location declaration
declare_location <name> <location>
where <location> is client or server.
declare_location currentUser server
declare_location scrollPos client
Tells the compiler that the variable belongs on the device or the server, constraining its location decisions where inference leaves them open.
Two occasions call for it:
- Before a
JS< … >JSblock that reads or writesEnv.<name>. The compiler does not look inside a JavaScript block, so it cannot tell which variables the block uses;declare_location <name> clientkeeps the variable on the device so thatEnv.<name>exists there. See JavaScript blocks for the whole rule, including a value the server computes. - When the compiler reports that it cannot decide where a variable lives, or refuses a write to a server-side variable from client code: the error suggests a location declaration, and placing one at the top of the activity resolves it.
Type declaration
declare_type <name> <type>
where a <type> is one of:
array of <type>
object with { <members> }
cloudobject with { <members> }
<type-name>
and a member list is one or more name : type pairs separated by whitespace:
declare_type ids array of number
declare_type point object with { x : number y : number }
declare_type user cloudobject with { name : string age : number }
declare_type score number
cloudobject types denote persistent, server-stored objects; object denotes a
plain structured value.
A type declaration is for a variable whose type the compiler cannot infer or can
infer only in part: a value that comes out of a PHP< … >PHP or JS< … >JS
block, a variable first filled by such a block, a structure whose members later
code needs to know. Where an assignment already determines the type, the
declaration adds nothing and does not necessarily override the inferred type.
Allocation declarations
allocate <name>
deallocate <name>
allocate buffer
deallocate buffer
Declare explicit allocation / deallocation of a named resource.
9. Client/server conditional statements
These run a block only when the code around them has been placed on a given tier:
if_on_client { <statements> }
if_on_server { <statements> }
// sleep one second wherever this code ends up
if_on_client {
JS<P new Promise(function(resolve) { setTimeout(resolve, 1000); }) >JS
}
if_on_server {
PHP< sleep(1); >PHP
}
- The body must be a block in braces. A single statement without
{ }is a syntax error. - They do not move code.
if_on_clientandif_on_serverreact to the compiler's placement decision; they never force it. The body of anif_on_clientcompiled into a server-side section is left out of the app (and anif_on_serverbody in client code likewise). So wrapping a check inif_on_clientbecause the compiler put it on the server does not bring it back to the device: it makes the check disappear. - The body of an
if_on_clientmay not contain anything that can only run on the server (and vice versa); the compiler reports that. - Always write them as a pair, in the same block: an
if_on_client { … }with itsif_on_server { … }, the second empty when there is nothing to do on the server (and the other way round). The pair says explicitly what happens on each tier, and it is how a step is written so that it adapts to wherever the compiler places the code: in a macro, a preset or a reusable routine the same text compiles correctly on either side, and the half that does not apply is dropped on purpose. An unpaired block whose body is left out raises a compile warning (the compile succeeds): the answer is to add the missing half, not to move the code, add location declarations or split the activity. - A check that must stop before a server write is written as such a pair, each
half doing the check for its tier: on the device the
if_on_clienthalf shows the message and aborts; on the server theif_on_serverhalf does the same withabort(...), whose message the user also sees (the device reports it as a failed server request in the console).
10. Macros
Macros (defmacro) are deprecated and no longer documented. Do not write
them: use subroutines to reuse code.
11. Explicit JS and PHP blocks
When you need to drop directly into the target language, use explicit blocks. Everything between the delimiters is passed through as raw target-language code.
JavaScript blocks (client side)
JS< ... raw JavaScript ... >JS
A JS block embeds client-side JavaScript. It may be used as an expression or as a statement.
result = JS< Math.floor(x / 2) >JS
JS<
console.log("hello from the client");
document.title = "ready";
>JS
An asynchronous variant uses the JS<P opener (the P denotes a
promise/async block):
data = JS<P fetch("/api").then(r => r.json()) >JS
Inside a block, a variable of the activity is reached as Env.<name>, and
only when that variable lives on the device.
The compiler does not read JavaScript blocks. Except for the value an expression block returns, it makes no attempt to find out which variables the block reads or writes. Three consequences, and the rules that follow from them:
- A variable the block reads may not be on the device. Put
declare_location <name> clientat the top of the activity for every variable a block reads throughEnv.<name>, so that it lives there.- A block does not wait for a value the server is still computing. Ordinary statements that read a pending server value wait for the server's answer; a JS block runs at once and sees the old value (or
undefinedon the first run). Whenxis assigned by a server-side statement (alookup(...), a cloud-object read) and a block needs it, readxin a plain statement placed between the two (for examplex_count = count(x)orx_ready = x): that statement waits forxand brings it to the device, and the block, which comes after it, sees the new value. Or put the block in the next activity, reached through a connector. (A server value comes to the device only because a device statement reads it; see Where code runs, where values live.)- Writes inside a block are invisible. Do not change a variable by assigning
Env.<name>inside a block: the compiler does not know it changed, so nothing that depends on it (analways, a template, a later server call) is updated. Return the value instead and assign it in Exotool code:total = JS< Env.a + Env.b >JS.Keep the device/server boundary in mind as well: a block runs in the browser, so it must not be handed anything secret. And the block's source travels through the compiler inside a quoted string of its own, so a straight apostrophe in a data literal inside the block (
'the customer's order') can end that string early: use a curly apostrophe (’) orString.fromCharCode(39).
PHP blocks (server side)
PHP< ... raw PHP ... >PHP
A PHP block embeds server-side PHP. It may be used as an expression or a statement.
cmodified = PHP<
$cmodified = array();
foreach($args->modset as $id => $obj) {
$satisfied = !$obj->was_deleted && $args->inquery[$id] && true;
if ($args->session->tracking[$id] != $satisfied) {
$args->session->tracking[$id] = $satisfied;
$cmodified[$id] = $satisfied ? $obj : 'deleted';
}
}
return $cmodified;
>PHP
Values from the surrounding Exotool scope are made available inside server blocks via an
$argsobject, and the block'sreturnvalue flows back out. Exotool handles the conversion of data between the device and the server (for example, JSON values to PHP arrays and back, and the marshaling of cloud objects).
$argsand$outputsare how the compiler learns what the block uses, and they are mandatory. It searches the PHP text for$args->xxxand$outputs->xxxto find the variables the block reads and writes; a variable reached any other way is not passed in or out. In a block used as an expression (x = PHP< … >PHP), read through$args->nameand hand the result back withreturn (...). In a block used as a statement, read through$args->nameand write results through$outputs->name; there is no return value. No type is assumed for a value that comes out of a PHP block: add adeclare_typewhen later code needs to know it.
Records and lists in a PHP block. A record (an object literal, a
json_decoderesult, a record sent from the device) is a PHP associative array there, and a list a PHP array: read$args->order['qty'], not$args->order->qty. A cloud object is an object:$args->item->amount.
Reaching a resource from a block
The resources a project is bound to (Resources in the editor, then the project's roles and its Other resources) are reached only from a block, through two functions the generated app defines; the language itself has no function for them, so that no activity variable ever holds a secret:
- on the device, in a
JS< … >JSblock,exotool.resource("MAPS", "api_key")gives an unprotected field of the resource namedMAPS(a third argument is the default); a protected field is not on the device at all, not even by name; - on the server, in a
PHP< … >PHPblock,exotool_resource("MAPS", "server_secret")gives any field, protected or not (a third argument is the default), answering from a secret store, the environment variableEXOTOOL_RES_MAPS_SERVER_SECRET, the compiled value, then the default, in that order.
A block that returns a protected value makes it an activity variable, and a server variable carried across a cut is written into the session, that is into the app's store: so use a protected value inside the block that consumes it (the request to the provider, the signature), and return only the result. Example:
// the geocoding call needs the server secret: made and consumed in one server block
place = PHP<
$r = @file_get_contents("https://geo.example.com/lookup?q=" . urlencode($args->q)
. "&key=" . urlencode(exotool_resource("GEO", "server_secret")));
return json_decode($r, true);
>PHP
As in every server block, the activity's variable q is read as $args->q and the result
is handed back with return.
12. Debug instrumentation
This is not something you write, but you will see it in compiled output and
should not be surprised by it. The markers are injected by the editor, in the
browser, each time a diagram is saved: the editor keeps the instrumented copy of
each activity's code next to the original (in the diagram's translated_code),
and the compiler builds from that copy rather than the original. The compiler
itself does not add them, so a diagram saved by any other route (for example
through the MCP server) compiles without markers until the editor next saves it.
The markers let the visual debugger follow execution:
- a
DBsource(...)marker at the start of every fragment and subroutine body — it tells the debugger which source text is executing. - a
DBpos(...)marker before each ordinary statement — it tells the debugger which line is executing. - a trailing
DBpos(-1, 0)at the end of a fragment or subroutine to refresh the variable display.
Declarations, blocks, subroutine definitions, and client/server
conditionals are not prefixed with position markers, and a bare (non-block)
if/else body is wrapped in braces so the marker and body stay together.
13. Built-in functions
The activity language ships with a library of built-in functions you can call from any activity. They are organized below by category. Each is shown in the form you call it, with a one-line description.
These summaries are condensed from Exotool's generated online Function Reference, which is the authoritative, always-current source — it gives the full call format, every parameter (with types and which are optional), the return value, and worked examples for each function. Use this appendix as a map; consult the online reference for detail. The online reference also says, for every function, where it runs (Runs on: the server only, the device only, or either side), generated from the compiler's own table: that is the complete and current list of server-only and device-only functions. The language constructs (
subroutine_def,always,JS<…>JS/PHP<…>PHP, declarations, comments, constants) also appear there, but are documented in the body of this manual above.
Access & Security
A permission is decided on the server and stays there: see Where code runs, where values live.
| Function | Description |
|---|---|
create_user(username, password [, type]) |
Creates a new user. Works only when the caller is signed in as an administrator; the user name must be unique. type is any string you choose ("admin" makes an administrator). |
register_user(username, password, confirm_password [, email] [, type]) |
Registers a new user from the app (no administrator needed). The user name must be unique and confirm_password must match password. type is stored as the account's role: login_session returns it as user_type, and on the server it is read from the session: s = get_current_session(), then s.user.type (the two are not written as one chain, which does not compile). |
change_password(...) |
Changes a user's password. Only an administrator, or the user whose password it is, may call it; without that permission it raises an error and shows an alert. |
dologin(...) |
Logs the current session in from submitted login-form values; sets variables reflecting success/failure, among them user_is_admin. Do not let user_is_admin decide whether a sensitive operation is allowed: it is a device-side convenience; use is_admin_user() for the decision itself. |
login_session(...) |
Logs a session in; returns a structure describing the result (logged_in, user_type, …). Normally used by the login-form element rather than called directly. |
logout() |
Logs the current session out. |
logout_session(...) |
Logs a specific session out (normally used internally by the login-form element). |
get_current_session() |
Returns the current session, creating one if none exists (logged_in, user, …). Normally used by the login-form element rather than called directly. |
is_admin_user() |
Whether the logged-in user is an administrator. Always goes to the server and the database, so nothing done on the device can spoof it: use it as the guard of every admin-only step (not the user_is_admin variable). Returns false when nobody is signed in. |
send_sms(to, body) |
Sends a text message (SMS) to a phone number (international form, e.g. "+14155551234"; a ten-digit North American number is accepted as is): a code, a reminder, a notice. Returns "OK" when the provider accepted it, or an error string. Needs the project's SMS Server resource (a Twilio account: Resources in the editor, then the project's SMS role); without one it returns an error string and nothing is sent. 1600 characters at most. |
send_tfa_code(...) |
Sends a two-factor authentication code by email (given an email address or a clouduser). Needs the project's E-mail Server resource. The mail body you pass must contain %CODE%, which is replaced by the code. Only one code is active per session: sending a new one invalidates the previous. |
verify_tfa_code(code [, lifespan]) |
Verifies a two-factor code against the one most recently sent in this session (the person who verifies must be the one who sent). A code is valid for ten minutes by default (lifespan in seconds extends that); a successful verification consumes the code, so it cannot be verified twice. |
Cloud Data
| Function | Description |
|---|---|
create_cloudobject(type [, ...]) |
Creates a new cloud object of the given type. Give the type as a constant string ("Person"): the compiler then produces faster and more secure code. Four forms: create_cloudobject("Person"); create_cloudobject("Person", {name: n, age: 30}), an object literal whose fields are set on the new object (since 2026-11-18; the keys must be plain names); create_cloudobject("Person", "name", n, "age", 30), the same as pairs of field name and value; and create_cloudobject("config", "the_config"), a second argument that is not an object literal, which is the object's identifier (__id, what locate_cloudobject and expect_cloudobject find it by), not a field. A cloud object belongs to the app, not to a user or a device: every user of the app can read it through cloudobjects_of_type, whether or not anyone is signed in. To keep data per user, store the owner on the object (s = get_current_session(), then item.owner = s.user.name; written as one chain, get_current_session().user.name, it does not compile) and filter with subset. There is no device-local storage built in; a value that must survive on one device only is kept with a JS< localStorage… >JS block. |
expect_cloudobject(type [, identifier]) |
Finds a cloud object by type (and optional identifier), creating one if none is found. If several match, one of them is returned. Give the type as a constant string. |
locate_cloudobject(type [, identifier]) |
Finds a cloud object by type (and optional identifier); returns it, or false if none. If several match, one of them is returned. Give the type as a constant string. |
delete(object_or_set) |
Deletes a cloud object, or every object in a cloud set. |
Sets
A set's members are a list. A cloud set itself (what subset or
cloudobjects_of_type gives) stays on the server; what reaches the device, when the set is read
there, bound to a data list, or looked up, is its members, as a list in order: a JavaScript array,
[] when the set is empty (since 2026-11-01; before, the members arrived as an object keyed by
id, as an array, or as {} depending on how the set had been produced). On the server the
language's lookup gives the same list, so get_field(lookup(s), 0) is the first member on
either side. An object's id is its id (or woeid) field. A project that needs the old shape,
because its own JS< … >JS blocks index a server result by id or its templates use {{@key}}
as the id, sets "sets_as_arrays": false in its project settings; the first compile that
changes the shape says so in a compile warning.
| Function | Description |
|---|---|
lookup(set) |
Returns the cloud objects of a cloud set as a list (an array in order). |
count(set_or_array) |
Returns the number of items in a set or array. |
sum(set_or_list [, field]) |
Adds up the numbers of a set or list, or the values of one field of its items (sum(invoices, "amount")); items whose value is not a number are left out; an empty list gives 0. A cloud set is summed on the server, a list where it is. |
avg(set_or_list [, field]) |
The average of the numbers, or of one field; null for an empty list. |
max_of(set_or_list [, field]) |
The largest of the numbers, or of one field; null for an empty list. |
min_of(set_or_list [, field]) |
The smallest of the numbers, or of one field; null for an empty list. |
First(set_or_list) |
The first member of a set (in its order, so most useful with ordered) or of a list; null when there is none. Capitalized: first(...) is a syntax error. |
One(set_or_list) |
One member of a set (useful for locating one object) or the first of a list; null when there is none. Capitalized: one(...) is a syntax error. |
ordered(set_or_list, key [, direction]) |
The set or list sorted by a field, ascending unless "descending"; a list is sorted where it is, stably, numbers numerically and other values as text. |
limited(set_or_list, start [, count]) |
Some of the members, from a position for a count (as for a page). start counts from 0 for the first item, not 1. |
explicit_set(...) |
Returns a set containing specific objects you supply (zero or more). |
superset(set_or_list, more, ...) |
A set or list with more added: each further argument a set, a list or a single object. |
cloudobjects_of_type(type) |
Returns the set of all cloud objects of a given type. Give the type as a constant string whenever you can: the compiler then produces faster and more secure code. |
possible_values(set_or_list, key) |
The different values of a field across the members, as a list. |
subset(set_or_list, key, value [, ...]) |
The members whose field has the value (more pairs narrow it). Every subset function takes a set or a list (since 2026-11-01): a cloud set is filtered on the server and stays a set; a list is filtered where it is and gives a list. Values compare as the stores compare them: numbers numerically, else as text. |
subset_neq(set_or_list, key, value) |
The members whose field is not equal to the value. |
subset_gt(set_or_list, key, value) |
The members whose field is greater than the value. |
subset_ge(set_or_list, key, value) |
The members whose field is greater than or equal to the value. |
subset_lt(set_or_list, key, value) |
The members whose field is less than the value. |
subset_le(set_or_list, key, value) |
The members whose field is less than or equal to the value. |
subset_like(set_or_list, key, pattern) |
The members whose field matches a pattern. The pattern is matched against the whole value, without regard to case (as MySQL's LIKE; since 2026-10-31 the file store agrees), with * as the only wildcard ("*pan*" finds "Fluffy Pancakes"; "pan" does not, nor does SQL's %). A pattern that is still null matches nothing, which empties the list until the variable is set. |
User Input
| Function | Description |
|---|---|
prompt(text [, value_on_cancel]) |
Asks the user for a text value via a modal: text is the question shown. Returns what the user typed, or value_on_cancel when the user cancels (name = prompt("Your name?", "")). Device only. |
confirm(...) |
Asks the user a yes/no question via a modal (confirm or cancel). |
imageprompt() |
Prompts the user to upload an image (a drop zone plus a file picker; on a phone the picker offers the camera and the photo library, so the dialog varies with the device); returns a cloud object (auto-processed into original, mid-size, and thumbnail). When the user cancels or the upload fails, no stored object comes back: the result is empty, so test it (if (photo) { ... }); on a failure an alert is shown and upload_error is set. The image data is kept in the app's database and goes with the object when it is deleted. Its url, midsize_url and thumbnail_url serve the image only to the session the object was handed to (see Where code runs, where values live): show it from the object's fields, never by copying an address. |
fileprompt() |
Prompts the user to upload a file (a drop zone plus a file picker); returns a storedCloudFile cloud object (with url, original_filename, size, mime_type). When the user cancels or the upload fails, no stored object comes back: the result is empty, so test it (if (f) { ... }); on a failure an alert is shown and upload_error is set. The file data is kept in the app's database and goes with the object when it is deleted. The url serves the file only to the session the object was handed to; to give the file to someone else, attach it with send_mail. |
public_link(file [, days [, size]]) |
Makes an address that opens one stored file or image for anyone who has it, without a session: the way to link a file in a mail to someone outside the app. file is the stored object (fileprompt, imageprompt, store_file, or a field that holds one); days how long the address works (30 by default, 365 at most, a fraction allowed); size, for an image, "full" (default), "midsize" or "thumbnail". Returns the complete https:// address, or an empty string with a runtime error when it cannot be made. Server only. The address is signed and cannot be altered; it ends at its expiry or with the file, and cannot be withdrawn sooner. A link made in an app's preview does not open on the deployed app, nor the reverse. Example: send_mail(o.cust_email, "Your summary", concat("<a href=\"", public_link(o.pdf, 30), "\">PDF summary</a>"), from, true). |
store_file(file_name, content [, mime_type]) |
Stores a file the app made on the device (a PDF it built, a CSV it assembled, a text) as a storedCloudFile cloud object, with no dialog, and returns it (its url opens only for this session, as for fileprompt; a file for someone else goes as a send_mail attachment), or false with upload_error set. content is a string (text), a data: URL (a PDF library's or a canvas's output), a Blob or File from a JS block, or an ArrayBuffer; the file name's extension must be one the app accepts (pdf, txt, csv, json, xml, html, css, js, svg, png, jpg, bmp, ttf, woff, mp4, mp3). Runs on the device; the data lives in the app's database like a fileprompt file. |
get_form_values(form) |
Reads the values the user entered in a form in the app. The values are available at any time, whether or not a submit button was pressed; a field the user left empty is null. |
set_form_values(...) |
Sets (changes) the values displayed in a form in the app. |
Modals and Alerts
| Function | Description |
|---|---|
alert(message [, ...]) |
Displays a modal alert until the user clicks OK (extra arguments are concatenated into the message). Unlike JavaScript's alert, it does not stop everything: background work (template updates, incoming signals) goes on; only the statements after it, and the elements that follow in the diagram, wait. |
show_notification(notice [, hold] [, subtitle] [, clickelement]) |
Displays a notification in the app: notice is its title, hold the seconds it stays (30 by default), subtitle a detail text, clickelement the identifier of an activity, page or popup to run or open when it is clicked (or true, to close it on a click). Device only. The subtitle is not shown in the material style; when a clickelement is given, the notification also closes on a click. |
UI Control
| Function | Description |
|---|---|
sync() |
Refreshes the app's data lists with the most current data from the server. |
page_back() |
Navigates the current page back (as a Back link would). |
close_popup([popup]) |
Closes the indicated popup, or all open popups. |
close_panel([panel]) |
Closes the indicated panel, or all open panels. |
sleep(seconds) |
Pauses for a number of seconds (fractional amounts allowed). For short intervals only (a few minutes at most): it runs on the device and does not survive the app being closed. |
abort([message]) |
Stops execution of the current thread, optionally showing a modal message first. |
run_subprocess(...) |
Runs a sub-process defined by a subview. |
Messaging
| Function | Description |
|---|---|
send_signal(channel, message [, url]) |
Sends a push-style signal to active "Listen" elements of this app, or of another app when url is its back-end entry point (a fully qualified address; another app's name is resolved only when both apps sit under the same path on the same server; that send runs as a server call). Not secure: use it to say that something happened, never to carry sensitive data. Non-blocking and non-buffered: there is no guarantee that any instance received it, and a listen receives only what was sent after it started listening. |
| Function | Description |
|---|---|
send_mail(to, subject, body, from [, html_format] [, attachments]) |
Sends an email; returns "OK" or an error message. Needs the project's E-mail Server resource (Resources in the editor, then the project's e-mail role; an SMTP account, or SendGrid or Mailgun through their APIs - the call is the same): without one it returns an error string and nothing is sent. attachments is a stored file (what fileprompt or store_file returns) or a list of them, attached by name and type; 8 MB at most for all of them, else an error string and no mail. |
Time and Date
Timestamps are UNIX timestamps (seconds). Days, hours and names are taken in the
app's timezone: the one given to set_timezone, or America/New_York until
then. The functions run on the server or on the device, with the same result.
| Function | Description |
|---|---|
now() |
Returns the current time as a UNIX timestamp (seconds since 1 Jan 1970 GMT). |
today() |
The timestamp of midnight today in the app's timezone (date_diff(today(), due_at, "day")). |
set_timezone(zone_name) |
Sets the app's timezone for the date functions, an IANA name such as "America/Chicago" or "Europe/Paris"; an unknown name leaves America/New_York. The value lives in the app variable __exotool_timezone, which the compiler places like any other. |
get_timezone() |
The app's timezone name. |
datestring([format] [, timestamp]) |
Formats a date/time with PHP's date() letters (d j D l m n M F Y y H G h g i s a A w N z t L W o S U e T O P c r; a backslash keeps the next letter). Both arguments are optional: the format is "m/d/y g:i:sa" and the time is now unless given. |
date_parse(text [, format]) |
Reads a date, or a date and time, into a timestamp in the app's timezone: "2026-10-31", "2026-10-31 14:30", "2026-10-31T14:30:00Z" (an offset is honored), "10/31/2026", "10/31/26", "10/31/2026 2:30 pm"; with a format in datestring's letters ("d.m.Y"), that shape. Text that is not a date gives null. |
date_part(timestamp, part) |
One part as a number: "year", "month" (1-12), "day", "hour" (0-23), "minute", "second", "weekday" (0 Sunday to 6), "yearday" (1-366). |
date_add(timestamp, amount, unit) |
Moves a timestamp by an amount of "second", "minute", "hour", "day", "week", "month" or "year" (negative to go back). Days, months and years are calendar units in the app's timezone (the time of day is kept across a daylight-saving change). |
date_diff(from, to, unit) |
The whole units from one timestamp to the other, positive when to is later. "day" counts calendar days (the times of day ignored); "month" and "year" count whole calendar months or years; the smaller units count elapsed time, rounded toward zero. |
Math
| Function | Description |
|---|---|
floor(number) |
Returns the integer value of a number, dropping any fractional part. |
ceil(number) |
The next whole number up (2.1 gives 3, -2.1 gives -2). |
round(number [, places]) |
Rounds to a number of decimal places (0 unless given); halves go away from zero on both sides (2.5 is 3, -2.5 is -3, 1.005 to two places is 1.01); negative places round to tens, hundreds. |
abs(number) |
The value without its sign. |
max(a, b [, ...]) / max(list) |
The largest of its arguments, or of a list's items, compared as numbers; null with nothing to compare. |
min(a, b [, ...]) / min(list) |
The smallest, likewise. |
mod(number, divisor) |
The remainder, with the sign of the dividend (mod(-7, 3) is -1); null for a zero divisor. |
format_number(number [, places] [, thousands_sep] [, decimal_point]) |
The number as text with fixed decimals and a thousands separator: format_number(1234.5, 2) is "1,234.50". |
distance(lat1, lng1, lat2, lng2 [, unit]) |
The distance between two points on the Earth, in kilometers, or "mi" or "m". |
String Manipulation
Text functions count characters, not bytes, and run on either side.
| Function | Description |
|---|---|
concat(...) |
Concatenates strings together (arguments that are not strings are converted first). |
lower(text) / upper(text) |
The text in lower or upper case. |
trim(text) |
The text without the spaces, tabs and line breaks at its ends. |
length(value) |
The number of characters of text, of items of a list or a set, of digits of a number; 0 for null. |
substr(text, start [, length]) |
The characters from a position (0 is the first; negative counts from the end), for a length or to the end. |
contains(text_or_list, value) |
Whether text contains a piece of text (case-sensitive), or a list contains a value (same value, same kind: the number 5 is not the text "5"). |
replace(text, search, replacement) |
Every occurrence of a plain text replaced (not a pattern; an empty search changes nothing). |
matches(text, pattern) |
Whether the whole text matches a pattern with * as the only wildcard, without regard to case, as subset_like matches. |
split(text, separator) |
The pieces of the text between the separators, as a list; an empty separator gives the characters. |
join(list [, separator]) |
The items of a list as one text, a comma between them unless another separator is given. |
Values
| Function | Description |
|---|---|
coalesce(a, b [, ...]) |
The first argument that is not missing (null, unset or the empty string); 0 and false are values and are kept, unlike JavaScript's \|\|. |
number(value [, default]) |
Text to a number: a sign, digits, a decimal point and an exponent, spaces around allowed; anything else ("$1,234", "12abc") gives the default, 0 unless given. A form's values are text, so use it before arithmetic. |
is_number(value) |
Whether a value is a number or text that number converts. |
json_encode(value) / json_decode(text) |
A record, list or scalar as JSON text, and back (null when the text is not JSON): the way to keep a list or a record in a text field of a cloud object. |
random_key() |
A random key of 16 hexadecimal characters. |
Records and Lists
A record is a value with named fields: a cloud object, an object literal
({name: x}, §4), or what json_decode or a JS< … >JS block
returns. A field named in the code is read with the dot,
record.name, on either tier and with no declaration needed; a type declaration,
declare_type r object with { name : string }, is for when later code needs the
field types of a record that came from a block. The functions below read a field
by a computed name and build lists.
| Function | Description |
|---|---|
get_field(record, name [, default]) |
The field of that name (a list: that position); the default (null unless given) when it is missing or null. |
has_field(record, name) |
Whether the field exists, even with a null value. |
keys(record) |
The field names as a list (a list: its positions 0, 1, 2...). |
array([value] [, ...]) |
A list of the arguments; array() is the empty list. |
append(list, value) |
A new list with the value at the end; the list itself is not changed, so write items = append(items, item). |
E-Commerce
The payment calls go through the project's E-Commerce Server resource (Resources in the editor, then the project's payments role): a PayPal account, or a Stripe account. With Stripe the card never reaches the app's server: the credit card form hands it to Stripe from the device with the publishable key, and the server charges with the secret key through a payment method id. With Stripe the amounts are in the resource's currency; with PayPal they are in US dollars.
| Function | Description |
|---|---|
usd(number) |
Truncates a number to dollars and cents (e.g. 23.13000001 → 23.13). |
charge_credit_card(cardinfo, total, description) |
Charges a card: cardinfo is a credit card form's values (_cardvalues_). Returns "OK" and sets the server variable transaction_record_id (a transactionRecord with the amount, the description, the card's description and a saved card for repeat charges), or an error string. Needs the E-Commerce Server resource. |
re_charge_credit_card(card, total, description) |
Charges a saved card again: card is the card property of an earlier transaction record. Same result as charge_credit_card. |
authorize_card(cardinfo, total, description) |
Stripe only. Puts a hold on the card for the amount without taking it (a deposit, an escrow, a reservation): "OK" and transaction_record_id (its authorization_state is authorized), or an error string. |
capture_card(transaction_record_id [, amount]) |
Stripe only. Takes the money of a hold, all of it or the smaller amount; "OK" or an error string. A hold can be captured once. |
release_card(transaction_record_id) |
Stripe only. Lets a hold go: nothing is taken. "OK" or an error string. |
14. Quick reference
Keyword summary
Reserved word-like tokens used by the core language and blocks (defmacro is
also reserved, for the deprecated macros):
if else
subroutine_def
always
declare_location client server
declare_type array of object with cloudobject
allocate deallocate
if_on_client if_on_server
null true false (constants; `always` is also one)
Delimiters for explicit blocks:
JS< JS<P >JS PHP< >PHP
Operators
binary: + - * / && || <= < >= > == != & |
The conditional expression `cond ? a : b` binds below every binary operator and groups to the right; object literals `{name: exp}` and array literals `[exp, exp]` are expressions ([§4](#4-expressions)).
prefix: - ! (binds to the next term only: -a + b is (-a) + b)
Remember: binary operators have the conventional precedence levels (* / above
+ - above comparisons above == != above & above | above && above ||)
and associate to the left, as in JavaScript and PHP; parenthesize when in doubt
(see §4).
+ with text. When either side of + is text that is not a number, the two are
joined as text: "Total: " + n gives Total: 5; numbers, and text that holds a
number, add. The same on the device and (since 2026-11-01) on the server; before,
the server refused text with a Server Error. concat() joins values of any kind.