YAMLScript

No Change
assess
First Added:April 9, 2024 Updated: July 2, 2026

YAMLScript. (YS) is valid YAML, however, it is not API compatible with YAML.

Blurb

Programming in YAML. Contribute to yaml/yamlscript development by creating an account on GitHub.

Summary

Garden stance: We assess YAMLScript for our estate.

Overview: All YS files must start with !yamlscript/v0/data, or a SheBang (#!). This will cause non-compliant parsers to fail, and instruct compliant ones on which language to use for the rest of the file.

Example Data

1
2
3
4
!yamlscript/v0/data

base =: 42
example: int(base)

will result in

1
example: 43

Example Program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env ys-0

# Print the verses to "99 Bottles of Beer"
#
# usage:
# ys 99-bottles.ys [<count>]

defn main(number=99):
 each [n (number .. 1)]:
 say: paragraph(n)

defn paragraph(num): |
 $bottles(num) of beer on the wall,
 $bottles(num) of beer.
 Take one down, pass it around.
 $bottles(num - 1) of beer on the wall.

defn bottles(n):
 cond:
 n == 0 : 'No more bottles'
 n == 1 : '1 bottle'
 =>  : "$n bottles"

main is the entry point and all command line arguments are split as function arguments. Builtins like each, say, cond take zero or more arguments and perform work given by their object definition. User defined functions are called using ().

This is a functional language and thus the program and object definitions are unordered. For example in cond the “=>” string indicates the default case; it is only placed last as a convention. This also means that all conditions have to be fully evaluated before the default case can be chosen. Not usually a issue, but something to be aware of.

In paragraph the | indicates that the next block is text. The $ in the block is interpolation.

Details

Example Data

1
2
3
4
!yamlscript/v0/data

base =: 42
example: int(base)

will result in

1
example: 43

Example Program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env ys-0

# Print the verses to "99 Bottles of Beer"
#
# usage:
# ys 99-bottles.ys [<count>]

defn main(number=99):
 each [n (number .. 1)]:
 say: paragraph(n)

defn paragraph(num): |
 $bottles(num) of beer on the wall,
 $bottles(num) of beer.
 Take one down, pass it around.
 $bottles(num - 1) of beer on the wall.

defn bottles(n):
 cond:
 n == 0 : 'No more bottles'
 n == 1 : '1 bottle'
 =>  : "$n bottles"

main is the entry point and all command line arguments are split as function arguments. Builtins like each, say, cond take zero or more arguments and perform work given by their object definition. User defined functions are called using ().

This is a functional language and thus the program and object definitions are unordered. For example in cond the “=>” string indicates the default case; it is only placed last as a convention. This also means that all conditions have to be fully evaluated before the default case can be chosen. Not usually a issue, but something to be aware of.

In paragraph the | indicates that the next block is text. The $ in the block is interpolation.