Fork me on GitHub
#meander
<
2020-11-19
>
jose10:11:49

Very interesting work to support babahska. Related to that, what is the current status of compiling a meander application with graalvm? It would be nice to use meander in a clojure compiled app. I didn't test it, but I suspect that currently, a clojure app will fail to compile if it depends on meander. But I also suspect that the changes to support babashka will help in compiling meander with graalvm.

borkdude10:11:54

@jlle I'm not sure why it would fail in GraalVM, I don't see any obstacles

borkdude10:11:20

I haven't tried and I'm not deeply familiar with the code.

borkdude10:11:03

It's not hard to try it out though. Here is a small CLI: https://github.com/borkdude/puget-cli which should easily be changed to run a meander example.

jose11:11:23

@borkdude maybe not, I didn't try myself neither. I supposed that if it fails with babashka, the compilation with graalvm will fail too, but I can easily be wrong

jose11:11:52

Thanks for the suggestion, I don't have the time right now, but definitely I'll try to compile meander

borkdude11:11:34

Babashka uses sci which is a Clojure interpreter which you can compile with GraalVM. Running code through sci is not the same as directly compiling it with GraalVM. Some things are support in one and not in the other and vice versa.

👍 3
jose11:11:22

I see, good to know, I assumed that if some code runs in babashka, it will compile with graalvm

borkdude11:11:02

One example: you cannot execute functions that use clojure.core/eval with graalvm, because eval needs compilation.

borkdude11:11:10

But you can do this with sci.

borkdude11:11:31

But some things like deftype, etc are not support in sci.

dominicm18:11:06

Obviously term rewriting is good for direct optimizations. But if I had a constraint on size, and had to prevent certain things from nesting, I'm guessing that's out of bounds for term rewriting?

noprompt19:11:13

@dominicm I don’t think that is necessarily true but maybe a little more context?

dominicm19:11:11

@noprompt I'm thinking of writing a clojure minifier, because reasons.

borkdude19:11:28

What's the use case and what are some of things you are thinking about?

borkdude19:11:36

There is an open issue for clj-kondo that would help LSP find locals for renaming. This could also be used for renaming locals to minify code

borkdude19:11:46

e.g. rename foobar to F

noprompt19:11:32

I need to find the time to look into these cool things. Long time fan of LSP though I’ve never made the time to put it to use in Emacs.

noprompt19:11:10

Good place to stick rewriting.

borkdude19:11:11

@noprompt Also check out https://github.com/borkdude/carve for deleting unused vars.

dominicm19:11:37

So can't nest #(#()) for example.

borkdude19:11:05

@dominicm I'm working on extracting the uberscript functionality from babashka so it also works for JVM. Together with carve (cut out unused vars) this is also a kind of minifier.

noprompt19:11:16

I’m thinking, for example, a pair of a peano number indicating the depth and the term

[0 ?term] = ?term
[(s ?nat) ?term] = (recur [?nat ?term*])

noprompt19:11:00

> because reasons @dominicm sounds like how I arrived 🙂

dominicm19:11:23

I'm thinking of building a code golfer, and this feels like a fair addition. Maybe it's not though. But it's no fun to be beaten by your colleague who strategically added #() after seeing your solution.

😆 3
noprompt19:11:07

Code golf is a young mans game. 😛

noprompt19:11:01

@borkdude I’m trying to grind out this interpreter code patch as fast as I can to try out.

noprompt19:11:48

TBH, I could probably remove a lot of the internal use of match which is one part suck and another part not.

borkdude19:11:08

sounds exciting :)

noprompt19:11:20

It would definitely improve the load time for every one.

noprompt19:11:27

I’ve tried to speed up the compilation of the macros but at some point I’m comfortable with prioritizing the speed of the runtime code over the compiler speed. At the point is where the interpreter should fit in.

noprompt19:11:37

I am quite interesting Graal FWIW.

👍 3
noprompt19:11:36

I’m interested to see how well the interpreter runs once the partial evaluation magic kicks in.

markaddleman19:11:05

Tangentially related to this discussion: I often use cata as a subroutine of sorts. When I do this, I've adopted an idiom along the lines of

(m/rewrite something
   ?n
   (m/cata {::number !n})

   [!n ...]
   [(m/cata {::number !n}) ...]

   {::number (m/pred number? ?n)}
   blah-blah)
I vaguely remember a conversation in this channel saying that this is a pretty common idiom and that meander might adopt first-class support for it. I'm just curious to follow up on that

