Fork me on GitHub
#beginners
<
2018-10-03
>
Azzurite08:10:51

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

deliciousowl08:10:02

Or this? 🙂

#((apply vector %1) %2)

Azzurite08:10:24

very good 😄

Azzurite09:10:50

#((vec %1) %2)

deliciousowl09:10:33

vec/vector .. confusing

deliciousowl09:10:44

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

Azzurite09:10:37

yea idk, probably legacy

schmee09:10:59

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

schmee09:10:08

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

Pavithra Kannan10:10:42

Thank you @UBWJ6QDGF

Azzurite11:10:18

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?

frenata13:10:44

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 ?

frenata14:10:54

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

enforser14:10:58

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

Pavithra Kannan14:10:27

Thank you @U8RCW3A2Y @UCQL6E7PY :+1:

frenata14:10:44

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.

seancorfield17:10:38

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

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

seancorfield17:10:02

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

Pavithra Kannan17:10:32

Thank you @U8RCW3A2Y @U04V70XH6 :+1:

Mario C.17:10:10

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

mfikes17:10:16

@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

CyberSapiens9717:10:30

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?

orestis17:10:38

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

orestis17:10:21

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

CyberSapiens9717:10:52

yes! wow Clojure is awesome haha

CyberSapiens9717:10:40

user> (class '(+ 1 1))
clojure.lang.PersistentList

CyberSapiens9717:10:04

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

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

CyberSapiens9717:10:33

my mind is going to explode

noisesmith17:10:45

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)

CyberSapiens9718:10:57

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.

dfcarpenter19:10:43

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. (java.net.URI. "") (StorageURL/createPipeline (storage-creds) (PipelineOptions.)))]
    ((.createContainerURL s-url)))

noisesmith19:10:47

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

noisesmith19:10:15

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

noisesmith19:10:50

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

noisesmith19:10:29

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

dfcarpenter20:10:39

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

alexmiller20:10:25

(.createContainerURL service-url “quickstart”)

javazquez21:10:06

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?

noisesmith21:10:09

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

javazquez21:10:35

I have yet to come across one myself..

javazquez21:10:37

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

dfcarpenter21:10:08

@alexmiller Thanks!

bones22:10:54

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

bones22:10:39

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

noisesmith22:10:56

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

noisesmith22:10:29

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

mfikes22:10:24

You can even name your fn +

noisesmith22:10:50

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

andy.fingerhut22:10:33

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

bones22:10:10

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

bones22:10:34

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

noisesmith22:10:38

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

noisesmith22:10:04

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

noisesmith22:10:33

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