yamlscript 2024-05-16

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

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
🙂

Sorry I missed this earlier.

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

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

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

Sweet! Thanks @sritchie09!

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

$ 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

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

% is the rem operator in YS:

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

(also %% is the mod operator)

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

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

with less parens:

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

Awesome thank you!!

👍 1

You're awake!

I'll review your matrix code more closely now

It looked pretty good when I glanced at it

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

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

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.

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

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

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.

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

So I made I made:

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

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

$ 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)
😄

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

but you can

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

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

But we are talking about making it invalid

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

⬆️ 1

That's spot on

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

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

😁 1

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

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