This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-21
Channels
- # 100-days-of-code (1)
- # announcements (2)
- # beginners (164)
- # cider (23)
- # cljs-dev (30)
- # cljsjs (11)
- # cljsrn (7)
- # clojure (116)
- # clojure-boston (1)
- # clojure-dev (20)
- # clojure-finland (2)
- # clojure-italy (4)
- # clojure-nl (1)
- # clojure-uk (10)
- # clojurescript (39)
- # core-async (19)
- # cursive (43)
- # data-science (2)
- # datomic (24)
- # emacs (10)
- # figwheel-main (20)
- # fulcro (63)
- # hoplon (7)
- # hyperfiddle (7)
- # instaparse (3)
- # kaocha (1)
- # nrepl (3)
- # off-topic (170)
- # onyx (13)
- # other-languages (3)
- # parinfer (13)
- # re-frame (39)
- # reagent (5)
- # reitit (22)
- # ring-swagger (4)
- # shadow-cljs (284)
- # spacemacs (2)
- # sql (27)
- # testing (28)
- # unrepl (2)
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.
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.
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
I will be surprised if polymethods cannot be implemented as multimethods (and thus show multimethods are more general)
@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?
I haven't really been following, so if there were some examples of usages of your poly stuff I haven't seen them
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.
I think the implementation for defmulti's could be slightly tweaked and you'd have the same thing
(and it deliberately picks "first match")
which is like, an atom containing predicates and a fixed dispatch function that invokes each predicate in the atom in turn
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 🙂
(and you'd pass the predicate as the first argument in all calls)
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
Yeah, I'm super interested in what claims could be made about it. It seems more general from certain perspectives
@seancorfield wait, will that work?
No, because you can't have multiple defmethod
with the same dispatch value.
It's basically the full firepower in the hands of the user, which I think Rich was intentionally avoiding with multi methods
It's almost the reverse of defmulti
/`defmethod` since you have a predicate for each method definition (rather than a value).
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
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
@hiredman It's funny, your comments here had me wondering about using gensym for the dispatch value!
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?
I was just about to ask that 🙂
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
(you'd have to be careful with anonymous functions)
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.
there are shell scripts that invoke lein to build it, but no project.clj, so that adds to the mystery.
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.
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
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
@mseddon org-mode is fantastic, but I don’t think there are implementations besides the one in emacs
that support no-web-style tangling
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
@alexmiller but getting the other thread from a second connection and interrupting it should work, no?
generally, this is a hard thing to do in Java
if you can get a handle to the Thread, and if the thread is doing something interruptible, then yes
was going to try something along https://puredanger.github.io/tech.puredanger.com/2010/05/30/clojure-thread-tricks/ 😼
hey that’s me :)
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)
right, so plain computation isn’t interruptible but .stop
would be a hack that would work until it’s removed?
every Java reference you read will tell you not to call .stop
it has the downside of not properly releasing locks b/c the stack goes away without being unwound
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
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…
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!
so (range) by itself is actually a totally fine lazy sequence
it’s printing it that’s bad
so it’s good to set *print-length*
etc to control that
@alexmiller congrats on https://dev.clojure.org/jira/browse/CLJ-2438 - it’s going to make exceptions much less scary
enjoy… :)
Do NOT call Thread.stop
If you have a long running computation
you can modify it to check if current thread is interrupted
for x in 10000000, if (Thread/interrupted) break
Simply divide workload into chunks and check thread interrupted flag before taking next chunk
@roklenarcic but this is for a notebook where I don’t control the user code that’s entered
Well there's no real cure for infinitely blocking tasks
other than killing things
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
this will of course leave that off-thread computation around executing till it finishes
consuming resources
you can join with timeout
but from user's perspective it looks like he aborted the computation
@zk is the maintainer I believe...
(... of ClojureDocs)
in the meanwhile, Googles cache works great ^^
its just a bit annoying to navigate
is there an easy way to modify transit-clj to return java.time.Instant instead of java.util.Date?
@schmee thanks but I'm more trying to get java.time.Instant out of transit requests automatically without manually converting
transit doesn't seem to have an extendable protocol, it seems to instead use WriteHandlers
take a look at https://blog.klipse.tech/clojure/2016/09/22/transit-clojure-2.html for some ideas on how to do this
Does anyone know how to properly escape this backslash? (str "foo " "\Car " " bar")
I want the output to be "foo \Car bar"
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?
works for me @michaellindon
I get EOF while reading string
wait sorry
@dpsutton your suggestion gives me "foo \\Car bar"
"foo \Car bar"
@michaellindon when displayed at a repl, it will seem to have 2 \, but if you use println, you will see it is correct.
oh that resolves the confusion, thanks 🙂