ASON Source Format

ASON is the AltScript Object Notation. It is the source format used for both data and code.

ASON consists of blocks that hold values and words.

Blocks

Array Blocks

Array blocks are free-form containers. Use them for arrays, lists, queues, stacks, and even code. They are denoted by square brackets [ ] and hold a sequence of values, words, or other blocks. Notice there are no commas.

[ 1 2 3 4 5 ]
[ "A" "B" "C" ]
[ 123 4.56 $78.90 ]
[ Mr "John" "Smith" 1990-12-1 john@jsmith.org ]
[
  "Reno" NV
  "Eureka" CA
  "Boston" MA
  "Miami" FL
]
[ <p> 2020-6-18/12:43:50 </p> ]
[ if time > 10:30 [ turn-off back-light ]]
[ at [ 10:22 15:30 ] activate [ front side back ]]
[ TCP address 138.197.200.83 for http://altscript.com ]

So, what are the unquoted words above? They are symbols. They boost the expressive power of ASON considerably. More on this below.

Important Rule: Use white-space not commas to separate values. Commas provide no added benefit, and they prevent blocks from being used for code.

Object Blocks

Object blocks hold key-value pairs. They are denoted by rounded braces { } and hold words (as keys) followed by values or blocks.

{ name: "John Smith" age: 27 }
{ site: "Altscript" url: http://altscript.com }
{ directions: [ up down left right ] }
{
    first-name:  "John"
    last-name:   "Smith"
    birth-date:  1990-7-4
    clock-color: 255.80.30
    wake-time:   [ 7:44 weekdays 9:00 weekends ]
    services:    [ http://spotify.com http://pandora.com ]
    song-id:     #"C23A9F87D457"
}

Special rules apply if the value part on the right contains multiple values. This is still an association block but may require special interpretation as code. That will be covered in the AltScript document, but here’s an example:

{
    start-time: 10:30
    stop-time: start-time + 3:00
}

Expression blocks

Expression blocks are containers just like array blocks except they are used for grouping values and words into evaluated expressions. They are denoted by parentheses ().

( 123 + 456 )
( 10:30 - 3:00 )
( 2021-2-1 - 365 )
( 1.20.00 + 0.0.1 )
( length? first-name )
( "Bob" + " " + "Smith" )
((degrees - 32) / 9) * 5
[ (123 + 456) (10.7 + 8.95) ]

More about evaluation is covered in the AltScript document.

Values

A wide variety of values are recognized directly in source format. You’ve seen some of them in the above examples. Notice that they are written in a simple, obvious way. No special constructors are needed.

Numerical Values

123      - integer
1.23     - decimal floating point
1,23     - decimal alternate format (European)
$1.23    - high precision decimal for currency
1.2.3    - tuple for versions, colors, IP addresses
1..20    - range for indexes
12x340   - pair for X/Y coordinates
#1A2B    - hexadecimal integer

Dates and Times

2021-4-5  - date (year, month, day)
10:23:45  - time (hours, minutes, seconds)
2021-4-5-10:23:45 - date and time
2021-4-5-10:23:45-8:00 - date, time, plus timezone

Strings and Binary

"abc"    - string
''abc''  - long strings (spans many lines or other strings)
<abc>    - hypertext tag
%abc     - file, directory, or path
abc://   - URL/URI
ab@cde   - email address
#"a1b2c" - binary base-16 format (hexadecimal)
##"atbfc"- binary base-64 format

Words

As seen above, words can be used as symbols. They are not the same as quoted strings. They represent a unique symbolic value and can be used symbolically, representing just themselves, or they can be used as variables that hold values. They provide substantial expressive power in ASON.

Words begin with a letter, followed by other letters, numbers, or special characters. There is no distinction between upper and lower case letters. It’s case insensitive.

In the above examples you saw these word formats being used:

abc  - a word, used as variable in code or symbol in data
abc: - define word or key (called a "set-word")

In addition, AltScript programs make use of other forms of words:

:abc - get variable value, unevaluated (get-word)
'abc - refer to word as a value (symbol reference)
.abc - selector for contexts, objects, functions, modules
/abc - refinement for paths and functions
@abc - literal values like @true, @false, @none, @string, @nan

Also, certain types of compound words are supported:

abc.def  - field selection
abc.def: - set a field variable
:abc.def - get a field variable, unevaluated
abc/def  - file path or function refinement

The details of words will be explained in detail in the AltScript section.