Fork me on GitHub
#yamlscript
<
2024-06-03
>
Ingy döt Net11:06:20

I'm working on organizing my ~200 to-do items for YAMLScript (big and small) that are in various places. I want to get most of them into public GitHub issues and label/prioritize/organize them appropriately. Many of these are in a GitHub Project that is private. I was able to export to TSV which is nice. GitHub API access requires GraphQL. This got me to thinking that maybe GraphQL usage is a great targeted domain for YS. I found this very nice Clojure library to build off of: https://github.com/walmartlabs/lacinia Excited to explore this a bit.

Ingy döt Net15:06:53

Well I'll be... I was talking about having implemented tag functions in YS like !str/upper-case: and !merge*: But then I couldn't get it working so thought maybe I dreamed I wrote that 😄 Found it: https://github.com/yaml/yamlscript/blob/main/core/test/compiler-stack.yaml#L649-L687

$ cat foo.ys 
--- &a-map
foo: 111
bar: 222
baz: 333

--- !yamlscript/v0/

- !merge*: [*a-map, {derp: 444}]

- !merge*:
  - *a-map
  - foo: 444
    derp: 555

- !merge*:
  - *a-map
  - foo: !str/upper-case: hello
    derp: 555

$ ys -Y foo.ys 
- foo: 111
  bar: 222
  baz: 333
  derp: 444
- foo: 444
  bar: 222
  baz: 333
  derp: 555
- foo: HELLO
  bar: 222
  baz: 333
  derp: 555

Ingy döt Net16:06:17

I just implemented a very useful thing I've wanted for some time. The ability to write raw Clojure code as part of a YAMLScript file.

$ cat foo.ys 
!yamlscript/v0

=>: !clj |
  (defmacro qq [x]
    `(quote ~x))

say:
  qq: (1 2 3)

$ YS foo.ys 
(1 2 3)
YS doesn't yet have the syntax for defining Clojure macros (backtick, tilde, etc). This will be very useful for doing things in YS where the language isn't quite entirely ready for.

👍 2
🎉 1
Ingy döt Net16:06:06

Note this isn't released or even pushed yet. I'll probably play with it on a branch for a couple days...

Ingy döt Net16:06:00

Interesting that it -c compiles with macros expanded.

$ YS foo.ys -c
(defmacro
 qq
 [x]
 (clojure.core/seq
  (clojure.core/concat
   (clojure.core/list 'quote)
   (clojure.core/list x))))
(say (qq (1 2 3)))
Not entirely sure I want that.

Ingy döt Net16:06:10

pushed to branch clj-raw

chromalchemy22:06:29

I share that with appreciation of how yamlscript smuggles in a “real” (not greenspun) lisp.

bsb07:06:27

> It's likely people who already use YAML and want it to do more; not just in k8s or GHA but anywhere they use it. I think the entry point could be data templating, ie. "this YAML is quite repetitive, how can I reduce it?"

Ingy döt Net09:06:45

By year end I'd like to see YS be the preferred YAML loader (for plain old YAML usage) in every major language. The challenge will get be to get major players like GHA (CircleCI etc) to adopt it natively. But people can do things like this in the mean time...

bsb09:06:34

https://github.com/BetterThanTomorrow/calva/blob/2952822ac64a4e85d0e28031749ab44d1df8aac4/.circleci/config.ys yes Every context using yaml ends up with hacked in "include", "for", templating, etc. I've done it myself