It's become somewhat clear that YAML is a poor programming language, and yet countless projects and systems continually reinvent half-baked domain-specific programming languages on top of YAML. Even worse are templating engines designed to emit YAML, but which are completely unaware of the YAML/JSON object model.
One could attribute this to Greenspun's Tenth Rule, although the resulting YAML-embedded DLSs are often markedly uglier and less featureful than Common Lisp.
So let's just cut to the chase and build a half-decent programming language
instead of "accidentally" doing it over and over again (poorly): jspr is a
Lisp-inspired programming language that is entirely representable within a
JSON/YAML document.
Here is a very simple jspr program written as a YAML document:
- user-home=:
- if: .isWindows
- then: [getenv: Profile]
- else: [getenv: HOME]
- [print: 'User home directory is "{}"', with:seq: [.user-home]]This will simply print the directory path of the user's home directory, which is
obtained from either the Profile or the HOME environment variable, depending
on the value of isWindows.
The above makes use of several syntactic-sugar elements of jspr that make the
program more concise and readable in YAML, especially with good syntax
highlighting. The equivalent document in raw JSON is somewhat uglier:
[
{"user-home=": [
{"if": ".isWindows"},
{"then": [{"getenv": "Profile"}]},
{"else": [{"getenv": "HOME"}]}
]},
[{"print": "User home directory is \"{}\""}, {"with": ["seq", [".user-home"]]}]
]Using jspr's array-based syntax can result in a JSON document with less
punctuation noise:
[
["let", "user-home",
["if", ".isWindows",
["getenv", "Profile"],
["getenv", "HOME"]
]
],
["print", "User home directory is \"{}\"", ["list", [".user-home"]]]
]From the above, it may be easier to see how jspr is "Lisp-inspired."