Fork me on GitHub
#clojure
<
2018-11-21
>
john00:11:48

So I'm going to put a little lib together for this dispatch work if other's would like to try it out as a dep. But I'm not going to call it "predicate dispatch" anymore. To disambiguate it with other predicate dispatch systems, I'm going to call it an "open dispatch" system. It lets the user bring their own functions or predicate dispatch systems, however they want.

john00:11:38

You can think of polymethods as more general forms of multimethods. Instead of providing a value to match against, you provide a function or any dispatch system you'd prefer to plug in.

richiardiandrea00:11:14

hello folks! can I tell pprint/pprint not to start which a \n? I would like it to append to the current buffer location and continue from there

hiredman00:11:02

I will be surprised if polymethods cannot be implemented as multimethods (and thus show multimethods are more general)

john00:11:07

@hiredman I wondered about that. It'd be an interesting exercise... Can you figure out a way to get multi-methods to be fully polymorphic?

hiredman00:11:25

in what way aren't they?

john00:11:10

there's a forced equality check in there...

hiredman00:11:30

I haven't really been following, so if there were some examples of usages of your poly stuff I haven't seen them

hiredman00:11:49

but predicates also have what is basically an equality check at the bottom

hiredman00:11:02

(= (f x) true)

seancorfield00:11:06

The main difference is that multimethods have a fixed dispatch function at the definition. @john’s stuff accepts a predicate function at each new definition.

john00:11:20

I think the implementation for defmulti's could be slightly tweaked and you'd have the same thing

seancorfield00:11:54

(and it deliberately picks "first match")

john00:11:15

yeah, that too

hiredman00:11:33

which is like, an atom containing predicates and a fixed dispatch function that invokes each predicate in the atom in turn

☝️ 4
john00:11:33

full speed ahead!

seancorfield00:11:22

It would be sort of like defmulti with a dispatch function that basically applied the first arg as a function to all the other args and cast the result to boolean and then all the defmethod would have true as their dispatch value 🙂

seancorfield00:11:38

