yamlscript

chris nilsson 2025-07-03T01:12:28.483949Z

Hi folks! I'm fumbling my way through, as both a yamlscript and clojure beginner, and having a play with referencing other documents within the same file. I spotted that the $/`$$` style references were replaced a few versions back, so this works ok (I'm using ys 0.1.97, btw):

--- 

sample-data:
  - "foo"
  - 1234

--- !YS-v0

defn main():
  println: _.sample-data 
But was wondering if this load-all approach should be possible as well?
--- !YS-v0

defn main():
  doc =: yaml/load-all(read("$FILE"))
  println: doc.1.sample-data 
  
--- !data

sample-data:
  - "foo"
  - 1234
At the moment, when I run this, it doesn't like the tags:
❯ ys sample.ys
Error: could not determine a constructor for the tag !YS-v0
 in 'reader', line 1, column 1:
    !YS-v0
Just checking if the load/load-all routines are expected to parse tags like this? I'm guessing not, and that I'm missing something fairly basic. I'm likely not YAMLing hard enough. 🙂

Ingy döt Net 2025-07-03T01:14:37.164099Z

You're doing great. Give me a few minutes to finish posting today's Summer of YS blog article.

chris nilsson 2025-07-03T01:16:07.418169Z

Thanks! No rush at all.

Ingy döt Net 2025-07-03T01:19:29.389679Z

You can read https://yamlscript.org/blog/2025-07-02/ys--java-interoperability/ while I respond 😄

👀 1
Ingy döt Net 2025-07-03T01:23:53.860429Z

The specific issue you are having is that you are using https://github.com/clj-commons/clj-yaml standard clojure yaml loader built into ys to load the YS file. It has no idea what to do with the tags 🙂

Ingy döt Net 2025-07-03T01:26:18.119979Z

Loading the file with FILE is clever. Never thought of that.

Ingy döt Net 2025-07-03T01:26:27.357519Z

Let me play with it a sec.

chris nilsson 2025-07-03T01:26:56.259809Z

Ah, that makes sense. It wasn't resolving a plain load-all symbol, so was throwing namespaces at it a bit randomly, it seems.

Ingy döt Net 2025-07-03T01:27:09.588929Z

Is there something specific you want to do or just playing around?

chris nilsson 2025-07-03T01:30:27.129469Z

At the moment, was just trying things out. Had imaginings of loading/dumping to the same file, a little along the lines of tiddlywiki, if you've come across that. But just trying to get comfortable with the language first.

Ingy döt Net 2025-07-03T01:32:29.140699Z

One of my best friends used to work for Jeremy Ruston (the maker of TiddlyWiki). I met Jeremy once or twice with him in London :D

Ingy döt Net 2025-07-03T01:33:22.211019Z

feels like almost 20 years ago!

chris nilsson 2025-07-03T01:33:28.046259Z

Cool! "If you've come across that..." 😆

chris nilsson 2025-07-03T01:35:22.103049Z

Well, thanks for having a look over this so fast, and pointing me the right way. Will keep noodling about and see what I can learn.

Ingy döt Net 2025-07-03T01:36:02.151349Z

Yeah, I'm still noodling with your thing too. Give me some minutes

chris nilsson 2025-07-03T01:36:39.682439Z

Oh, sorry! Didn't want to presume anything there.

Ingy döt Net 2025-07-03T01:53:39.653549Z

still there?

chris nilsson 2025-07-03T01:54:02.618229Z

Yep, still about. 🙂

Ingy döt Net 2025-07-03T01:54:15.035839Z

Create a.ys

--- !YS-v0

defn main():
  doc =: ys/eval(read(FILE) FILE true)
  println: doc.1.sample-data

--- !data

sample-data:
- foo
- 1234

Ingy döt Net 2025-07-03T01:54:45.449609Z

then run ys a.ys

Ingy döt Net 2025-07-03T01:54:53.445939Z

it should hang 🙂

Ingy döt Net 2025-07-03T01:55:39.956699Z

