This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-17
Channels
- # admin-announcements (104)
- # adventofcode (3)
- # aws (1)
- # boot (651)
- # cljs-dev (21)
- # cljsrn (12)
- # clojure (81)
- # clojure-china (1)
- # clojure-germany (1)
- # clojure-miami (2)
- # clojure-nl (8)
- # clojure-russia (19)
- # clojurescript (208)
- # core-typed (1)
- # cursive (19)
- # datavis (55)
- # datomic (57)
- # events (1)
- # hoplon (102)
- # ldnclj (12)
- # leiningen (8)
- # off-topic (11)
- # om (127)
- # onyx (21)
- # parinfer (2)
- # portland-or (3)
- # proton (2)
- # re-frame (2)
- # reagent (6)
what's the reasoning behind why I can assoc
into a vector but cannot dissoc
?
what would you expect dissoc
ing a vector to do?
(dissoc [:a :b :c] 1) ;=> [:a :c]
yeah, that's what I'd expect too. I think it has to do with the underlying implementation, though
you'd end up having to copy the whole vector
right
so I imagine it's just for performance reasons
and memory
well, it'd be unexpected for dissoc
to have wildly different performance characteristics on maps vs vectors
unexpected, but easily explained by thinking about how vectors are implemented
sure. by the same token, though, it's also easily worked around by implementing your own dissoc
once you understand the implications
(defn dissocv [v idx]
(vec (concat (subvec v 0 idx)
(subvec v (inc idx)))))
that's what I'm using atm
seems reasonable
my vectors will not be large in this case, so I'm not terribly worried about performance or memory
(this is actually cljs)
In my experience, when you find yourself writing functions like that, you’re usually using the wrong data structure. I’d probably use an array-map and just key on integers. dissoc
works as expected there.
i thought of that as a cute comedy option, but it doesn't rekey the rest of the map
well, I assume there's a reason @bostonaholic wants the collapsing behavior, but then again, I see your point re: treating a vector like a map from int to whatever
honestly, I have to go back and see if a vector is really what I need
does anyone have experience using lein repack?
I can’t figure out how to make it work on a project. I end up with a manifest with a single “nil” branch with all files in it. Which crashes
Say I have some very performance sensitive map, with only lookups and no modifications after it. We’ve already had a bit of a speed up by changing the Persistent HashMap from Clojure with a simple ConcurrentHashMap (Unmodifiable) … but it might make sense for our use case (essentially a very large dictionary of strings, think millions of terms) to use a (Minimal) Perfect Hash for the Hashing Function
but eeh there is no Java impl that I know of that takes the a hashing function as arg (yay OO over FP)
so I need to override the hashCode of string somehow, or encapsulate the keys in a new object (adding a bit of overhead to object creation)
what would be the best way to go about this?
I guess I can just make a simple type/object that encapsulates the string, beats modifying the build in HashMap to take a function as argument 😛
That's how I would have done it, yeah. A little more overhead for creation but in the end you get the same level of conposability if you want to swap out how the hash is made, etc.
has anyone run into issues where a you defined a macro in your code, but when you run the uberjar it won’t find that macro. In dev mode it does find it tho.
btw, the macro is pretty simple
(defmacro step
"Separates logical steps in a clojure script file."
[ctx msg & body]
(list 'do (list 'prn msg) (cons 'do body)))
@roberto: how do you mean? does (constantly (list ….)) do what you want?
ah. you want eval
but when compiled to an uberjar, it can’t find a macro that is used within the string I’m loading
you need to load and eval the string before you can compile any code that uses the macro
yeah, what is upsetting me is that clojure works different in the repl than as an uberjar
clojure compiles each form in turn.
you start developing, everything works fine in the repl, you get very far, and then when you want to package and deploy, things explode
yeah but that’s not necessarily because of the jars. the order in which things are defined matter in clojure, and if you’re working from the repl you don’t necessarily have the right sequence of definitions down in a file so you can recreate it
so it probably also won’t work if you use
or require
the code instead of trying to build a jar
I mean use
in a fresh environment
I could take a look at your code if it’s available online but I have to go in a few minutes
Can I use maven build plugins when building clojure projects? https://github.com/tgrall/drill-simple-mask-function/blob/master/pom.xml
@roberto from the looks of it, your step
macro should just work as long as it’s required
or otherwise defined before us
more or less
using backquotes would make it a bit more idomatic,
` (defmacro step [msg & body] (do (println ~msg) ~@body))
` I think
this is really how it is being called:
(defn run-dsl-script [ctx script-string]
(let [dsl-script (load-string script-string)]
(dsl-script ctx)
(eval (dsl-script ctx))
@(:output ctx)))
backquotes don’t really work slack
so, the output of calling read-string
on the script-string
is a fn, eg:
(fn [s] (step ….))
and you’ve got step
defined in the current namespace?
sorry I’ve got to go
hope someone can help you 😄
@hlship: you mean rebinding stdout? I don’t think you’d want to do it like that, you can just use with-out-str
Nope I'm doing some nasty & tricky where I need to change System/out (via System/setOut) and then rebind out to match.