Fork me on GitHub

I don't think this problem is supposed to be solved like that right 😄


Or this? 🙂

#((apply vector %1) %2)


very good 😄


#((vec %1) %2)


vec/vector .. confusing


I was already wondering why (vector) didn't work on its own


yea idk, probably legacy


vec converts another collection into a vector, vector creates a vector with the arguments as elements, e.g


user=> (vec #{1 2 3})
[1 3 2]
user=> (vector #{1 2 3})
[#{1 3 2}]

Pavithra Kannan10:10:11

Can some one tell me the difference of the below (let [ k "rain"] (println (str "It is going to " k))) It is going to rain nil (let [ k "rain"] (str "It is going to " k)) It is going to rain Why are we using the println when str does the same?

Daniel Truemper10:10:00

'println' is a side effect. It actually prints the string to stdout. The return value of the form is 'nil'. The return value of the second form is the string which happens to be printed in the repl. So it feels the same but it's not


just to make it a little more visual: if you run the println one as a standalone program, this is your output:

It is going to rain
If you run the str one as a standalone program, this is your output:
(it's nothing)

Pavithra Kannan12:10:21

Standalone program in the sense, (println "Hello") - Hello Because when i run as (str "Hello") even this get printed?


this only works because of the REPL prints return values by default; the following is worth understanding as well:

(let [k "rain"]
  (str "It is going to " k)
  (str "It is also going to be cold"))

Pavithra Kannan13:10:29

@U8RCW3A2Y why latter was printed ?


Because the return value of let is the last form inside of it, and the REPL only prints return values


The latter one is not being "printed", it is the return value of the of the function. When you run a function in the REPL it outputs the return value, but that output is different from the output of an actual print statement

(let [k "rain"]
  (println "This will print")
  (str "It is going to " k)
  (str "It is going to be cold"))


Glad we could help, this stuff can be hard to wrap your head around at first. Really the only purpose of non-final forms inside a let binding is for side-effects.


It's probably also worth noting that, in the REPL, you actually saw two lines from your println case:

It is going to rain
So you are seeing the REPL print the result -- nil -- as well as the side-effect of println itself.


In the str case, the REPL still printed the result -- which was the whole string.

Mario C.17:10:10

Is there anyway I can 'inject' a variable in a cljs file during build time? using lein cljsbuild auto?


@mario.cordova.862 See the :closure-defines compiler option

Mario C.17:10:27

@mfikes Thanks! I am using :closure-defines but its not replacing the default value for some reason. Still poking around though

Mario C.17:10:59

How do you define :closure-defines if you have a ns set up as (ns myproj.api . . .)?

Mario C.17:10:34

:closure-defines {"myproj.api/myvariable" "test"}?

Mario C.17:10:53

:closure-defines {'myproj.api/myvariable "test"}?

Mario C.17:10:00

:closure-defines {myproj.api/myvariable "test"}?

Mario C.17:10:09

Non work BTW


so, when we are writing Clojure code, you're literally writing lists and nested lists? and it happens that, for your "code", i mean, list haha, be evaluated, clojure reader expects your first item to be a function, a macro or a special operator, else an exception is thrown. Is that correct?


That’s a pretty good summary, of course it’s not only lists but also vectors, maps etc but that’s the general gist.


As in, to write a defn you have to also type a vector for the arguments, right?


yes! wow Clojure is awesome haha


user> (class '(+ 1 1))


Which turns out, that a List is just a directly implementation of lSeq

user> (seq? (cons + (cons 1 (cons 1 '())))) 
user> (eval (cons + (cons 1 (cons 1 '()))))


my mind is going to explode


one small gotcha here: the list? function isn't actually something you should use (it returns false for most seqs, and for cons for example)


yeah, i noticed that, when i have to check if it's a list, i prefer to use seq?

Mario C.18:10:54

If anyone was curious >For :optimizations :none, a :main option must be specified for defines to work, and only goog-define defines are affected. :closure-defines currently does not have any effect with :optimizations :whitespace.

Mario C.18:10:11

Which is why my :closure-defines were not taking effect.


I'm struggling to convert a java sample to clojure as I don't know java. Anyways, i'm trying to convert the below sample

SharedKeyCredentials creds = new SharedKeyCredentials(accountName, accountKey);
final ServiceURL serviceURL = new ServiceURL(new URL("http://" + accountName + "."), StorageURL.createPipeline(creds, new PipelineOptions()));
containerURL = serviceURL.createContainerURL("quickstart");

(defn blob-client []
  (let [s-url (ServiceURL. ( "") (StorageURL/createPipeline (storage-creds) (PipelineOptions.)))]
    ((.createContainerURL s-url)))


for starters, I'd turn every definition in the java into a let binding


(let [creds ... service-url ...] ...)


((...)) in an interop form is pretty much always an error


you should be able to have a translation where each line of java becomes one line of clojure


I'm specifically confused about how to create this serviceURL.createContainerURL("quickstart"); I have a service-url let binding but I can't seem to figure out how to call a method on a bound variable

Alex Miller (Clojure team)20:10:25

(.createContainerURL service-url “quickstart”)


going through "the joy of clojure" and looking at the section that describes having tests in meta data the get ran by clojure.test/run-tests.. Is there a rule on a time and place to use this functionality, or is it best to keep tests in a test directory?


I've never seen a project that actually uses that feature


I have yet to come across one myself..


but admit to having tunnel vision on the code bases I have looked through


Am I able to extend-type of vectors so I can add them e.g. (+ [2 2] [4 4])?


Thus that would do a component-wise addition of the two vectors? Or is that the wrong thinking and I'm better off making a function? Cheers


the problem is that + isn't defined in a way that allows such extension


you could make your own plus multimethod, that uses + for numbers, and your own code for data structures


You can even name your fn +


that's also true, but more tedious to use from other code


Making its fully qualified name clojure.core/+ would involve unpleasant and fragile surgery that others could not consume easily. making its fully qualified name is much easier.


Oh so you're saying extend + not vector or whatever it's type is?


Oh yeah I guess it needs to know how to deal with those operands, right?


right, clojure.core/+ isn't really extensible (IIRC making it extensible would be really bad for clojure performance)


so you'd be making a standin for it, that can be extended


or maybe you care about performance, then you'd likely be looking at one of the matrix libs instead of doing all this yourself...