This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-16
Channels
- # announcements (22)
- # beginners (4)
- # biff (4)
- # cider (5)
- # clerk (3)
- # clojure (28)
- # clojure-chennai (1)
- # clojure-europe (23)
- # clojure-gamedev (7)
- # clojure-korea (5)
- # clojure-madison (3)
- # clojure-my (1)
- # clojure-nl (1)
- # clojure-norway (49)
- # clojure-sweden (7)
- # clojure-uk (4)
- # clojuredesign-podcast (14)
- # clojurescript (10)
- # clr (5)
- # cursive (4)
- # datascript (17)
- # datomic (2)
- # events (1)
- # garden (1)
- # introduce-yourself (2)
- # jobs-discuss (14)
- # lsp (23)
- # malli (14)
- # missionary (9)
- # off-topic (109)
- # overtone (7)
- # polylith (5)
- # releases (5)
- # shadow-cljs (7)
- # sql (13)
- # testing (30)
- # xtdb (10)
- # yamlscript (44)
I'm puzzled about clj -X
(and -M
). The documentation suggests that you can pass a map of function arguments. What if my function expects a single argument, e.g. a number? Can I not call it via -X without adapting the signature to accept a map?
The https://clojure.org/guides/deps_and_cli would maybe benefit from adding an example that actually uses opts/arguments, e.g. print "Hello <name>" instead of "Hello World" if name is given a) as a single argument (if even possible?) b) as a map entry

-X mandates a particular calling convention, it builds a map out of the list of arguments (calling read-string on each) and then passes it to the function
Can I not call it via -X without adapting the signature to accept a map?Unless there's some voodoo I'm unaware of, you cannot. There are several other good alternatives:
• create a new function for adapting command line args
• use -M
• The syntax for specifying the map at the command line tries to help so using :num 42
might not be so bad.
• There's also tricks you can do with aliases (see https://github.com/phronmophobic/clirun as an example)
• There are also some libraries that can help. see https://github.com/babashka/cli