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. 🙂You're doing great. Give me a few minutes to finish posting today's Summer of YS blog article.
Thanks! No rush at all.
You can read https://yamlscript.org/blog/2025-07-02/ys--java-interoperability/ while I respond 😄
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 🙂
Loading the file with FILE is clever. Never thought of that.
Let me play with it a sec.
Ah, that makes sense. It wasn't resolving a plain load-all symbol, so was throwing namespaces at it a bit randomly, it seems.
Is there something specific you want to do or just playing around?
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.
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
feels like almost 20 years ago!
Cool! "If you've come across that..." 😆
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.
Yeah, I'm still noodling with your thing too. Give me some minutes
Oh, sorry! Didn't want to presume anything there.
still there?
Yep, still about. 🙂
Create a.ys
--- !YS-v0
defn main():
doc =: ys/eval(read(FILE) FILE true)
println: doc.1.sample-data
--- !data
sample-data:
- foo
- 1234
then run ys a.ys
it should hang 🙂
next try ys -x a.ys and I you get what's going on. at least in theory
lemme know when you're caught up
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)?
$ 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])(zprint is just a clj code prettier)
main is called automatically so yeah, infinite loop
I think I have a solve...
Hadn't thought of eval.... Having a read of that....
https://github.com/yaml/yamlscript/blob/main/core/src/ys/ys.clj#L62-L76
Ah ok, so that's running eval with steam-mode on? Reading along to see what that does.
I think ys/eval and ys/eval-stream need a little reworking...
wow I got it
wasn't sure I could
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.
--- !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
$ ys -U a.ys
[nil {sample-data [foo 1234]}]
[foo 1234]That's some Clojure stuff I don't use regularly (defonce and alter-var-root)
This idea of yours was sufficiently evil!!!
Apologies! Hope it was a little fun though.
totally
keep em coming
I think ys/eval-stream was what you want, but doesn't work on itself like that
lemme try something more
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> 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.
oh hey, I'd really like to help you on that
I'm trying to get HelmYS into Helm 4, but I need some real use cases to push it
let's move to DM