This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-07
Channels
- # announcements (16)
- # asami (15)
- # babashka (12)
- # beginners (38)
- # calva (32)
- # cider (1)
- # clj-commons (9)
- # clj-otel (4)
- # clojure (57)
- # clojure-europe (43)
- # clojure-korea (1)
- # clojure-nl (1)
- # clojure-norway (13)
- # clojure-uk (4)
- # clojuredesign-podcast (9)
- # clojurescript (10)
- # cursive (5)
- # datahike (9)
- # deps-new (2)
- # events (1)
- # fulcro (8)
- # hyperfiddle (7)
- # kaocha (1)
- # lsp (2)
- # malli (3)
- # nrepl (2)
- # off-topic (19)
- # releases (3)
- # ring (10)
- # shadow-cljs (4)
- # sql (14)
- # xtdb (57)
- # yamlscript (2)
just to double check: clojure code on the classpath isn't loaded until load
is called, right? usually done with use
or require
or ns
. is it possible to inspect the code in a file on the classpath before it's loaded?
every "file" on the classpath should be accessible as resource. You can just slurp it before calling load
. But clojure code is a vague term, it might be a compiled class or real source file.
if load
can find them on the classpath, then so can you with whatever mechanism you like.
user=> (doc find-ns)
-------------------------
clojure.core/find-ns
([sym])
Returns the namespace named by the symbol or nil if it doesn't exist.
nil
user=> (find-ns 'clojure.core.reducers)
nil
user=> (subs (slurp ( "clojure/core/reducers.clj")) 0 20)
"; Copyright (c) Ri"
here i demonstrate that i haven’t loaded the reducers namespace but it’s on the classpath so i can find it by many mechanisms
cool, thank you
With emacs/cider, you can cider-open-classpath-entry
which might be similar to what you are after?
I am trying to execute a function from my terminal running the command :
clj -X main/hello
I am getting the error :
Wrong number of args (1) passed to: main/hello
even tho my function does not take any parameter...
Any idea why ?
that’s your issue. the -X
will pass a single map to your function. if main/hello
accepts no arguments, you will get a “wrong number of args (1) passed to main/hello”
I had another function with 2 parameters, when I tried to call it I also got the same error. Any idea how to properly call it ? Here's how I did it : clj -X main/get-contracts 100 200
(i’m trying to find documentation about this but surprisingly not finding it in the guide or reference on http://clojure.org)
theres an example here https://clojure.org/guides/deps_and_cli clojure -X:repl-server :port 51234
in the first case it says (1) because 0 args are being passed to a function that expects 1, in the second case it will say something like (2) because 1 arg is being passed to a function that expects 2
@U0NCTKEV8 yea exactly
the first says 1 argument passed (expected 0) The other says 1 argument passed (Expected 2)
I added a parameter to hello and it works with clj -X main/hello
oh, well I am just confusing myself then, anyway -X always passes a single argument, which is a possibly empty map
If my function takes 2 arguments how can I do ? I cant find anything in the doc 😕
ahhh so I have to change my function so it takes a map i guess
I know -M is for the main, is there any other flag that could help me in my case ?
ah, but I guess -m
only supports a namespace with a -main function, which I always forget, so you would have to use -e or something, which will make the args stuff not as nice
yea thats what I meant with -M is for the main lol
thanks guys
there is no CLI option to invoke an arbitrary function. you can:
• clj -M -m namespace-with-main
to invoke a namespace that has a -main [& args]
function
• clj -X ns/f
to invoke a function that takes a map of args
• clj -M file.clj
to run all top-level expressions in file.clj
Hello everyone,
Context:
• I am using @vlaaad's cljfx library for a few of my projects, and I have a basic question about finding callers and callees in Clojure code using events. I don't think my question is cljfx specific, though it has examples from it.
Main question:
• Is there a simple way to identify where this input parameters current-dir
are defined/set/modified?
◦ I usually use "Go to definition" in IntelliJ or Emacs, however decouling the code with event messages seems to completely break this flow.
Example:
I am swapping the state atom with the current directory that the user has selected from a GUI here:
(defmethod event-handler ::display-files [{:keys [current-dir]}]
(swap! *state assoc :files (util/list-clojure-files current-dir)))
Here is where I define the component
(defn file-list-view [{:keys [files selection current-dir]}]
{:fx/type fx.ext.list-view/with-selection-props
:props {:selection-mode :multiple
:selected-items selection
:on-selected-items-changed {:event/type ::events/update-selected-files-svg}}
:desc {:fx/type :list-view
:cell-factory {:fx/cell-type :list-cell
:describe (fn [item]
{:text (util/str->relative-path item current-dir)})}
:items files}})
When I do a "Go to definition" it is able to do a basic search for the keyword here, however, it is not able to tell me in any simple way that the atom is set in the ::display-files
handler.
Screenshot attached to show IntelliJ's go to definition search.
Here is the repo if anyone cares to take a look: https://github.com/aeonik/graph/blob/main/src/aeonik/gui/main.clj