Fork me on GitHub
#clojure
<
2015-12-17
>
bostonaholic00:12:39

what's the reasoning behind why I can assoc into a vector but cannot dissoc?

anisoptera00:12:35

what would you expect dissocing a vector to do?

akiva00:12:30

Vectors can’t be sparse so you can’t dissoc on an index.

bostonaholic00:12:31

(dissoc [:a :b :c] 1) ;=> [:a :c]

anisoptera00:12:22

yeah, that's what I'd expect too. I think it has to do with the underlying implementation, though

anisoptera00:12:31

you'd end up having to copy the whole vector

akiva00:12:06

Yep. Due to immutability, there could be serious memory and performance issues.

bostonaholic00:12:14

so I imagine it's just for performance reasons

anisoptera00:12:36

well, it'd be unexpected for dissoc to have wildly different performance characteristics on maps vs vectors

bostonaholic00:12:22

unexpected, but easily explained by thinking about how vectors are implemented

anisoptera00:12:14

sure. by the same token, though, it's also easily worked around by implementing your own dissoc once you understand the implications

bostonaholic00:12:26

(defn dissocv [v idx]
  (vec (concat (subvec v 0 idx)
               (subvec v (inc idx)))))

bostonaholic00:12:33

that's what I'm using atm

anisoptera00:12:42

seems reasonable

bostonaholic00:12:14

my vectors will not be large in this case, so I'm not terribly worried about performance or memory

bostonaholic00:12:22

(this is actually cljs)

akiva00:12:30

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.

anisoptera01:12:08

i thought of that as a cute comedy option, but it doesn't rekey the rest of the map

akiva01:12:31

‘Cute comedy option’. Heh.

anisoptera01:12:50

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

bostonaholic01:12:43

honestly, I have to go back and see if a vector is really what I need

joost-diepenmaat10:12:06

does anyone have experience using lein repack?

joost-diepenmaat10:12:14

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

joelkuiper11:12:30

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

joelkuiper11:12:49

but eeh there is no Java impl that I know of that takes the a hashing function as arg (yay OO over FP)

joelkuiper11:12:16

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)

joelkuiper11:12:22

what would be the best way to go about this?

joelkuiper11:12:08

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 😛

akiva11:12:56

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.

doddenino11:12:08

Has anyone used sente on an amazon ec2 instance?

roberto14:12:59

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.

roberto14:12:30

I suspect it has something to do with aot

roberto14:12:35

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)))

roberto14:12:13

is there a way to convert a list to a function?

joost-diepenmaat14:12:42

@roberto: how do you mean? does (constantly (list ….)) do what you want?

roberto14:12:25

no, I read a file with read-string

roberto14:12:31

this file contains a function definition

roberto14:12:39

I’d like to execute that function

joost-diepenmaat14:12:49

ah. you want eval

roberto14:12:31

hmm, can’t seem to make it work with eval either

roberto14:12:45

I’m down this rabbit hole, because uberjars suck

roberto14:12:54

it works fine in dev mode using load-string

roberto14:12:18

but when compiled to an uberjar, it can’t find a macro that is used within the string I’m loading

joost-diepenmaat14:12:38

you need to load and eval the string before you can compile any code that uses the macro

roberto14:12:04

yeah, what is upsetting me is that clojure works different in the repl than as an uberjar

joost-diepenmaat14:12:05

clojure compiles each form in turn.

roberto14:12:38

you start developing, everything works fine in the repl, you get very far, and then when you want to package and deploy, things explode

joost-diepenmaat14:12:42

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

joost-diepenmaat14:12:10

so it probably also won’t work if you use or require the code instead of trying to build a jar

joost-diepenmaat14:12:24

I mean use in a fresh environment

joost-diepenmaat14:12:38

I could take a look at your code if it’s available online but I have to go in a few minutes

joost-diepenmaat14:12:13

@roberto from the looks of it, your step macro should just work as long as it’s required or otherwise defined before us

joost-diepenmaat14:12:22

using backquotes would make it a bit more idomatic, ` (defmacro step [msg & body] (do (println ~msg) ~@body)) ` I think

roberto14:12:49

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)))

roberto14:12:55

and that worked in dev

joost-diepenmaat14:12:02

backquotes don’t really work slack

roberto14:12:23

the script-string is slurped from a file, and just has a number of calls to step

roberto14:12:44

in uberjar, it explodes in load-string

roberto14:12:55

so I’m changing to read-string

roberto14:12:43

so, the output of calling read-string on the script-string is a fn, eg:

(fn [s] (step ….))

joost-diepenmaat14:12:18

and you’ve got step defined in the current namespace?

roberto14:12:42

yeah, it is defined in the same namespace

joost-diepenmaat14:12:19

sorry I’ve got to go

joost-diepenmaat14:12:29

hope someone can help you 😄

firthh15:12:28

@roberto: you're calling a macro at run time on a file that has just been evaled?

roberto15:12:21

yeah, fixed it

roberto15:12:51

appended a require to the string loaded from the file

hlship23:12:39

Is there something sneaky that keeps you from (alter-var-root #'out ...)?

lfn323:12:36

@hlship: you mean rebinding stdout? I don’t think you’d want to do it like that, you can just use with-out-str

hlship23:12:27

Nope I'm doing some nasty & tricky where I need to change System/out (via System/setOut) and then rebind out to match.

lfn323:12:42

Well in that case you probably want to use a binding rather than alter-var-root. I’m not sure how well alter-var-root works with dynamic vars, but I suspect not well.

hlship23:12:42

Ok, looks like its an oddity of running the REPL.

rbxbx23:12:13

x-posted from #C03S1KBA2 on freenode: Has anyone here used mcohen01's amazonica lib for dynamodb? Specifically performing a scan query with key-conditions. Having a difficult time sussing out the exact sort of heterogenous map it's expecting 😉