This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-09
Channels
- # aleph (1)
- # announcements (4)
- # asami (6)
- # babashka (45)
- # beginners (19)
- # biff (3)
- # calva (35)
- # cider (4)
- # clojars (5)
- # clojure (117)
- # clojure-art (3)
- # clojure-denmark (2)
- # clojure-europe (89)
- # clojure-gamedev (5)
- # clojure-nl (4)
- # clojure-norway (17)
- # clojure-spec (3)
- # clojure-uk (5)
- # clojurescript (84)
- # conjure (13)
- # datomic (11)
- # emacs (2)
- # figwheel (2)
- # fulcro (16)
- # graphql (5)
- # honeysql (7)
- # introduce-yourself (1)
- # lsp (86)
- # malli (16)
- # music (1)
- # off-topic (2)
- # pathom (14)
- # polylith (28)
- # re-frame (11)
- # reagent (23)
- # releases (1)
- # reveal (19)
- # shadow-cljs (72)
- # spacemacs (13)
- # sql (1)
- # test-check (3)
- # timbre (4)
- # tools-deps (45)
- # vim (18)
I want to try a s-expr for every stuff that I required, when this s-expr won't throw an exception I would like to see for which module it happened
is that possible?
like, right now I'm copying the verbose output from a require and I'm thinking on doing a (doseq [s-expr forms-list] (try (my-stuff) (catch e (prn "not passed"))) (eval s-expr))
for each one
is there a function for it?
instead of using the s-expr from verbose print
you're telling me to make
(fn [] (s-expr))
?
I'm picking every in-ns
, alias
and loading
that comes from the :verbose
inside a require
in a namespace
If you are reading forms from a file then evaling them that is an appropriate use of eval, if you just have a list of expressions you are evaling, the correct thing is to write functions and call those functions instead of using eval
and I want to eval 1 expression before each require
Right now I'm copying the output from the :verbose
making a list and trying to do this
I'm doing that because there is a java mutable object that is being evaluated inside some ns require
that I need to know which one of those are mutating this java object
which require
Dealing with some legacy strange code hehe
Would it be possible to write a new clj file that require
s those same files and run that as the entry point like clj debug-files.clj
then comment out each import until you pinpoint the one executing arbitrary java?
(ns proj.debug-files
(:require
[proj.module-a :as a]
[proj.module-b :as b]
[proj.module-c :as c]))
(my-stuff)
As an example, can be done with java imports as well, assuming grep is not an optionIf grep isn't an option I would do something like https://gist.github.com/hiredman/62f11dc663083f2127824d1c393c8f4c
Using with-redefs to redefine clojure.core/load, so you can check the state of the java object before and after each load, and use tools.namespace to find all the clojure code to load
I’ll try this with-redefs
this sounds an interesting idea
Wouldn't it be easier with a regular debugger and breakpoints in all the mutating methods?
I've tried:
(with-redefs [clojure.core/load (fn [& paths]
(try (get-all)
(catch Exception e
(println paths)
(println "Not loaded")))
(clojure.core/load paths))] (require ,,,, :verbose))
got some strange error
Stackoverflow because you can redefining clojure.core/load, and then calling the new definition in the new definition
The example gist captures the original value of load before redefining load, and invokes the original load or does the other thing as needed
(let [orig-require @#'clojure.core/require]
(with-redefs [clojure.core/require (fn [& args]
(try (do (get-all)
(throw (Exception. "WORKED!")))
(catch NullPointerException e
(println args)
(println "Not loaded")))
(apply orig-require args))] ,,,,)
better one:
(let [orig-require @#'clojure.core/require]
(with-redefs
[clojure.core/require
(fn [& args]
(try
(let [v (get-all)]
(println "Foi")
(throw (ex-info "FOI!"
{::args args
::v v
::ok 42})))
(catch Exception ex
(if (::ok (ex-data ex))
(println "FOI!" (ex-data ex))
(throw ex))))
(apply orig-require args))]))
the nice thing about intercepting calls to load vs. require is load is a much simpler function, the argument is just string instead of require's whole dsl, and load is downstream of require, and require checks to see if something was already loaded and then doesn't load it, so you won't get duplicate calls to load
if you get rid of the try/catch and put the println from the if in the try in place of the throw it will behave the same, unless get-all is also throwing exinfos with ::ok in them
How do I export fns I'm require
ing in my core.clj
for other modules to conveniently use? For example, let's say I have a utils.clj
that I want to also expose clojure.pprint/pprint
so I can do (require '[my-app.utils :refer [pprint]])
in my app
You can do it explicitly in utils.clj:
(def pprint clojure.pprint/pprint)
To be honest though, if you're using pprint I don't see the point in not requiring the namespace directly. In other languages like python you can transitively call functions from modules that are imported but that's not as easy in clojure. You can do it with macros but I'm not a fan.
If you do the def format so you lose the docstr? Agree that using pprint like that would be impractical but was trying to come up with a simple example.
take a look at this thread: https://clojurians.slack.com/archives/C053AK3F9/p1646820965857209?thread_ts=1646816986.120279&cid=C053AK3F9
you can do ^{:doc (:doc (meta #'clojure.pprint/pprint))}
to keep the docstring
May I know how do y'all work with monorepos when you want to have different versions for different components. And how would git tagging work with that? Or do yall just have various repos
External artifacts that you build can be released with versions, but inside the monorepo, the whole point is to avoid version dependencies and have the entire codebase stay in sync.
Understand that Google uses a monorepo. I guess I'm really just trying to figure out what can solve my boss' version problem in a monorepo. Like he doesn't want to bump the version of something somewhat external to the main project when we bump the version of the main stuff. Does that mean this should be an external artifact? :o
I only started to look into this recently. But given your question it sounds like you have “somewhat of a monorepo”, or that the external thing is not really external or that it has too many responsibilities? If not you could use it as an external artifact or just maintain it from the monorepo. But bumping the version of an external thing seems like there are issues to be resolved first, maybe the “somewhat external” thing should be two things? In terms of git and tags: the article I linked discusses how they version control. It’s a very simple system without long-lived branches that merge back to main. It assumes that you have a single versioned main branch with feature flags on top and cherry-picking into release branches if so necessary. You can simplify it further and just use release tags instead of branches (that’s what we do).
I think of the monorepo/trunk based version control as a kind of RDBMS with transactions that have the full view of a thing.
Perhaps I can distil it as the external part will end up functioning as a very small microservice. Something like a kafka message reader with an alert email system. Have a main project that is somewhat like a monorepo. And felt that instead of creating a separate project. I could just put it on the monorepo that we have. But in a sense they are 2 separate projects with different versions since. I wouldn't want changes in my alert stuff to bump the version of the main project vice versa
Maybe what I want is an external artifact. Not really sure how that works :thinking_face:
if you mean treating it as an external library then maybe like so: https://clojure.org/guides/deps_and_cli#_using_git_libraries or like so: https://clojure.org/guides/deps_and_cli#local_jar
I think having a bunch of deps versions in sync is great, but you don't want to rebuild your entire fleet of services for every bump
most of the times you dont have to. But knowing what version of a thing works with another has value
personally I was toying with the idea of having the dependency "manifest" for all versions of all deps for all services under version control and allow services to depend on it somehow (via stg like a git submodule). So you have a way to choose when to "re-sync", while having at least the guarantee stuff that worked together at a time would always be the same
it's an odd situation, in that case we cannot/don't want to go monorepo, we have plenty of multi-modules repo tho
but if I could choose I think I'd go the monorepo route. But it's a lot of work to port to it in this case
Any guides to get started on tools deps when i have pretty much always been using lein? (I also need guides on converting the :release-tasks
part but that's later on i guess)
Is there a way to obtain a persistent copy of a transient value without making the original transient persistent?
Would it be possible to get the value of a transient on the 1000th entry and reset! an atom then have a watcher on the atom to react to it?
@U8WFYMFRU But the question remains: when I finally call the (report ...)
I have to pass the value of the transient, but report
expects persistent
Could you deref
it to get the value?
Was thinking you could deref the transient
@U8WFYMFRU you might be thinking of volatile. transients don't implement IDeref
@U6SEJ4ZUH you could iterate over the values/entries of the persistent collection and create a new persistent collection from them. however, I think you are going to miss out on any perf gains you are gettin from transients by doing this
is there a reason you are using transients in the first place? perhaps you could use a persistent data structure from the start
@U4YGF4NGM I used transient because it's a tight loop that appends an element to a vector at every iteration. Though I haven't measured if there's any the performance gain doing that...
Oh right that may be what I was thinking of
I needed this because the transient is in a tight loop but I want to periodically (e.g., every 1,000 iterations) make a report based on what's currently in the transient, but I don't want to pass a transient to the report function which expects a persistent
If it is only every 1000th iteration or so, i.e. occasionally, you could simply create a persistent value from the transient, call the function that needs a persistent, then create a new transient from that and continue, yes?
If it is only occasionally, I would not expect that to cause much of a performance hit at all.
Btw. Did you measure the actual performance of the loop when not using transients vs using them? What's the difference?
Is there a core function for performing a filter like operation but short-circuiting when an coll item first passes the predicate?
Transducers are not my favorite but seems like it would do the job, thanks.
some
perhaps?
Some would totally do the job, thank you!
If you are willing to add a library, I always use medley.core/find-first
for that.
(it also seems to be significantly faster than some
)
Good to know, I'll have to learn how it's implemented
~
is defined only within syntax quote literal `
could you explain more the usecase you thinking about?
The use case is populating all of the data literal templates in use all over Clojure, e.g. for querying Asami I currently have to do this:
[:find '?id '?sort-value
:where
['?e :db/ident '?id]
['?e sort-key '?sort-value]]
rather than this:
'[:find ?id ?sort-value
:where
[?e :db/ident ?id]
[?e ~sort-key ?sort-value]]
i.e. I have to quote every single symbol as opposed to quoting the outer data structure + unquoting a single symbolclojure.template can sometimes help with these
Most people aren’t aware that's even in core
I was about to suggest the same 🙂 thanks Alex
hello, i am trying to deploy on clojars and i am getting Read timed out
my jar is (7968k)
i used lein deploy clojars
and given username/token , i uploaded the jars of 3 projects only one timeouts
i dont know why the jar is so big, for some reason it has the dependencies also, for example from the 8mb the 6mb is clojure
the other 2 jars are so small like kb, and they dont have the dependencies, but i didnt do anything different, in all i just did lein deploy clojars
i reinstalled lein, and its the same, its a mixed java/clj project , for some reason it looks like it only produces standalone jar
this would be project config not the config for lein itself. can you share your project.clj? do you have aot turned on by chance?
Hi guys, any ideas why lein classpath
returns something like
$ lein classpath
/home/anonimito/work/audience-republic/server-4/.cpcache/21FA38690A160741FD2BB36A1C13039C.jar
as opposed to a list of paths?
FWIW, to verify that it's not a clojure deps.edn (i.e. non-lein) project
$ clojure -Spath
src:/home/anonimito/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar:/home/anonimito/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar:/home/anonimito/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar
versions
$ lein --version
Leiningen 2.9.8 on Java 11.0.15 OpenJDK 64-Bit Server VM