yamlscript

Ingy döt Net 2023-07-27T13:53:51.119379Z

I just had some chats with @lee and @borkdude in #clj-yaml and I think it will be pretty easy to have YAMLScript written in Clojure and runnable in the JVM and JS.

Ingy döt Net 2023-07-27T13:57:46.817469Z

https://goo.by/5Puzv - Just tested some of the YS examples (https://rosettacode.org/wiki/Category:YAMLScript) and SnakeYAML (the Java lib under clj-yaml) has no probelm with them. 🙂

hifumi123 2023-07-27T17:29:28.938789Z

is yamlscript ultimately yaml? if so, would it be reasonable to use yamlscript to create yaml templates? it could make a nice alternative to helm while being emitting a manifest that people already send to k8s 😄

Ingy döt Net 2023-07-27T17:36:43.254989Z

@hifumi123 yes. and it's interesting...

Ingy döt Net 2023-07-27T17:37:06.973889Z

Did you happen to watch my talk?

hifumi123 2023-07-27T17:37:48.548199Z

Not yet. I am assuming that is the youtube link in the channel topic?

✅ 1
Ingy döt Net 2023-07-27T17:38:25.011179Z

One of the things I show near the start is a YS program that prints out some data in YAML

Ingy döt Net 2023-07-27T17:39:29.157079Z

and then at the end I show how you can load a .yaml file written in YAMLScript and have it execute to produce the result.

Ingy döt Net 2023-07-27T17:40:11.443579Z

In that case the foo.yaml file starts with:

--- !yamlscript

Ingy döt Net 2023-07-27T17:40:47.998669Z

And you need to use a YAML loader that is aware of how to process that tag

Ingy döt Net 2023-07-27T17:42:27.300709Z

imho, that's what you would want... • To declare with an explicit tag that the following node is YS • To use a YS aware loader to load it

Ingy döt Net 2023-07-27T17:42:47.430129Z

but then you have the full power of clojure 🙂

Ingy döt Net 2023-07-27T17:43:25.034439Z

and data structures in YAMLScript are also coded as YAML

Ingy döt Net 2023-07-27T17:44:14.071229Z

def data =: !
  foo: 1
  prn: 2
prn: data

Ingy döt Net 2023-07-27T17:44:40.013749Z

the first prn is just a string key

hifumi123 2023-07-27T17:44:42.509229Z

Yeah, I remember seeing something like that in the README of the github repo, and it’s what sparked the idea of templating with YAMLScript in my mind 😄

Ingy döt Net 2023-07-27T17:45:05.163879Z

the ! tag says the following node is data

Ingy döt Net 2023-07-27T17:46:03.141269Z

def data =: !hash-map
  foo: 1
  prn: 2
prn: data
would also work as would:
def data =:
  'foo': 1
  'prn': 2
prn: data

Ingy döt Net 2023-07-27T17:48:47.656499Z

@hifumi123 right. This is one thing that I think will make YS become well adopted. The rub is that we need a Clojure platform in every language this is needed.

Ingy döt Net 2023-07-27T17:49:03.850839Z

That's what Lingy is going to do 🙂

hifumi123 2023-07-27T17:50:56.738649Z

I see. At first I was confused at whether Lingy and YAMLScript were “orthogonal”, so to speak. But now it’s all starting to make sense to me. Thankfully, my end goal is just “write some clojure functions and create yaml data” without having to resort to things like nindent and related string manipulation tools in https://pkg.go.dev/text/template

Ingy döt Net 2023-07-27T17:54:55.210249Z

Yeah it's been an interesting journey to get here. At first I thought of YS a year ago and made a toy one. Then I realized to write a lisp I had to know how lisp works. I googled and found https://github.com/kanaka/mal/blob/master/process/guide.md with almost 100 implementations https://github.com/kanaka/mal/blob/master/process/guide.md I took 2 weeks to do that project in Perl and then decided to make Lingy (using my Mal implementation as a start)

Ingy döt Net 2023-07-27T17:56:29.059469Z

Starting with Mal was both good and bad so far. The macro expansion and TCO parts have been great so far, but taking on clojure namespacing was hard.

Ingy döt Net 2023-07-27T17:56:53.301399Z

All the YS classes are subclasses of Lingy classes in the implementations

