This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-06
Channels
- # announcements (4)
- # aws (2)
- # beginners (48)
- # calva (39)
- # cljsrn (12)
- # clojure (98)
- # clojure-dusseldorf (1)
- # clojure-serbia (2)
- # clojure-spec (13)
- # clojure-uk (13)
- # clojurescript (97)
- # code-reviews (1)
- # datomic (14)
- # fulcro (24)
- # jobs-discuss (160)
- # juxt (1)
- # luminus (2)
- # nrepl (1)
- # off-topic (1)
- # other-languages (1)
- # overtone (1)
- # perun (6)
- # protorepl (16)
- # re-frame (20)
- # reagent (1)
- # reitit (6)
- # rum (8)
- # shadow-cljs (96)
- # spacemacs (8)
- # specter (4)
- # tools-deps (18)
- # uncomplicate (1)
- # vim (1)
I have working code where I get hash code of data structures with (hash data-structure) but it works in small amount of them. When I have few millions of data structures it will start giving me duplicate hashes (clash). How to get something more unique when structure of data structure is unknown?
@masta hash returns a 32 bit int, so the birthday problem means you'll start to get conflicts regardless
You might want to look in to something like sha or md5
Or design your data structures to work even with hash conflicts, which is what clj itself does
how do I get pprint to print this with the leading quote?
(def x '[foo bar])
(pprint x)
=> [foo bar]
Like this?
(clojure.pprint/pprint ''[foo bar])
'[foo bar]
Maybe not. Is it for edn data or for something else?
Or indeed
user=> (defmacro quoted [x] `(quote (quote ~x)))
#'user/quoted
user=> (def x (quoted [foo bar]))
#'user/x
user=> (clojure.pprint/pprint (quoted [foo bar]))
'[foo bar]
cool, i'm curious
@borkdude Not sure if it is an idiom, but I often see the sequence
`'~
used in macros. It looks a bit like line noise, but perhaps it is an idiom.
So for that example
(pprint `'~x)
Hey everyone, I have a problem with leiningen, reloaded.repl, Cursive and/or CLJC. I have defined some protocols in .cljc files which are used from clj/s. In an open REPL from Cursive, most of the time when using reloaded.repl/reset(-all)
, it doesn't pick up my changes at all. If I do a "manual" clojure.tools.namespace/refresh(-all)
, my changes are picked up but all the protocol implementations won't satisfy their respective (newly modified) protocols anymore, so I get exceptions from somewhere near clojure.core/-cache-protocol-fn
. I need to fully restart the REPL for everything to be picked up again. Is there a way to remedy this, or workarounds? Has anybody encountered this? (my google searches haven't turned up much)
(My workflow is roughly equivalent of what using chestnut involves)
this sounds relevant: https://lambdaisland.com/blog/2018-02-09-reloading-woes > when you use tools.namespace to reload your code, it effectively creates completely new and separate versions of functions, records, multimethods, vars, even namespace objects, and any state that is left around from before the reload might still be referencing the old ones
I personally don’t use tools.namespace, but I know that re-evaluating things like multimethods is tricky
have you had any success simply re-evaluating the namespace you’re trying to refresh?
Well, sort of. It sends me on a wild goose chase through my namespaces, totally arbitrary and non-deterministic
Sooner or later it sometimes works, but not so often that restarting the whole thing isn't much easier and faster
Multimethods work fine, by the way
I have lots of defrecords
implementing various protocols, and those very often "loose" their implementations in this way
well, specifically, I always run into an issue where you can’t re-evaluate the (defmulti <dispatch>)
part. re-evaluating the cases works fine 🙂
which is a bummer since I quite like the architecture so far, but without proper refreshes in the REPL it's very frustrating
ah you're right, I know that one too ^^
Maybe it's reloaded.repl's alter-var-root! that does something funky?
so, question: if you create a new instance of the new defrecord
impl, do you see the correct behavior?
iirc yes, if I switch to the respective namespace and manually instantiate the record, it satisfies the protocol
but let me check real quick
(most of the records are instantiated via an integrant like multimethod mechanism)
so it sounds like what’s happening is that your defrecord
is being picked up correctly, but your application is still referring to instances of the old implementations
I haven’t use integrant, I typically use mount because I’m lazy. but I assume there is a way to stop/start your system with new instances of your records, which would solve the problem you’re encountering I think?
i'm not using integrant, but the core of the IoC mechanism is a multimethod that's basically integrant's init-key
i'll look into the REPL utilities to see if there's something that keeps around stuff
I'd be surprised though since afaik there's one aliases and stuff. reloaded.repl uses alter-var-root! and component/suspendable, so in a reset, it'll call Lifecycle/stop. All the records in question are re-instantiated on start and discarded on stop. But there could be a bug there as well I suppose.
there's only aliases*
yes, but only "behind the scenes"
and really only for repl convience. all components wrap a subsystem which consists of the actual parts of the application
the wrapper components discard the subsystem on stop and create a fresh one through the IoC mechanism on start
which is why this protocol issue puzzles me
reloaded.repl's reset does stop, refresh, start, so in theory the subsystems should be created after the tools.namespace refresh
and with the new implementations
but maybe that's the crux, a combination of cljc processing and protocol/multimethod reloading
or protocol reloading and multimethod instantiation, rather
the reason I suspect something very messy is that very rarely everything breaks completely, even after a REPL restart, and I have to lein clean
before any of it will work again 😅
FWIW I don’t use reloaded.repl at all. I use mount and re-evaluate the var or namespace I’m in as I develop. Occasionally, if necessary, I call (mount/stop) (mount/start)
but I also have never used records and rarely use protocols 😛 so take my advice with a grain of salt!
we considered mount but decided on component+reloaded, since they seemed to be made for record/protocol stuff
and it works quite beautifully, too, except the actual reloading 😄
Well, I'll try reproducing this in a minimal test project i think. Maybe it really is something with the code. Otherwise maybe I can try using an atom for REPL development and completely scrap everything on restart, to rule out reloaded
Who can share experience about https://github.com/onyx-platform/onyx ? Do you feel it is right solution for PDF processing when fast response for query by API is needed?
I remember seeing a comparison table of Clojure web libraries/frameworks. I can't seem to find it now. Anyone have the link?
It showed which ones use macros and which ones are data driven
I think you might mean this https://github.com/juxt/bidi/blob/master/README.md
Yes, that was it, thanks. Forgot it was just comparing routing specifically though.
I'm contemplating bidi + yada, but not quite sure the practical differences between the libraries
That could be. They are both from JUXT and is stated as sister libraries
It is an alternative to ring though
"A yada handler is an instance of the yada.handler/Handler record. Since this record satisfies clojure.lang.IFn, yada handlers behave just like normal Ring handlers and can be used wherever you might use a Ring handler. "
there's this one too https://github.com/metosin/reitit
Yeah, looking at that too
yeah. I think you would use something like: ring (http abstraction) + jetty (web server) + bidi (routing) + yada (resources)
No, yada provides the http server and is an alternative to ring
It uses Aleph
@whoneedszzz if you have any questions about bidi/yada, there is a subset of us specifically in #juxt
Fwiw, it isn't outside the realm of possibilities for yada to work with other web servers, but yada is currently coupled to the async extensions that Aleph adds. We haven't had a need to extend yada to other web servers, so it hasn't happened, and in the mean time, we have added conveniences for starting yada.
Thanks for the recommendations
Can you elaborate?
I guess certain extremely complex webservers can benefit from it. But it seems like lots of templates include the structure just in case you need it. Which usually isn't a huge deal, since it doesn't usually get too much in the way even when you don't need it. But then it's just one extra piece of unnecessary complexity.
And in my experience, it's quite easy for projects to evolve and reloading to become broken with life cycles, unless teams maintain good discipline
It is. And I guess I'm glad the abstraction has some standard. I just think it's over used
Ran across this from H L Ship of Walmart Labs https://medium.com/@hlship/tips-and-tricks-for-component-d00832abcdfa
I guess I'm not exactly sure what your statement was responding to.
I was just airing a general complaint, sorry. Your use case may be entirely appropriate.
I'm just not familiar with mount or component and didn't see it mentioned above it so I was just confused by that. If I knew them I might agree with your complaint.
From a cursory glance of them, it sounds to me like it's another example of OOP mentality trying to claw back in to our functional paradise. 🙂
I guess I was reading some backlog in another channel... And I accidentally responded in this channel... Lol
No worries. It ended up having a relation indirectly after all