This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-04
Channels
- # beginners (14)
- # boot (28)
- # chestnut (9)
- # cljsrn (18)
- # clojure (64)
- # clojure-conj (1)
- # clojure-dusseldorf (45)
- # clojure-finland (4)
- # clojure-gamedev (1)
- # clojure-greece (8)
- # clojure-italy (22)
- # clojure-russia (4)
- # clojure-spec (19)
- # clojure-uk (38)
- # clojurescript (49)
- # code-reviews (2)
- # component (12)
- # core-async (3)
- # cursive (3)
- # data-science (2)
- # events (4)
- # fulcro (394)
- # heroku (3)
- # hoplon (16)
- # immutant (11)
- # jobs (5)
- # lein-figwheel (1)
- # lumo (18)
- # off-topic (8)
- # om (11)
- # other-languages (1)
- # overtone (1)
- # pedestal (7)
- # portkey (62)
- # protorepl (1)
- # re-frame (40)
- # reagent (41)
- # ring-swagger (5)
- # spacemacs (5)
- # unrepl (5)
- # yada (12)
Is there a way to change the REPL prompt for the REPL I’m currently using?
I.e. from “my.ns =>” to something else
sure, just start a new (embedded) repl and supply your own prompt function
http://clojure.github.io/clojure/clojure.main-api.html#clojure.main/repl
(clojure.main/repl :prompt #(printf "hi mom (%s) => " (ns-name *ns*)))
If you’re using Leiningen, then the option is under :repl-options
, :prompt
, I believe.
yeah, to be clear that answer was for a clojure.main repl - other repls may vary
Thank you. Made some progress with using leiningen which is what I usually use with Cursive but think I’m going to try the clojure.main repl. When I eval inside IntelliJ using cursive it brings up this and I”m wondering if this is the repl that wasn’t able to accept an exit argument. Think I heard Mr. Halloway mention that in a talk
Doesn’t matter really I can just restart cause obviously I don’t want to be coding in an alert…
@alex-dixon Yes, you don’t want to run nested REPLs inside a lein (nREPL) REPL or you’ll get that message.
@cfleming Thank you. This is exciting 🙂
Too cool
Googling for nested repls isn’t turning up anything. Is this common practice? Also if I wanted to exit one and get back to the one it’s running in, is that possible?
By default, no. The repl variant we created for the socket server repl does support a special :repl/quit command that can be used for that. You could steal that stuff from clojure.core.server.
It's just more function options passed to repl
@donyorm @piegie Its best to just use them, understanding them isn't needed until you need to extend them. Basically, instead of using map, filter, remove, take, etc. on lazy sequence, you should use transducers instead. All it takes is a slight syntax change.
(filter even? coll)
(into [] (filter even?) coll)
So on a lazy sequence I should try to use transducers, but on a vec or a list I should use the normal functions (map, filter, etc)?
No, instead of lazy sequences. You can think of transducers as eager versions of all the lazy sequence operations. They are implemented as overloads on the same functions with the collection argument removed. So (map inc) is the eager transducer variant of (map inc coll)
The specialty with them is that they won't do redundant loops. So if you (map inc) and (filter even?) over the same collection, it will only loop once over the collection instead of twice.
Personally, I think transducers should have been the default, and lazy sequence should be an opt in alternate, but transducers were introduced later. The only time you don't want to use them is when you really need lazyness.
Instead of
(map inc (filter even? coll))
, which is the lazy sequence variant of collection operations, you just remove the collection and to chain them together you use comp instead:
(into [] (comp (filter even?) (map inc)) coll)
And just use them on all things, collections like vector, list, map, set, and also on sequences. And when you want lazyness, only then use the older versions. The syntax difference is that lazy operations are nested, so they all take the collection. And eager transducers variants are not nested, so they omit the collection and you compose them with (comp) instead.
Because of that, you do need to wrap them in something that takes a collection like into or transduce
Lazyness only introduces complexity onto your code, so unless you explicitly want lazy behaviour, transducer are still simpler.
That said, nothing wrong with the lazy variants, just need to be careful about when they get realized.
You can see a favourite Clojure question is: "How do I force a sequence to realize itself?" And often people say to wrap it in an (into). Amd if you've got nested lazy sequences, then its non trivial to realise it.
So a lot of times, lazyness just trips people over. Even when only applying one transformation.
Thank you
hey guys, quick question. I just started using the components
framework from Stuart Sierra and the reload
workflow. One thing that I still dont understand is that for development he recommends to use alter-var-root
. Why not an atom
together with swap!
. I thought that is the recommended way. Is there any benefit in using vars over atoms?
oh, really? I thought about it but I coudnt believe that that would be the only benefit 😄. Thanks @the-kenny
Is there a way to programmatically quit a repl created with clojure.core.server/repl? I’m using Cursive and it quits when I type :repl/quit
into the prompt just fine but not when I evaluate :repl/quit
from a file
that repl is interpreting a read :repl/quit keyword as a command
I suspect the path that you’re following evaluates the keyword, rather than just sending the keyword itself, like (eval :repl/quit)
the socket server repl does not look at the result of an evaluated expression, just the input
I suppose it could…. but then any evaluated expression could potentially kill your repl. not sure that’s actually a feature. :)
Yeah…I’m doing something weird as usual. Experimenting with using a REPL instead of bash to work with ssh/docker/containers. I’m changing the REPL prompt to show what host I’m ssh’d into, and when I disconnect I’d like the prompt to go back to the previous user/hostname
I was thinking nested REPLs might help encapsulate some state management but I think I’m in over my head on that one 🙂
I made this by starting with the code for ->
and adapting, but wondering whether this is already done somewhere
(defmacro v->
"Like Clojure's `->` but expects the 'forms' to be vectors"
[x & forms]
(loop [x x, forms forms]
(if forms
(let [form (first forms)
threaded (if (vector? form)
`[~(first form) ~x ~@(next form)]
(vector form x))]
(recur threaded (next forms)))
x)))
It supports the DSL I'm working on for kafka streams. e.g. imagine you want to start with a stream, join it to a bunch of other streams, and then map the result through some transformation
(v-> [:stream #"foos"]
[:join (fn [foo bar]
{:foo foo, :bar bar})
[:stream #"bar"]
[:join (fn [foobar baz]
(assoc foobar :baz baz))
[:stream #"bar"]
[:map (fn [foobarbaz]
(whatevs foobarbaz))]
That turns into the following which can be interpreted by the evaluator https://github.com/cddr/ksml/blob/master/src/cddr/ksml/eval.clj
[:map
[:join
[:join
[:stream #"foos"]
#function[user/eval9655/fn--9656]
[:stream #"bar"]]
#function[user/eval9655/fn--9658]
[:stream #"bar"]]
#function[user/eval9655/fn--9660]]
is there a reason to use vectors instead of lists there? (I am new to clojure, sorry if it’s obvious)
I'm actually not sure. Was following the example set by hiccup and honeysql which do similar things with a different target
@scaturr I create a simple helper to transform some maps with complex names (ex: {:foo/foobar 1}) to a simple name (ex: {:foobar 1}) treating colls and maps, but I do not expect key collisions, if helps you, please see this link: https://github.com/eronalves/foodship-restaurant/blob/master/src/foodship_restaurant/helpers/keywords.clj
You’re welcome! If you modify something or improve the implementation, please, send me! I will like to improve my own implementation! 🙂
#(into {} %) will take as input a list of 2-item-vectors and produce a hash map as output I want something which can take as a input a list of 3-item-vectors and produce a '2 level' hash map is there a builtin for this ?