noprompt19:11:58

Do you remember what was connected to that? I vaguely remember that but my memory these days, eh, is bad.

markaddleman19:11:45

heh I sympathize

markaddleman19:11:55

No, I don't recall much else about the conversation.

markaddleman19:11:18

It is not a big issue for me.

markaddleman19:11:49

I imagine that direct support could yield better runtime performance but my use case is not performance sensitive

noprompt19:11:00

cata compilation will get better in time. I’m just barely starting to get time in my life back for hacking on Meander.

noprompt19:11:16

The paste few months have been hard on me.

markaddleman19:11:04

I'm sorry. I hope you don't take my comments as critical. Meander has been a HUGE boon to my productivity and I appreciate all your efforts

noprompt19:11:58

> I hope you don’t take my comments as critical Not at all! 🙂

noprompt19:11:55

I love this project, this channel, and the little community of we’ve established here around this stuff. I like making people happy and get sad when I can’t. 🙂

markaddleman19:11:15

In general, the Clojure community is very friendly. Meander community is even more so 🙂

noprompt21:11:39

OK I’m like 80% done with an initial interpreter worthy of kicking around.

dominicm21:11:06

So just 80% left to go? :)

noprompt21:11:46

I just meant that I have a rough draft that is sturdy enough to use at your own risk. 🙂

noprompt21:11:09

I’m trying to minimize the at your own risk part as a courtesy, however. 😂

noprompt22:11:50

(ns scratch
  (:require [meander.interpreter.epsilon :as m]))

(def search-a
  (m/searcher
   '(m/re #"(.)(.)(.)" (m/and [?0 ?1 ?2 ?2] [!0 ...]))
   (fn [{:syms [?0 !0]}]
     [?0 !0])

   '(m/re #"f(.*)" [!0 ?0 . !0 ...])
   (fn [{:syms [?0 !0]}]
     [?0 !0])))
  
(search-a "foo")
;; => (["foo" ["foo" "f" "o" "o"]] ["oo" ["foo"]])
(search-a "foe")
;; => (["oe" ["foe"]])

noprompt22:11:05

Seems like this could work

noprompt22:11:16

What do y’all think?

noprompt23:11:46

JHOLDBRO-M-C65T.jholdbro=> rlwrap bb --classpath src
Babashka v0.2.3 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (require '[meander.interpreter.epsilon :as m])
nil
user=> (def s1 (m/searcher '(m/re #"f(.)(.)" [_ ?x ?x]) #(get % '?x)))
#'user/s1
user=> (s1 "foo")
("o")
user=> (s1 "faa")
("a")
user=> (s1 "f11")
("1")
@borkdude works

noprompt23:11:28

It appears to be very fast.

3
noprompt23:11:12

Well, sort of.

noprompt23:11:47

;; Clojure
(with-out-str (time (dotimes [_ 10000] (doall (search-a "foe")))))
"\"Elapsed time: 253.965799 msecs\"\n"
;; Babashka
(with-out-str (time (dotimes [_ 10000] (doall (search-a "foe")))))
"\"Elapsed time: 3284.494238 msecs\"\n

noprompt23:11:02

Not sure what’s going on here.

noprompt23:11:13

;; Clojure
(with-out-str (time (doall (search-a "foe"))))
"\"Elapsed time: 0.012454 msecs\"\n"
;; Babashka
(with-out-str (time (doall (search-a "foe"))))
"\"Elapsed time: 0.814953 msecs\"\n"

noprompt23:11:08

In terms of performance, for this example, interpretation is going to be slower over all, however, it’s also going to be more flexible.

(defn search-b [s]
  (me/search s
    (me/re #"(.)(.)(.)" (me/and [?0 ?1 ?2 ?2] [!0 ...]))
    [?0 !0]

    (me/re #"f(.*)" [!0 ?0 . !0 ...])
    [?0 !0]))

[(with-out-str (time (dotimes [_ 10000] (doall (search-a "foe")))))
 (with-out-str (time (dotimes [_ 10000] (doall (search-b "foe")))))]
;;=>
["\"Elapsed time: 120.945113 msecs\"\n"
 "\"Elapsed time: 15.265521 msecs\"\n"]

noprompt23:11:09

It’s likely possible to close that gap on this a bit using, say, an approach similar to Egison.

noprompt23:11:42

Or using ye olde matrix style pattern matching compilation but, of course, to functions instead of code.

noprompt23:11:11

Variables would need to have their names changed to protect the innocent.