Fork me on GitHub
#beginners
<
2016-04-22
>
Jon02:04:41

like (aget a "b") that generates a["b], how do I generate a["b"](c) with js interop?

Jon02:04:58

in :advanced mode the property name might be uglified, but I don't want it to

lauri05:04:23

@polymeris: there is https://github.com/untangled-web/untangled which works on top of Om.next and should make implementing some functionality easier.

lucj0613:04:13

Hi, I’m working on my first Clojure project, a consumer of RabbitMQ messages. I’ve created the project with leiningen but I used the single core.clj file to put everything. I’m cleaning this up and creating several files (smtp.clj, mq.clj, sms.clj, …) that I load in the main core.clj. Some functions (that are not in the same files) need the same clojars (like clj-http, log, …) what is the recommended way to load those commun lib ?

jswart13:04:11

This is what the (ns yourproject.core (:require [clj-http :as http] [log :as l] …)) is for

lucj0613:04:23

@jswart great so loading them in the core makes them available to all the files loaded with (load « … ») ?

jswart13:04:20

Hmm, so if you are writing the files you don’t want to use load.

jswart13:04:28

Load is for the REPL mostly.

jswart13:04:38

In general @lucj06 clojure has changed enough that any comment from > 1-2 years ago is likely not a best practice. Chouser is a smart dude but in general that is not the “state of the art” in clojure.

jswart13:04:53

use would be considered a “worst practice” at this point.

jswart13:04:18

I recommend reading all of braveclojure to get started. It is a super fast read but super packed with knowledge.

jswart13:04:39

and probably the fastest way to go from 0 -> understanding clojure

lucj0613:04:40

yep, I’m reading it

lucj0613:04:16

but I should probably reread all the namespace and organisation stuff

jswart13:04:29

Yeah that part is unusual when you come from other languages

jswart13:04:39

b/c the REPL and writing code are a bit different

lucj0613:04:41

thanks for your tips of requiring within the ns

jswart13:04:42

you do different things

jswart13:04:01

yeah no problem

jswart13:04:13

you can use require too when you are working in a REPL

lucj0613:04:30

I’ll give a closer look to « use » also

jswart13:04:54

lein repl and then (require ‘[myproject.core :as c]) then (c/my-fn 123)

jswart13:04:40

I would mostly avoid use. I write clojure for my job and I almost never use it.

jswart13:04:48

I do what I just typed

jswart13:04:12

I do the above and then: (in-ns ‘myproject.core)

jswart13:04:17

to achieve a similar effect

lucj0613:04:31

just to be sure. Let’s say I have core.clj and smtp.clj

lucj0613:04:50

at the top of smtp.clj I use (in-ns ‘myproj.core)

lucj0613:04:08

and in core.clj I use (load « smtp »)

lucj0613:04:14

the load part is wrong ?

jswart13:04:48

So when you are writing the files themselves, in your editor you would do this: (one sec I’m making a big snippet to paste in)

lucj0613:04:38

thanks. in term of file structure do you have project/core project/smtp and project/db ?

jswart13:04:16

yeah that part sort of depends

jswart13:04:19

basically src/myproject/core.clj -> project.core and src/myproject/db/core.clj would be project.db.core the NS macro just looks at the directory structure

jswart13:04:35

that is honeslty something I usually forget and just mess with until it works

lucj0614:04:06

got it ! (I usually do the same :) )

lucj0614:04:45

thanks a lot for your help, that’s great.

lucj0614:04:37

np, next time I’m on the east coast simple_smile

dharrigan14:04:01

So, I guess this has been asked many times, but I see that lists and vectors are pretty much similar - where would one favour lists over vectors?

dharrigan14:04:15

(and perhaps why one is a sequence and the other is not?)

zzamboni14:04:10

vectors allow random access, lists only sequential

zzamboni14:04:22

and other differences

dharrigan14:04:35

so a vector is similar to an array/List in java, whereas a list is more akin to a LinkedList.

zzamboni14:04:09

(I think, I’m not big on Java)

dharrigan15:04:23

Those Clojure Koans are pretty nifty