next try ys -x a.ys and I you get what's going on. at least in theory

Ingy döt Net 2025-07-03T01:56:26.042409Z

lemme know when you're caught up

chris nilsson 2025-07-03T01:58:34.501539Z

By hang, I'm seeing a java exception? But looking at the ys -x log, and looks like it's recursing forever (before the exception)?

Ingy döt Net 2025-07-03T01:59:50.430009Z

$ ys -c a.ys | zprint
(defn main
  []
  (let [doc (ys/eval (read FILE) FILE true)]
    (println (get+ (get+ doc 1) 'sample-data))))
(+++ (apply main ARGS))
(% "sample-data" ["foo" 1234])

Ingy döt Net 2025-07-03T02:00:08.484589Z

(zprint is just a clj code prettier)

Ingy döt Net 2025-07-03T02:00:43.401569Z

main is called automatically so yeah, infinite loop

Ingy döt Net 2025-07-03T02:01:19.547709Z

I think I have a solve...

chris nilsson 2025-07-03T02:02:19.729809Z

Hadn't thought of eval.... Having a read of that....

chris nilsson 2025-07-03T02:12:48.251309Z

Ah ok, so that's running eval with steam-mode on? Reading along to see what that does.

Ingy döt Net 2025-07-03T02:13:42.356679Z

I think ys/eval and ys/eval-stream need a little reworking...

Ingy döt Net 2025-07-03T02:18:36.550119Z

wow I got it

Ingy döt Net 2025-07-03T02:18:43.021029Z

wasn't sure I could

🙌 1
chris nilsson 2025-07-03T02:20:07.416349Z

Afraid I'm still parsing eval. 😅 I need to level up my clojure... This is helping with that, but I've a way to go yet.

Ingy döt Net 2025-07-03T02:20:19.036099Z

--- !YS-v0

defonce first-time: true

when first-time:
  alter-var-root var(first-time): \(false)
  doc =: ys/eval(read(FILE) FILE true)
  say: doc
  say: doc.1.sample-data

--- !data

sample-data:
- foo
- 1234

Ingy döt Net 2025-07-03T02:20:44.414169Z

$ ys -U a.ys
[nil {sample-data [foo 1234]}]
[foo 1234]

Ingy döt Net 2025-07-03T02:21:42.503449Z

That's some Clojure stuff I don't use regularly (defonce and alter-var-root)

Ingy döt Net 2025-07-03T02:22:25.240869Z

This idea of yours was sufficiently evil!!!

😄 1
chris nilsson 2025-07-03T02:22:54.432339Z

Apologies! Hope it was a little fun though.

Ingy döt Net 2025-07-03T02:23:03.970399Z

totally

Ingy döt Net 2025-07-03T02:23:19.688629Z

keep em coming

Ingy döt Net 2025-07-03T02:25:01.583209Z

I think ys/eval-stream was what you want, but doesn't work on itself like that

Ingy döt Net 2025-07-03T02:25:15.227699Z

lemme try something more

Ingy döt Net 2025-07-03T02:27:04.698479Z

ok here's my cleaned up version:

--- !YS-v0

defonce first-time: true

when first-time:
  alter-var-root var(first-time): \(false)
  doc =: FILE:read:ys/eval-stream
  say: doc
  say: doc.1.sample-data

--- !data

sample-data:
- foo
- 1234

chris nilsson 2025-07-03T02:27:15.169419Z

> keep em coming Will try. Off topic, a bit. We're currently doing the big helm migration at work, so I'm aiming to get my head into this game and get yamlscript in there, like you're doing with helmys. But that's what kicked me off learning. Enjoying my travels so far.

Ingy döt Net 2025-07-03T02:27:56.581049Z

oh hey, I'd really like to help you on that

Ingy döt Net 2025-07-03T02:28:40.074039Z

I'm trying to get HelmYS into Helm 4, but I need some real use cases to push it

Ingy döt Net 2025-07-03T02:29:10.387279Z

let's move to DM