Syntax · 3 of 6
Operators
OxiScript has the operators you'd expect from a JavaScript-shaped language. They behave on JSON values.
Arithmetic
| Op | Use | Example |
|---|---|---|
+ | add | a + b |
- | subtract / unary negate | a - b, -x |
* | multiply | price * qty |
/ | divide | total / count |
% | modulo | i % 2 |
proc invoice(qty, unit_price, tax_rate) {
let subtotal = qty * unit_price
let tax = subtotal * tax_rate
let total = subtotal + tax
return {subtotal: subtotal, tax: tax, total: total}
}
Comparison
| Op | Use |
|---|---|
== | equal |
!= | not equal |
< > <= >= | numeric & string ordering |
proc tier(spend) {
if spend >= 10000 { return "platinum" }
if spend >= 1000 { return "gold" }
if spend >= 100 { return "silver" }
return "bronze"
}
Logical
| Op | Use |
|---|---|
&& | and (short-circuits) |
|| | or (short-circuits) |
! | not |
proc can_purchase(user, item) {
if user.is_adult && user.balance >= item.price {
return {ok: true}
}
return {ok: false}
}
proc validate(input) {
if input == null || input.email == null {
abort "email required"
}
return {ok: true}
}
Field access
proc deep(doc) {
let city = doc.user.address.city
let first_tag = doc.tags[0]
let by_key = doc["first name"]
return {city: city, first_tag: first_tag, by_key: by_key}
}
Operator precedence (high → low)
- Field access (
.), index ([]), call (f(...)), unary (-,!) *,/,%+,-<,>,<=,>===,!=&&||
Use parens to make intent explicit:
let ok = (a + b) * c > threshold && user.active
Combining everything
proc score(user, opts) {
let base = user.purchases * 10
let bonus = 0
if user.is_premium {
bonus = 500
}
let final = base + bonus - opts.penalty
if final < 0 {
final = 0
}
return final
}
Note: reassignment (
x = expr without let) parses, but it's the same statement form as let x — variables shadow the previous binding. Practically: just always write let.