Fork me on GitHub
#beginners
<
2017-03-24
>
camdenclark03:03:55

can anyone help me with a stupid git question? totally clojure unrelated

camdenclark03:03:27

I forked a repository, made a commit and made a pull request on my fork

camdenclark03:03:15

now i’m making sort a different commit so I want to be able to go back down to the origin branch to the original forked repository, make my commit, then make a separate pull request

camdenclark03:03:40

(also keep in mind I’ve made the edits already to the branched repository…)

eriktjacobsen03:03:23

Do you have an origin setup?

eriktjacobsen03:03:11

it might be just doing git checkout origin/master -b new_branch and committing that new branch for PR

eriktjacobsen03:03:48

if you don't, then sub origin/master with the commit hash of where the original repo's HEAD

camdenclark04:03:52

Yeah that helped, thanks

gklijs06:03:22

I now have a luminus project, with three cljc files I want to use in a different project. Does this mean, when I already ran the other project, just requiring the namespaces will be enough?

jumar06:03:44

@gklijs I'd say that you need to ensure that the another project is on classpath, which typically means using something like lein install to install the other project jar to local maven repo and then add the appropriate require. You can also consider using "checkout dependencies": https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#checkout-dependencies

gklijs07:03:35

Thanks, that looks usefull

algiras09:03:39

Hello. I am looking for a clojure library that would JWK. The only thing I can find is that https://github.com/palletops/clj-docker/blob/master/src/com/palletops/docker/jwk.clj has some code to do so, but I can't find any dedicated library.

manu10:03:53

I've just started learning clojure-specs. My question is: what is the right place to put them? in a different file or right next to the production code?

not-raspberry10:03:00

Right next to.

not-raspberry10:03:12

If you put it to a single file, you'll have nasty conflicts in maps specs created with s/keys.

not-raspberry10:03:49

Sometimes you are forced to put them somewhere else, e.g. to cljc files when you share them between clojure and clojurescript.

not-raspberry10:03:56

Another case is some common spec building block that you use in multiple places. At that point it will be obvious that it needs to be placed in some 'common specs' ns.

manu10:03:48

so basically the best would be closed to the code, but if I have to share them so I have to use a different ns

yogidevbear13:03:21

Anyone willing to help me test something. I have a friend who is doing a comparison of how different languages handle clojures. I was hoping to help him out with converting this JS closure functionality into CLJ:

function doit() {
    var a = ["a", "b", "c"];
    var b = ["x", "y", "z"];
    var counter = 0;
    
    a.forEach(function(foo) {
        counter = 0;
        b.forEach(function(bar) {
            counter++;
            // print info
            console.log({
                counter: counter, 
                foo: foo, 
                bar: bar
            });
        });
    });
}
I've started the definitions as:
(def a ["a" "b" "c"])
(def b ["x" "y" "z"])
(defn doit [] (
  ...))
(doit)
I'm a bit stumped as to what to do within the doit function though simple_smile

yogidevbear13:03:43

