yamlscript

2024-05-16T02:13:08.164749Z

I did this matrix multiplication toy implementation based on some code that @sritchie09 put on stack overflow years ago, and it’s got me thinking that yamlscript is just as approachable as Python https://github.com/danielmartincraig/yamlscript-experiments/blob/master/matrix.ys

Ingy döt Net 2024-05-17T22:01:43.569699Z

Very nice:

$ curl -s  | time ys -
((3 2 1) (6 5 4) (9 8 7))
0.00user 0.03system 0:00.08elapsed 42%CPU (0avgtext+0avgdata 48000maxresident)k
0inputs+0outputs (0major+4746minor)pagefaults 0swaps
🙂

Ingy döt Net 2024-05-17T22:02:15.581239Z

Sorry I missed this earlier.

Ingy döt Net 2024-05-17T22:02:35.196799Z

How do I get all messages in #yamlscript to notify me?

Ingy döt Net 2024-05-17T22:03:00.521449Z

I just get notifications for mentions and threads I'm active in...

Sam Ritchie 2024-05-20T20:34:11.923129Z

Sam Ritchie 2024-05-20T20:34:21.450209Z

click on the channel name to get settings, then change the dropdown here

Ingy döt Net 2024-05-20T20:36:46.180369Z

Ingy döt Net 2024-05-20T20:36:57.296099Z

Sweet! Thanks @sritchie09!

2024-05-16T02:13:59.376549Z

What’s the syntax for an anonymous function in yamlscript? Apologies if you already explained to me

Ingy döt Net 2024-05-17T22:05:33.033019Z

$ ys -e 'foo =: \(%1 * %2)' -e 'foo: 6 7' -c
(def foo (fn [& [_1 _2]] (*_ _1 _2)))
(foo 6 7)

$ ys -e 'foo =: \(%1 * %2)' -e 'foo: 6 7' -p
42

Ingy döt Net 2024-05-17T22:06:08.800479Z

Note that you can't use %, you need to use %1

Ingy döt Net 2024-05-17T22:07:23.464579Z

% is the rem operator in YS:

$ ys -e 'say: 42 % 13'
3

Ingy döt Net 2024-05-17T22:07:54.633689Z

(also %% is the mod operator)

Ingy döt Net 2024-05-17T22:09:57.954229Z

Of course you can always use fn (as in clojure)

$ ys -e 'foo =: (fn [a b] (a * b))' -e 'foo: 6 7' -p
42

Ingy döt Net 2024-05-17T22:12:41.449229Z

with less parens:

$ cat x.ys 
!yamlscript/v0
foo =:
  fn [a b]: a * b
say:
  foo: 6 7
$ ys x.ys 
42

2024-05-17T23:06:02.838189Z

Awesome thank you!!

👍 1
Ingy döt Net 2024-05-17T23:06:35.794899Z

You're awake!

2024-05-17T23:59:53.966529Z

Ha yes I am!

2024-05-18T00:00:11.236689Z

This is great help

Ingy döt Net 2024-05-18T00:00:48.175999Z

I'll review your matrix code more closely now

Ingy döt Net 2024-05-18T00:01:04.662169Z

It looked pretty good when I glanced at it

Ingy döt Net 2024-05-18T00:15:13.365789Z

I did a bunch of things different to show off various ways to do things

Ingy döt Net 2024-05-18T00:15:40.835699Z

My way is not the correct way, just an alternate way

Ingy döt Net 2024-05-18T00:20:26.842529Z

The one thing that YS won't do for you is offer a single syntax, like a Lisp does. I know some people like this because it keeps that part of the language simple. YS lets you do stuff in lots of ways. Some are close to Lisp and some avoid all parens, and some are in between. But if you ok with that, YS can offer you some really cool syntactic things.

Ingy döt Net 2024-05-18T00:21:44.151089Z

One thing I struggle with constantly is remembering argument order for things like take and nth and pretty much anything that takes multiple args

2024-05-18T00:23:01.478549Z

This is great, I’m intrigued by moving the : to the places where you moved it

Ingy döt Net 2024-05-18T00:23:38.408189Z

get-some-seq().take(5) used to blow up because the seq gets inserted first. One solution is get-some-seq().take(5 _) which works but angered me.

2024-05-18T00:24:53.939999Z

apply map vector: m is different than I was expecting, I think I thought the : always had to follow the first thing in the expression

Ingy döt Net 2024-05-18T00:24:55.493979Z

So I made I made:

$ ys -ce 'get-some-seq().take(5)'
(__ (get-some-seq) (list +take 5))

Ingy döt Net 2024-05-18T00:26:23.927289Z

and +take checks it's args and DTRT. slower but cleaner and no need to remember. If speed counts then:

$ ys -ce 'get-some-seq().take(5 _)'
(__ (get-some-seq) (list take 5 '_))
is still available

Ingy döt Net 2024-05-18T00:27:39.200099Z

$ ys -ce '
a: b c d
a b: c d
a b c: d
a b c d:'
(a b c d)
(a b c d)
(a b c d)
(a b c d)
😄

Ingy döt Net 2024-05-18T00:29:25.943819Z

if:
  (a > b)
  bar
  baz
works fine, but I'd rather see:
if (a > b):
  bar
  baz

Ingy döt Net 2024-05-18T00:30:28.298649Z

but you can

if (a > b) bar: baz
if that's your thing 🙂

Ingy döt Net 2024-05-18T00:33:05.251929Z

We don't support:

$ ys -ce ': a b c d'
Error: while parsing a block mapping
 in reader, line 2, column 1:
    : a b c d
    ^
That's SnakeYAML-Engine's fault not mine. It's actually valid YAML according to the 1.2 spec: https://play.yaml.io/main/parser?input=OiBhIGIgYyBk

Ingy döt Net 2024-05-18T00:33:27.359799Z

But we are talking about making it invalid

2024-05-18T00:33:52.482659Z

Haha oh my gosh so the : can be anywhere that makes sense to the author almost

⬆️ 1
Ingy döt Net 2024-05-18T00:34:34.393719Z

That's spot on

Ingy döt Net 2024-05-18T00:35:08.121219Z

That reminds me, today I got a replacement for SnakeYAML working. RapidYAML (world's fastest known YAML parser in C++)

2024-05-18T00:36:21.570999Z

Ooh nice

Ingy döt Net 2024-05-18T00:36:54.520859Z

Integrating C++ into Clojure isn't for the faint of heart 😄

😁 1
Ingy döt Net 2024-05-18T00:37:38.131739Z

in the next release you can enable it with export YS_PARSER=rapidyaml

Ingy döt Net 2024-05-18T00:38:24.904239Z

It comes as a shared library with a JNA wrapper. Still working on the cleanest install strategy.