YAMLScript

Programming in YAML

Synopsis

A YAMLScript program greet.ys to greet someone 6 times: ```

!/usr/bin/env yamlscript

Defined a function called 'main' (entry-point):

main(name): # main args come from ARGV - min =: 1 # Assign 1 to variable 'min' - max =: # max = 6 (-): [10, 4] # 10 - 4 = 6 - for: # Loop over array, calling a function for each - (..): [$min, $max] # Range operator (1-6) - greet: [ $_, $name ] # Call the local 'greet' function

Define another function:

greet(num,name): # Takes 2 arguments - greeting =: Hello, $name! - say: $num) $greeting ```

Run: $ yamlscript greet.ys YAMLScript 1) Hello, YAMLScript! 2) Hello, YAMLScript! 3) Hello, YAMLScript! 4) Hello, YAMLScript! 5) Hello, YAMLScript! 6) Hello, YAMLScript!

Use the YAMLScript REPL: ``` $ ys # or 'ys --repl'

ys> {range: [1, 3]}

Description

YAMLScript is a programming language that uses YAML as a base syntax. It feels like a YAML encoded Lisp, but with fewer parentheses. It takes inspiration from Clojure, Haskell and Perl.

YAMLScript adds various scalar (valid YAML) syntax forms to make coding it clean and flexible.

For instance you could use any of the following syntax forms to define and initialize the x variable to the number 42: - x =: 42 # Special DSL for the `def` function - def: [x, 42] # Literal function call of `def` - (=): [x, 42] # Use the operator alias of `def` - !def [x, 42] # Use YAML tag instead of simgle pair mapping - != [x, 42] # Operator alias tag - !expr [def,x,42] # Tagged expr(ession) - (def x 42) # Lisp/Clojure expression form (as YAML scalar) - (x = 42) # Operator expr using Haskell style - ((=) x 42) # Alternate Haskell style #1 - (x `def` 42) # Alternate Haskell style #2

Take your pick. They are all valid YAML, they all compile to the same AST, they all evaluate to the same result.

YAMLScript's runtime engine is whatever programming language you are using it from. If you are using the yamlscript or ys CLI binaries, it picks one for you. The current prototypes are written in Perl, Python and JavaScript.

YAMLScript functions can be defined in the runtime language or in YAMLScript proper. YAMLScript has module support and they also can be written in either.

This is a powerful concept because it lets you have clean, multilanguage front end code, that can do absolutely anything the runtime language is capable of.

A good usage is writing tests. All of the YAMLScript tests are written in YAMLScript. The exact same test files are run, regardless of the runtime language they are testing, or the specific test framework in that language.

Installation

YAMLScript can be installed in several ways. Once installed you will have access to the yamlscript and ys CLI commands. You will also have library support to invoke YAMLScript directly from Perl, Python or JavaScript.

YAMLScript Language Capabilities

Possible Use Cases

We will write example YAMLScript programs for each of these use cases, in time.

Future Plans

Status

This is very ALPHA software.

Some of the features documented here are not yet implemented:

Everything in the test files definitely works. :)

Authors

Copyright and License

Copyright 2022 by Ingy döt Net

This is free software, licensed under:

The MIT (X11) License