This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-01
Channels
- # 100-days-of-code (5)
- # adventofcode (234)
- # aleph (13)
- # announcements (2)
- # architecture (3)
- # bangalore-clj (1)
- # beginners (312)
- # calva (7)
- # cider (6)
- # cljdoc (3)
- # cljs-dev (30)
- # cljsrn (2)
- # clojure (40)
- # clojure-austin (2)
- # clojure-dev (65)
- # clojure-greece (1)
- # clojure-italy (29)
- # clojure-kc (1)
- # clojure-russia (2)
- # clojure-uk (26)
- # clojurebridge (1)
- # clojurescript (4)
- # cursive (11)
- # data-science (1)
- # datomic (43)
- # docker (1)
- # duct (7)
- # emacs (3)
- # figwheel-main (7)
- # fulcro (8)
- # garden (3)
- # graphql (8)
- # hyperfiddle (4)
- # off-topic (10)
- # other-languages (12)
- # pathom (4)
- # portkey (1)
- # remote-jobs (3)
- # rum (8)
- # shadow-cljs (40)
- # tools-deps (68)
- # unrepl (2)
- # vim (5)
Looks like clj
main-opts don't compose. For example, I tried to define two aliases that both set main-opts
: https://github.com/pesterhazy/advent2018/blob/e0f8fba23339052eb112958fed712da97c7c270b/deps.edn#L3
Unfortunately with clj -A:nrepl:in-ns
, the -e (...)
argument for the second alias overrides the -e (...)
of the first
Is this intended behavior? Is there another way for an alias to execute code?
Note that clj -A:nrep -e (...)
does work
Those are two enhancements to clj
that would make aliases more useful then: avoiding the need for Corfield Commas, and being able to stack side effects (like starting an nREPL server) on top of each other
You can stack effects with -m - main args are appended to the end. But, there are other things going on in your example above (no support for -e aliases, ordering of -A vs other aliases, etc)
https://clojure.org/reference/deps_and_cli > If multiple -M alias maps are activated, only the last one will be used
so in this case it's better to use -M:alias1:alias2
than -A:alias1:alias2
?
Ok, I'll give that a try
I opened an nrepl issue to start a discussion about how this might work. I've not come up with anything good.
@U09LZR36F can you link to the issue?
sorry, I meant you could stack effects from last alias + command line, not across aliases. I think making ordering do stuff beyond that is too fragile
the order of “last” should be unambiguous (but is currently not, and that’s a bug (https://dev.clojure.org/jira/browse/TDEPS-100 which may be irritating to fix)
at some point, you are putting too much on CLJ and should recognize that you are writing a program and push this complexity into a Clojure program I think
but I’m willing to consider that I’m wrong on that :)
It's a little bit complicated, because I think mains have been pushed as a common interface. But they don't compose exactly. But anything you want to do, can be done with jvm opts and a custom main.
clojure -Sdeps '{:aliases {:a1 {:main-opts ["-e" "(println,:a1)"]} :a2 {:main-opts ["-e" "(println,:a2)"]}}}' -Srepro -M:a1:a2
will print out only :a2
Also you can only ever specify one -m/--main
option
To me, those two facts combined diminish the usefulness of aliases, because you often need to produce a side effect to make an alias effective
As an example, to start an nREPL server, you need to call nREPL's start-server
function
Yep! This is a limitation from Clojure itself, inherited from Java. I've given this some thought, and I don't know what multiple mains look like. In parallel presumably?
So one person in the team uses nREPL so they, so they run,e e.g. clojure -M:nrepl
That to me is how composition of aliases would help - in different situations you can enable different sets of features
Using :main-opts
with ["-e" "(do (require ...) (start-server))]"
is a little crude but works-ish - except for the fact that main-opts don't compose
You can call functions, as long as they exit, but nrepl main doesn't, else it would be fairly useless as a main
If not through aliases, I'm not sure how I would accomplish the same thing
Edge has a workaround for this already, it looks at the system properties, and loads things based on flags there.
do jvm opts compose?
Gotcha. It seems a little arbitrary though that jvm-opts get concatenated, whereas main-opts are replaced
Jvm opts naturally concatenate in the underlying system. I think they're unordered. Main opts is talking about clojure's main-opts though. You wouldn't be able to do what you want with nrepl and other mains even if concatenation happened.
why?!
this does work https://github.com/pesterhazy/advent2018/blob/e0f8fba23339052eb112958fed712da97c7c270b/deps.edn#L6
is the problem with concatenating main-opts that the ordering of different aliases is not well defined?
here's where the behavior is defined btw https://github.com/clojure/tools.deps.alpha/blob/master/src/main/clojure/clojure/tools/deps/alpha.clj#L26
@U09LZR36F I guess your idea is to use an alias like
{:jvm-opts ["-Dclojure.run.foo=foo.core"]}
and then have a main
that scans through system properties and calls those in some order?@U06F82LES somrthing like that, yeah
@U06F82LES nrepl.main blocks forever. So rebel would not run afterwards.
nrepl.server/start-server
doesn't block
Something that we have discussed is a “start” option that would invoke an arbitrary function
Corfieldization is a fun exercise but a clearer way to achieve this effect would be great
I'm sure that if someone can come up with patches to the clojure
shell script that eliminate Corfield, lots of people will be very happy. Me included.
Fixing it is difficult I would guess. You have to figure out how to generate properly escaped strings from edn.
Mainly you need to be able to round-trip arbitrary strings from bash to file to bash again.
Portably 🙂
Sean’s description is pretty good, happy to have someone figure that out
I suspect powershell is prob easier
One issue is with nested quotes, another is needing to write the second half in bash (first half is in Clojure)
@alexmiller if you can give me an example of what needs to be done, I'll try to stretch my shell muscles.
Sorry, boarding a flight but there is a ticket in TDEPS
(there may be others but that's the first one I found)
@dottedmag ^ yup, that seems to be the whole issue.
I’ll take a look as well