YamlScript

No Change
assess

YAMLScript (YS) is valid YAML, however, it is not API compatible with YAML. Therefore, even if example.ys can be read by a YAML interpreter the output would not contain the same objects as the parsed YS. Currently no main stream programs use it, but we are optimistic that it might eventual replace Go Templates for things like Helm. But until that happens you have to assess if it suits your needs.

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

!yamlscript/v0/data

base =: 42
example: int(base)

will result in

example: 43

Example Program

#!/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 as the program and object definitions are unordered. For example in cond the “=>” string indicates the default case; it is only placed 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.