Ingy döt Net 2023-07-27T17:57:24.155729Z

and only YAMLScript::Reader has any serious amount of code to it

Ingy döt Net 2023-07-27T17:58:33.457919Z

porting that to Clojure will be a big next step.

Ingy döt Net 2023-07-27T17:58:49.400729Z

and fairly simple

Ingy döt Net 2023-07-27T17:59:20.108339Z

@hifumi123 where are you using yaml mostly now?

hifumi123 2023-07-27T17:59:36.799929Z

Pretty much just Helm and anything related to k8s ecosystem

Ingy döt Net 2023-07-27T17:59:51.506519Z

with Go code involved?

hifumi123 2023-07-27T18:00:24.607769Z

Sort of… so Helm uses that golang package I linked above in order to let users define helper functions (written in go) or use pre-existing ones like nindent and printf and default and what not

Ingy döt Net 2023-07-27T18:00:32.724179Z

I'd love to see Helm fall away like an old scab 😂

hifumi123 2023-07-27T18:00:37.461659Z

Oh yeah, me too

hifumi123 2023-07-27T18:01:28.473559Z

I have had to deal with adding some features to a Helm chart recently and it was frustrating. I know the Clojure world has at least one solution to this, but it doesn’t exactly have native YAML data structures https://github.com/barracudanetworks/lighthouse

Ingy döt Net 2023-07-27T18:01:58.310469Z

The main problem with pushing YS forward right now is that Lingy is so young (and also only in Perl)

Ingy döt Net 2023-07-27T18:02:40.939349Z

But if it works with all of JVM and JS then we can really move fast

hifumi123 2023-07-27T18:03:15.215889Z

well, the value i see in lingy is that basically every unix box out there has at least perl 5.18 or some later version 😛

hifumi123 2023-07-27T18:03:32.296519Z

so if lingy can target an “old enough” perl version, there may be very little users have to do to get it running

Ingy döt Net 2023-07-27T18:03:41.187779Z

Except Centos 6 😉

Ingy döt Net 2023-07-27T18:03:59.494079Z

good point.

Ingy döt Net 2023-07-27T18:04:10.724679Z

it targets 5.16.0

👍 1
Ingy döt Net 2023-07-27T18:04:47.974269Z

which is the core maintainers (new as of April) target perl version

Ingy döt Net 2023-07-27T18:05:21.157599Z

we made the decision for perl to have a 10 year rolling eol window

Ingy döt Net 2023-07-27T18:05:42.563089Z

instead of 5.8.1 forever 🙂

Ingy döt Net 2023-07-27T18:06:56.144889Z

I want Lingy to run clojure/core.clj entirely by the end of the year

Ingy döt Net 2023-07-27T18:07:39.710019Z

The Lingy/Perl is kind of a test run to make a blueprint of how to make a clojure anywhere

Ingy döt Net 2023-07-27T18:09:12.361829Z

@pez and I were talking about starting a make-a-clojure project

Ingy döt Net 2023-07-27T18:09:31.450299Z

I just made #make-a-clojure if anyone has interest 😄

hifumi123 2023-07-27T18:11:36.480439Z

Sounds interesting. I am not going to make my own Clojure dialect any time soon, but I did see this talk at Clojure/conj and it was pretty good: https://www.youtube.com/watch?v=Yw4IAY4Nx_o

Ingy döt Net 2023-07-27T18:13:48.393079Z

Yep. Saw that one.

Ingy döt Net 2023-07-27T18:14:20.189459Z

He mentions working on jank for 7 years. I'm hoping to fast track that 😄

Ingy döt Net 2023-07-27T18:15:21.778869Z

Where/When is the next Conj?

hifumi123 2023-07-27T18:33:51.331769Z

This year's was April 27-28 IIRC. We'll have to wait until next year for another one

Ingy döt Net 2023-08-05T16:05:14.737269Z

🎉

Ingy döt Net 2023-07-27T18:17:20.447019Z

I should try a https://www.meetup.com/seajure/

Ingy döt Net 2023-07-27T18:36:03.515999Z

@hifumi123 I forgot that I made this module https://metacpan.org/pod/YAML::PP::YAMLScript 🙂

Ingy döt Net 2023-07-27T18:36:26.336579Z

ie the YS aware YAML loader.