yamlscript

Ingy döt Net 2024-05-11T17:24:07.179699Z

@danielmartincraig (and everyone) YeS-expression operators are polymorphic. Here you can see the * operator used several ways, first with the -c compilation to clojure code, then the runtime results:

$ ys -ce 'say: (* 6 7)'
(say (* 6 7))
$ ys -ce 'say: (6 * 7)'
(say (*_ 6 7))
$ ys -ce 'say: (6 * "seven")'
(say (*_ 6 "seven"))
$ ys -ce 'say: (6 * [7 7 7])'
(say (*_ 6 [7 7 7]))
$ ys -e 'say: (* 6 7)'
42
$ ys -e 'say: (6 * 7)'
42
$ ys -e 'say: (6 * "seven")'
sevensevensevensevensevenseven
$ ys -e 'say: (6 * [7 7 7])'
(7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7)
this is currently not supported
$ ys -e 'say: ([6 6 6] * [7 7 7])'
Error: clojure.lang.PersistentVector cannot be cast to java.lang.Number
but you got me to thinking maybe it should. Not sure what semantics to use. Perhaps when both arguments are vectors we transform them to clojure.core.matrix/matrix objects and use clojure.core.matrix/mmul ? Opinions appreciated.

Sam Ritchie 2024-05-12T18:10:43.046239Z

I am not sure what they are using, I would ask in #cljdoc

👍 1
Ingy döt Net 2024-05-11T17:43:45.473089Z

> Note, in general the YS special syntaxes often do things at a higher level (make decisions based on runtime checks) which is of course slower but makes code cleaner. > However, you can always get YS to produce clojure code you want (without runtime magics). Here's a contrived example with dot chaining and YeS operators:

$ ys -ce 'say: ENV.USER.str/split(/()/).reverse().join(("-" + "-") _).str/upper-case()'
(say
 (__
  ENV
  'USER
  (list str/split #"()")
  (list reverse)
  (list join (+_ "-" "-") '_)
  (list str/upper-case)))
$ ys -e 'say: ENV.USER.str/split(/()/).reverse().join(("-" + "-") _).str/upper-case()'
Y--G--N--I
You can always fall back to a more verbose but more lisp/clojure style:
$ ys -ce 'say: (-> (get ENV "USER") (str/split /()/) reverse (->> (str/join (str "-" "-"))) str/upper-case)'
(say
 (->
  (get ENV "USER")
  (str/split #"()")
  reverse
  (->> (str/join (str "-" "-")))
  str/upper-case))
$ ys -e 'say: (-> (get ENV "USER") (str/split /()/) reverse (->> (str/join (str "-" "-"))) str/upper-case)'
Y--G--N--I

Ingy döt Net 2024-05-11T17:49:03.440489Z

oops. Accidentally wrote @danielcompton rather than @danielmartincraig above. I wish Slack was a little better wrt context 😕

Ingy döt Net 2024-05-11T17:52:01.092849Z

I wonder if there's prior art with going nuts on the polymorphism of the + - * / operators. (not necessarily in Clojure) I prefer to base design decisions on stuff that's already out there...

2024-05-11T18:12:29.330759Z

Emmy has polymorphic + - * and /, that supports a lot of types. I am thinking of wrapping Emmy in a babashka pod so that I can access it in ys

2024-05-11T18:13:38.955209Z

@sritchie09 Emmy is Sam Ritchie’s library that I’ve been experimenting with

Ingy döt Net 2024-05-11T18:23:56.529799Z

URL?

Sam Ritchie 2024-05-11T18:36:30.516139Z

https://github.com/mentat-collective/emmy

Ingy döt Net 2024-05-11T18:38:06.224909Z

Oh Hello, @sritchie09 🙂

👋 1
Ingy döt Net 2024-05-11T18:48:02.101569Z

What's the best intro docs for learning what this is all about?

Sam Ritchie 2024-05-11T19:01:10.221109Z

Take a look at https://cljdoc.org/d/org.mentat/emmy/0.31.0/doc/reference-manual#_emmy_reference_manual

👀 1
Sam Ritchie 2024-05-11T19:01:26.069379Z

There’s a lot more in here now, including lots of work on powerful visualizations

Sam Ritchie 2024-05-11T19:01:35.144769Z

But this document provides a decent overview

Sam Ritchie 2024-05-11T19:35:37.638459Z

the emmy answer here is that vector*vector is the “tensor product”:

emmy.env> (* [6 6 6] [7 7 7])
(up (up 42 42 42) (up 42 42 42) (up 42 42 42))

Sam Ritchie 2024-05-11T19:35:56.803619Z

probably not exactly what you want! but the whole library’s built on operator overloading

Ingy döt Net 2024-05-11T19:37:07.415809Z

Thanks. I'll look into it certainly. See what makes sense to expose in YS....

🤩 1
Ingy döt Net 2024-05-11T19:42:54.443359Z

@sritchie09 do you happen to know what http://cljdoc.org uses to format its site?

Ingy döt Net 2024-05-11T19:43:16.251979Z

I need to decide how to format YS docs