yamlscript

Eric Promislow 2025-08-07T21:49:45.939339Z

I'm failing the configurable hello-world test with this particular instance: cron.template:

!YS-v0:

apiVersion: batch/v1
kind: CronJob
metadata:
  name:: $(ENV.CRON_NAME)
spec:
  schedule: "*/7 * * * *"
  ...
And when I run:
$ CRON_NAME=blip ys -Y cron.template
Compile error: Odd number of elements in map
What am I missing/getting wrong?

Eric Promislow 2025-08-07T21:50:55.232179Z

Also would it be possible to include line numbers (and columns) in error messages?

Eric Promislow 2025-08-07T22:26:34.682449Z

I worked it out. Actually I should say Chris O worked it out -- the $(ENV.CRON_NAME) part needs to be double-quoted. And some error messages do include line numbers

Ingy döt Net 2025-08-07T22:50:51.130409Z

Hi @eric.promislow

Eric Promislow 2025-08-07T22:51:06.732359Z

afternoon

Ingy döt Net 2025-08-07T22:51:37.571239Z

simply:

name:: ENV.CRON_NAME
would be fine

Ingy döt Net 2025-08-07T22:52:10.301909Z

"... $(...) ..." is interpolation syntax

Eric Promislow 2025-08-07T22:52:11.695379Z

I'll try that.

Eric Promislow 2025-08-07T22:52:20.627079Z

exactly

Ingy döt Net 2025-08-07T22:52:39.337839Z

but you aren't interpolating an expression into a string

Eric Promislow 2025-08-07T22:52:46.263679Z

Took a little more wrangling to make one line in an array interpolatable and landed on - ! "..."

👍 1
Ingy döt Net 2025-08-07T22:54:04.994769Z

well don't interpolate just to get a variable or expression value

Ingy döt Net 2025-08-07T22:54:14.046089Z

just use the var or expr

Ingy döt Net 2025-08-07T22:54:53.167589Z

if you need it inside a string then interpolate using double quoted or literal style scalars in code mode

Eric Promislow 2025-08-07T22:55:02.238549Z

The final line is the last part of a complex ["bash", "-c", "CMD ; CMD ; ... CMD"]

Eric Promislow 2025-08-07T22:55:13.969249Z

Anyway I have it working

Ingy döt Net 2025-08-07T22:55:35.137149Z

you can dm it to me if you want a review

Ingy döt Net 2025-08-07T22:55:41.526289Z

but glad it works 🙂

Eric Promislow 2025-08-08T01:09:31.008599Z

Sorry to bother you, how is this supposed to work. With input:

!YS-v0:

let:
  name:: ENV.CRON_NAME
  match: (re-matches #".*bb(\d+)t(\d+)" name)
do:
  spec:
    name:: name
    # match:: match
how do I formulate a match?
$ CRON_NAME=ct13bb29t4 ys -Y  cron.template3
let:
  name: ct13bb29t4
  match: (re-matches
do:
  spec:
    name: !!clojure.core$name {}
I figured I could deconstruct the name to pull out a version and a minutes value but am running into issues. Not much in the docs. Gemini, our official recommended AI tool, came up with plenty of erroneous suggestions. Anyway have to go now. This is a very interesting tool inlining lisp into yaml - I just need to read the docs more thoroughly and pick up the subtleties

Ingy döt Net 2025-08-08T01:13:10.965469Z

I'm at a restaurant but I can answer in about 30 minutes

Ingy döt Net 2025-08-08T02:24:46.418259Z

@eric.promislow this should give you insight: https://gist.github.com/ingydotnet/8598725ed647f4aa3339a2103b7406c8 There's lots of ways to write things. Feel free to ask questions. And also point out places that need better doc.

Ingy döt Net 2025-08-08T02:27:04.008769Z

it should be obvious but the 3rd command there ys -U -c ... (you can use -Uc as well) is the YAML compiled to Clojure.

Ingy döt Net 2025-08-08T02:30:30.045209Z

BTW, -U is to compile mappings to {"a" 1, "b" 2} (normal mapping with unordered keys) rather than the default (% "a" 1, "b" 2) (ordered mapping). I just thought the output would be easier to read.

Ingy döt Net 2025-08-08T12:50:34.653489Z

This is a very interesting tool inlining lisp into yaml@eric.promislow I realized that I think you have a misunderstanding of what YS is... It's not inlining lisp into yaml. The entire yaml file is a lisp program. IOW, YS is a complete Lisp with a YAML syntax. Every YAML data file is a valid YS "program". A program that evaluates to the data value that it expresses. Take any YAML (or JSON, since JSON is YAML) file and run ys -c any.yaml and it will output Lisp (Clojure) code. Sure, given a regular YAML, that lisp code is just lisp syntax for a data mapping or vector literal. When you run ys -Y file.yaml the file is read, compiled to clojure/lisp, evaluated by a clojure runtime to a single value, and then the value is printed (as YAML since you chose -Y). Hope that makes it clearer. 🙂

Ingy döt Net 2025-08-08T12:50:44.376759Z

@chris032 ^^