Syntax
Reverse Polish Notation
Ajisai uses RPN (postfix notation). Operators follow operands:
# Traditional: (1 + 2) * 3
# Ajisai:
[ 1 ] [ 2 ] + [ 3 ] * # Result: [ 9 ]
Basic Elements
Comments
# This is a comment
[ 1 2 3 ] # Inline comment
Numbers
42 # Integer
3.14 # Decimal (stored as fraction)
1/3 # Fraction
-5 # Negative
1.5e2 # Scientific notation
Strings
'hello'
'日本語' # UTF-8 supported
Booleans & Nil
TRUE
FALSE
nil
Vectors
# 1D Vector
[ 1 2 3 ]
# 2D Nested Vector
[ [ 1 2 ] [ 3 4 ] ]
# Mixed types
[ 1 'hello' TRUE [ 2 3 ] ]
# All brackets equivalent
[ 1 2 3 ]
{ 1 2 3 }
( 1 2 3 )
Defining Words
Use code block syntax { ... } (or ( ... )) to define words:
# Define a word
{ [ 2 ] * } 'DOUBLE' DEF
# Use it
[ 5 ] DOUBLE # Result: [ 10 ]
# Check if even
{ [ 2 ] MOD [ 0 ] = } 'EVEN?' DEF
[ 4 ] EVEN? # Result: [ TRUE ]
Operation Targets
Stack Top Mode (default)
[ 1 2 3 ] LENGTH # Operates on top element
Stack Mode (..)
a b c .. LENGTH # Operates on entire stack
a b c .. REVERSE # Result: c b a
Pipeline Operator (==)
Visual marker for data flow (no-op). Makes complex transformations readable:
[ 1 2 3 4 5 ]
== { [ 2 ] * } MAP # Double each
== { [ 5 ] < NOT } FILTER # Keep >= 5
== [ 0 ] { + } FOLD # Sum
Nil Coalescing Operator (=>)
Returns alternative value when first value is NIL:
NIL => [ 0 ] # Result: [ 0 ] (NIL replaced)
[ 42 ] => [ 0 ] # Result: [ 42 ] (non-NIL preserved)
# Useful for default values
'key' LOOKUP => [ 'default' ]
Input Helpers
| Helper | Result |
|---|---|
SCALAR | [ ] |
VECTOR | [ [ ] ] |
MATRIX | [ [ [ ] ] ] |
TENSOR | [ [ [ [ ] ] ] ] |