Would I approach it using two maps like this? (defn doit [] (map a (map b ( ... )))

singen13:03:50

I’m a bit surprised that this throws exception instead of catching it (try (do (ex-info "noooooooo!" {})) (catch Exception e (println “oopsie”)))

singen13:03:01

Is it supposed to work like that?

dominicm13:03:02

@yogidevbear those should be inside a let, I imagine scoping inside doit is important

agile_geek13:03:09

@yogidevbear I am struggling to see how that JS is really a Closure? I guess doit contains the two arrays a and b so that's a closure but it's not a useful one.

yogidevbear13:03:26

Don't think I'm aiming for useful here, more just an observation of how clojures are treated in different languages

agile_geek13:03:02

@dominicm yeah the a and b would have to be scoped to doit for it to be considered a closure. After that I'd use a for list comprehension to process b inside a

dominicm13:03:23

@agile_geek probably better to be a doseq, side effects & all 😛

agile_geek13:03:44

Oh good point. Forget about the println

yogidevbear13:03:58

So more like

(defn doit [] (
  (let a ["a" "b" "c"])
  (let b ["x" "y" "z"])
  (doseq ...)))
(doit)

agile_geek13:03:54

(defn doit
   (let [a ["a" "b" "c"] b ["x" "y" "z"]]
       ....
    )
)

yogidevbear13:03:50

Or

(defn doit [] (
  (doseq [a ["a" "b" "c"]
          b ["x" "y" "z"]]
    ...)
(doit)

dominicm13:03:13

That doseq is the same as his nested forEach's

yogidevbear13:03:11

I should probably have added the output that I see from the JS example as a comparison:

VM128:11 Object {counter: 1, foo: "a", bar: "x"}
VM128:11 Object {counter: 2, foo: "a", bar: "y"}
VM128:11 Object {counter: 3, foo: "a", bar: "z"}
VM128:11 Object {counter: 1, foo: "b", bar: "x"}
VM128:11 Object {counter: 2, foo: "b", bar: "y"}
VM128:11 Object {counter: 3, foo: "b", bar: "z"}
VM128:11 Object {counter: 1, foo: "c", bar: "x"}
VM128:11 Object {counter: 2, foo: "c", bar: "y"}
VM128:11 Object {counter: 3, foo: "c", bar: "z"}

tbaldridge13:03:46

Go write him an example of how broken JS closures are:

tbaldridge13:03:03

(doseq [i (for [x (range 10)] 
                  (fn [] x))]
    (println (i))) 

tbaldridge13:03:27

prints 0-9 in Clojure, and prints 9 ten times on Python and JS

tbaldridge13:03:40

mutable closures FTL

agile_geek13:03:40

@singen you are not throwing the exception. Your (ex-info ...) call is creating an exception that then falls out of the the try.

agile_geek13:03:07

this is throwing the exception

(try
    (throw (ex-info "noooooooo!" {}))
    (catch Exception e (println "oopsie")))

singen13:03:22

Ah, I need to throw ex-info, of course

singen13:03:30

Why is catch bad?! 😄

agile_geek13:03:54

It's clojurebot complaining - it works in an ordinary repl

tbaldridge13:03:52

@yogidevbear my solution

(def as ["a" "b" "c"])
(def bs ["x" "y" "z"])

(for [a as
      [counter b] (map-indexed vector bs)]
  {:counter counter :foo a :bar b})

yogidevbear13:03:54

That's awesome! Thank you @tbaldridge :thumbsup:

yogidevbear13:03:06

Now to fully comprehend what you'd actually done 🙂

yogidevbear13:03:09

So (for [a as is doing a for-loop over as and assigning the current for-loop item to a yes?

yogidevbear13:03:17

The next line confuses me a little. [counter b] is creating counter and assigning it the value of b which is coming from the index of the current item position in the map of vector bs?

yogidevbear13:03:39

Am I understanding that correctly?

tbaldridge13:03:42

no, the map-index pairs each b with a number, then we use destructuring to assign the number to counter and the value to b

yogidevbear13:03:26

okay, was just reading docs on map-indexed

yogidevbear13:03:34

I think that makes sense

tbaldridge13:03:50

all the closures are hidden from you here behind the for macro. So you don't ever see them but they are there 🙂

tbaldridge13:03:34

This code doesn't print out the results, but returns them which is the more functional method anyways.

yogidevbear13:03:37

So (map-indexed vector bs) is generating something like [0 \x 1 \y 2 \z]

tbaldridge13:03:03

wait, no, it's [[0 "x"] [1 "y"] ...]

yogidevbear13:03:28

Sorry, yes 🙂

mbcev17:03:12

Is anyone familiar with http://github.com/Gonzih/cljs-electron ?? Long story short I want to use it to build an app but I'm a confused in regards to where my Clojure (aka desktop code) would go and how it would communicate with the ClojureScript/Electron UI code.

manutter5117:03:35

@mbcev Normally you don’t write Clojure code in an Electron app — your back end is node.js, and you use node/npm for all your requires and such

mbcev17:03:58

@manutter51 so I'm probably using the wrong tool for the job. What I'd like to do is have some clojure code that does some networking stuff and I thought it would be cool to use Electron as a nice front-end for that app. But perhaps my thinking of Electron and CLJS as a "View" for a Clojure "Controller" in a MVC type mindset is misguided. Yes?

manutter5117:03:29

I don’t think many people are trying to build stuff like that, in any case. You might be interested in looking for a JavaFX/Clojure lib, I think I saw one recently but never got around to playing with it.

manutter5117:03:22

On the other hand, if you don’t mind browsing the NPM archives, you can probably find Node equivalents for the networking stuff. You can still write your app code in ClojureScript, and just use interop to talk to the Node lib

manutter5117:03:46

I’ve done a little of that, and it’s fun 🙂

mbcev17:03:05

If I were doing my app the "traditional" (for me) way I'd probably use Java and Netty for the networking code but I kind of wanted to see what Aleph was all about and then I thought Electron looked interesting. But from what it sounds like maybe it would be easier to use JavaFX + Clojure rather than have the Clojure "server" code talk to the Electron "client" code right?

noisesmith17:03:29

right - and cljs in electron can actually do all that networking stuff if you want to use electron

noisesmith17:03:55

but the best options are clojure/javafx or cljs/electron rather than trying to mix them, for a simple app

mbcev17:03:48

Gotcha, gotcha. Thank you guys. Can you point me in the direction of some networking stuff with cljs?

noisesmith17:03:37

also, don’t be afraid of interop - you can use the AJAX api directly from cljs code

noisesmith17:03:10

or the extensive built in libraries that node provides

drewverlee17:03:44

I know that a clojure program can use a java library, is the reverse also true? Does it require anything?

noisesmith17:03:22

drewverlee it’s pretty straightforward - it means using Clojure.java.api.Clojure and clojure.lang.IFn

noisesmith18:03:02

usually you need to use Clojure.var to find require, and calling that to make your ns load, then Clojure.var again to access the functions or values you need

noisesmith18:03:36

in fact, if I were designing the next version of clojure.java.api.Clojure I would make require accessible directly without using var to find it

noisesmith18:03:50

(not that anyone would let me do such a thing)

drewverlee18:03:20

I’m trying to find out if i can just make this library I need to create in Clojure, as the rest of the team is java, i figured i would do it in java. However sense i’m a java newbie, its becoming very painful as 60% of my mental energy is spent on boiler plate types.

drewverlee18:03:46

Also, i wanted to make it very extensible.

noisesmith18:03:03

@drewverlee it might be simplest if you make a small java class that uses Clojure.var to load up and require your clojure functions, and then exposes a normal java interface

noisesmith18:03:53

perhaps you could even get a java using coworker to define the interface, and a minimal class where you can fill in the implementation via Clojure.var, then do the rest of the work in regular clojure

drewverlee18:03:27

Yea, i’ll look into that. Thanks for the advice.

noisesmith18:03:41

the guide on http://clojure.org should be pretty straightforward to follow

noisesmith18:03:47

also your clojure deps can be translated to a pom.xml, or you can implement your clojure lib in the normal way, and once that is in a maven repo the larger project can pull it in like any other maven dep

mathpunk20:03:58

Does it make sense to define my own tagged literals in clojurescript? It seems like a neat way to design but it also looks less straightforward than in Clojure

drewverlee20:03:01

How does one pass a macro around like or? I felt like i knew how to do this and now i find myself confused about my options

drewverlee20:03:44

I just want to let the user choose between or or and

noisesmith20:03:09

@drewverlee you pass functions that use or or and internally - macros are not first class