yamlscript 2025-01-16

I released https://github.com/yaml/yamlscript/releases/tag/0.1.88 today. @danielmartincraig the java-time and std/now are in there. The polymorphic infix + now adds functions. (fn1 + fn2 + fn3) == comp(fn3 comp(fn2 fn1)) Also (fn1 + not-fn) == partial(fn1 not-fn) The big update is the use command updates. I'll write that up separately.

🎉 1

To date YS hasn't had good support for external libraries. You could load('some/file.ys') or 'some/file.clj. You could use: some::name which would look for a some/name.ys or some/name.clj in YSPATH or the dir of the running file. > Note YS replaces 5 or 6 clojure functions like use but you can always get the original ones with clj/use etc. I want to have use handle all externals including ys libs, clojure libs and bb pods, and also handle the deps coordinates. I want it to be able to use code from maven, clojars, github, gitlab, gists, urls, local filesystem etc. I want YS code to not need require at all. Here's some of what that looks like:

use: foo
use: foo::bar
use foo::bar: :as fb
              :get foo bar
use foo::bar: :all :not baz
use:
  foo::aaa: :as fa :mvn 'group/artifact/version'
  foo::bbb: :git 'github:user/repo/ref'
  foo::ccc: :url ''
  foo::ddd: :file 'some/file.ys'
  foo::eee: :path 'some/dir:other/dir'

❤️ 2

@delon ^^ 🙂

😎 1

Here's how that compiles

$ ys -ce "
use: foo
use: foo::bar
use foo::bar: :as fb
              :get foo bar
use foo::bar: :all :not baz
use:
  foo::aaa: :as fa :mvn 'group/artifact/version'
  foo::bbb: :git 'github:user/repo/ref'
  foo::ccc: :url ''
  foo::ddd: :file 'some/file.ys'
  foo::eee: :path 'some/dir:other/dir'

"
(use foo)
(use foo.bar)
(use foo.bar :as fb :get foo bar)
(use foo.bar :all :not baz)
(use
 (foo.aaa :as fa :mvn "group/artifact/version")
 (foo.bbb :git "github:user/repo/ref")
 (foo.ccc :url "")
 (foo.ddd :file "some/file.ys")
 (foo.eee :path "some/dir:other/dir"))

Obviously you don't have to put the deps next to the libraries but you can.

So far I only support loading from YSPATH and these keywords: :url :as :get :all :not

I think that YS code will have no use for require . use should be able to do it all.

The :url caches its download, and :git will too. The :mvn parts should try to work like bb.

I still have quite a bit to figure out but I'm happy to at least be able to share code that can make use of externals.

@danielmartincraig speaking of that, I wanted to write a nice time library in YS. Now I'll be able to do that as something external. I'll probably try to keep as many libs as possible be external.

As I understand it, the limitation is that all required java code needs to be compiled into the ys (or bb) binary by graalvm native-image.

From another discussion here's some points about how YS can make code easier to write and read:

$ bb -e '(-> 2 (repeat 10) (concat [0]) (->> (take 3)))'
(10 10 0)
$ bb -e '(->> 2 (repeat 10) (concat [0]) (take 3))'
(0 2 2)
$ bb -e '(as-> 2 _ (repeat _ 10) (concat _ [0]) (take 3 _))'
(10 10 0)
$ ys -pe '2.repeat(10).concat([0]).take(3)'
(10 10 0)
$ ys -ce '2.repeat(10).concat([0]).take(3)'
(+take (concat (+repeat 2 10) [0]) 3)
at the expense of +take inspecting arg types. But also YS always has ways for you to get the clojure you want when it is important:
$ ys -pe '2.repeat(_ 10).concat([0]).take(3 _)'
(10 10 0)
$ ys -ce '2.repeat(_ 10).concat([0]).take(3 _)'
(take 3 (concat (repeat 2 10) [0]))
Same concept with the polymorphic infix operators:
$ ys -ce '(a + b + c)'
(add+ a b c)
$ ys -ce '(a + b)'
(add+ a b)
$ ys -ce '(+ a b)'
(+ a b)
$ ys -ce 'a(+ b)'
(a + b)