(and you'd pass the predicate as the first argument in all calls)

hiredman00:11:51

which maybe is interesting, and maybe would be a nice short cut, but I wouldn't go around claiming it is more general then multimethods

john00:11:36

Yeah, I'm super interested in what claims could be made about it. It seems more general from certain perspectives

john00:11:59

That's why I'm not calling it a "predicate dispatch" system

john00:11:22

@seancorfield wait, will that work?

john00:11:47

It might be possible to hack multi methods to do it

seancorfield00:11:51

No, because you can't have multiple defmethod with the same dispatch value.

john00:11:58

ah, right

john00:11:49

It's basically the full firepower in the hands of the user, which I think Rich was intentionally avoiding with multi methods

john00:11:09

you can make a super slow dispatch system with this, if you want to

seancorfield00:11:35

It's almost the reverse of defmulti/`defmethod` since you have a predicate for each method definition (rather than a value).

john00:11:43

so I'm calling the lib "dispacio" 😉

john00:11:55

You can dispatch off of database lookups, or carrier pigeons

john00:11:17

and have the caller waiting for the function to call

john00:11:30

or you can pass in a super fast equality check

hiredman00:11:01

I mean, again, I haven't been following the discussion around this if there was any beyond the mentions in the last page or two of chat, which sounds like it is describing https://gist.github.com/hiredman/fbade00f1641dbcb62a0feee2964495e

hiredman00:11:55

which is like a thing, and some people might be interested in that, but I would proceed with caution when making claims about full firepower and more general, etc

john01:11:43

generality is in the eye of the beholder, I guess 😉 But that looks super interesting

seancorfield01:11:21

@hiredman It's funny, your comments here had me wondering about using gensym for the dispatch value!

john01:11:18

I had something pretty much the same before... just around 30 or 40 lines of code that did it. But does your version lean on defmulti's resolution system too? Can you prefer-method on them?

seancorfield01:11:41

I was just about to ask that 🙂

hiredman01:11:07

not directly, but you could take a predicate, look it up in preds to find the gensym for it, and then pass that to prefer-method

seancorfield01:11:44

(you'd have to be careful with anonymous functions)

mseddon08:11:06

Does anyone know how https://github.com/thi-ng/geom is written? It appears to be some literate programming model, but I've not come across it before.

mseddon08:11:49

there are shell scripts that invoke lein to build it, but no project.clj, so that adds to the mystery.

andy.fingerhut08:11:11

The tangle.sh script mentions Emacs org mode and a package called ob-tangle. I haven't used that before, but it looks like one of the many literate programming tools.

mseddon08:11:44

yeah, I found some references to babel, in there. I may look for a slightly less opaque building tool if I want to do LP. Thanks for taking a look

mkvlr09:11:15

can somebody point me to an example of starting a socket prepl in 1.10?

mkvlr09:11:43

oh, looks like it was an escaping issue and clojure -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.10.0-beta7"}}}' -J-Dclojure.server.repl="{:port 0 :accept clojure.core.server/io-prepl}" works

👍 4
hkjels10:11:03

@mseddon org-mode is fantastic, but I don’t think there are implementations besides the one in emacs that support no-web-style tangling

hkjels10:11:32

if your using emacs, I would highly recommend diving a bit deeper 🙂

mseddon10:11:12

@hkjels Thanks! I will check it out 🙂

logistark12:11:25

Hi, i am trying to use https://github.com/AvisoNovate/logging in my services. But i can't make it work. There is no output in the logs about the correlation-id

ijmo12:11:41

is http://clojuredocs.org dead for now?

🆘 4
schmee13:11:22

seems like it, I was just in it a couple of hours ago so probably a temporary thing

mkvlr14:11:55

is there a way to interrupt a long-running prepl eval?

mkvlr14:11:39

I guess using a second connection…

mkvlr14:11:08

@alexmiller but getting the other thread from a second connection and interrupting it should work, no?

Alex Miller (Clojure team)14:11:43

generally, this is a hard thing to do in Java

Alex Miller (Clojure team)14:11:08

if you can get a handle to the Thread, and if the thread is doing something interruptible, then yes

Alex Miller (Clojure team)14:11:15

there might be some way to do the first thing but if the thread is doing computation, rather than a blocking I/O op, you won’t be able to do the second part (unless you literally .stop the thread (which is deprecated and even going to be removed in the JDK)

mkvlr14:11:35

right, so plain computation isn’t interruptible but .stop would be a hack that would work until it’s removed?

Alex Miller (Clojure team)15:11:20

every Java reference you read will tell you not to call .stop

Alex Miller (Clojure team)15:11:00

it has the downside of not properly releasing locks b/c the stack goes away without being unwound

Alex Miller (Clojure team)15:11:46

this stands a reasonable chance of leaving locked and unlockable locks, thus setting your app up to die the next time something tries to obtain one of those

mkvlr15:11:48

I now see unrepl does it as well… Since it’s generic clojure user code (in a notebook) chances are low it will be interruptible…

mkvlr15:11:31

alright, I guess the primary use case would be to abort if a user puts in e.g. (range). And there’s still the option to restart the process cleanly if the user wants to but for this case I think .stop is better than losing all repl state. Thanks a lot for your help!

Alex Miller (Clojure team)15:11:53

so (range) by itself is actually a totally fine lazy sequence

Alex Miller (Clojure team)15:11:57

it’s printing it that’s bad

Alex Miller (Clojure team)15:11:08

so it’s good to set *print-length* etc to control that

stathissideris15:11:50

@alexmiller congrats on https://dev.clojure.org/jira/browse/CLJ-2438 - it’s going to make exceptions much less scary

roklenarcic15:11:34

Do NOT call Thread.stop

roklenarcic15:11:58

If you have a long running computation

roklenarcic15:11:12

you can modify it to check if current thread is interrupted

roklenarcic15:11:24

for x in 10000000, if (Thread/interrupted) break

roklenarcic15:11:08

Simply divide workload into chunks and check thread interrupted flag before taking next chunk

dpsutton15:11:15

seems like a tall order? make all code cooperatively scheduling

✔️ 4
mkvlr15:11:27

@roklenarcic but this is for a notebook where I don’t control the user code that’s entered

roklenarcic15:11:57

Well there's no real cure for infinitely blocking tasks

roklenarcic15:11:02

other than killing things

dpsutton15:11:07

like .stop?

roklenarcic15:11:01

If you can spare the resources you can spawn the calculation in a separate thread, then have the current thread join on that and then you can interrupt the join

roklenarcic15:11:20

this will of course leave that off-thread computation around executing till it finishes

roklenarcic15:11:29

consuming resources

roklenarcic15:11:00

you can join with timeout

roklenarcic15:11:42

but from user's perspective it looks like he aborted the computation

pablore16:11:17

clojuredocs appears to be down

seancorfield17:11:39

@zk is the maintainer I believe...

seancorfield17:11:45

(... of ClojureDocs)

Lennart Buit17:11:14

in the meanwhile, Googles cache works great ^^

Lennart Buit17:11:22

its just a bit annoying to navigate

taylor18:11:23

it's working for me now, just found ns-unalias 🙂

kanwei20:11:33

is there an easy way to modify transit-clj to return java.time.Instant instead of java.util.Date?

kanwei20:11:45

especially since 1.10 is now on jdk8

schmee20:11:22

you can register your own data reader for #inst that uses turns it into an instant

kanwei20:11:01

@schmee thanks but I'm more trying to get java.time.Instant out of transit requests automatically without manually converting

kanwei20:11:45

transit doesn't seem to have an extendable protocol, it seems to instead use WriteHandlers

kanwei21:11:12

thanks, that's a start!

michaellindon21:11:12

Does anyone know how to properly escape this backslash? (str "foo " "\Car " " bar") I want the output to be "foo \Car bar"

gleisonsilva21:11:08

hello, guys! how can I run my tests from repl? I'm using expectations and cognitect.test-runner, all defined in deps.edn. From command line is everything ok, but I haven't yet figured out how to invoke the test-runner from repl... can u help-me?

dpsutton21:11:12

(str "foo " "\\Car " " bar")

michaellindon21:11:14

I get EOF while reading string

michaellindon21:11:03

@dpsutton your suggestion gives me "foo \\Car bar"

dpsutton21:11:15

what are you hoping to get?

michaellindon21:11:24

"foo \Car bar"

dominicm21:11:51

@michaellindon when displayed at a repl, it will seem to have 2 \, but if you use println, you will see it is correct.

michaellindon21:11:58

oh that resolves the confusion, thanks 🙂