@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.I am not sure what they are using, I would ask in #cljdoc
> 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--Ioops. Accidentally wrote @danielcompton rather than @danielmartincraig above. I wish Slack was a little better wrt context 😕
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...
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
@sritchie09 Emmy is Sam Ritchie’s library that I’ve been experimenting with
URL?
What's the best intro docs for learning what this is all about?
Take a look at https://cljdoc.org/d/org.mentat/emmy/0.31.0/doc/reference-manual#_emmy_reference_manual
There’s a lot more in here now, including lots of work on powerful visualizations
But this document provides a decent overview
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))probably not exactly what you want! but the whole library’s built on operator overloading
Thanks. I'll look into it certainly. See what makes sense to expose in YS....
@sritchie09 do you happen to know what http://cljdoc.org uses to format its site?
I need to decide how to format YS docs