Fork me on GitHub
#beginners
<
2018-01-16
>
seancorfield00:01:52

@pablore And you have your source code all under src and your test code all under test, yes?

justinlee03:01:22

I’m trying to figure out how to include react-dnd, which apparently is no longer part of cljsjs. The cljs Dependencies documentation has an example when the library code expressly sets a global variable, but it isn’t clear to me what one does in place of an import statement or a require statement because without that, there’s no name by which to refer to the library’s exports. Likewise with the “Packaging Foreign Dependencies” documentation, I don’t see where you name the global. Am I missing something?

abdullahibra10:01:21

Hello Guys, if there is someone using cider+emacs, if so please just refer me how can i compile file which depend on another file and contain something like (require [ns1.hello :refer :all]), i got errors which refer all funtions from ns1.hello not defined ?

abdullahibra10:01:33

i'm new in Cider + emacs

abdullahibra10:01:09

it's working with (use)

abdullahibra10:01:17

maybe i made something wrong

conan13:01:39

if it's somebody else's file you're trying to use, have you included the correct dependency in your project.clj file? what happens if you run lein deps :tree on the command line - it should print out a tree structure of all your dependencies, which is a good way of checking to see if it can resolve the one you need. If both files are yours (you've created them), are you working in the repl? I can't remember the syntax for use (it's deprecated now), but require looks like this (note the quote): (require '[clojure.string :as string]) you can :refer individual functions or :all of them, but typically it's more idiomatic to alias the namespace using :as (like above) and refer to the functions as (string/lower-case "BANANA")

conan13:01:18

if you're not in the repl, there's a shortcut to the ns declaration that lets you require things, and it looks like this (note that :require is a keyword):

(ns my-string-fns
  (:require [clojure.string :as string]))

Eran Harel12:01:41

Hiii, I have a java client that returns guava ListenableFuture, and I want to wrap it up for clojure code. I tried to use (promise) and then add a callback on the java future, but I didn't find a way to set the exception on the clojure promise. Dereferencing the future works, but everyone that will want to work async will have to (reify) the callback on the future... hints?

Eran Harel12:01:29

^^ How about writing this as a multi-arity function? I.e. add an overloaded function arity with on-success, on-error callbacks. Makes sense?

Eran Harel13:01:21

This is what I came up with. WDYT?

(defn listenablefuture-handler
  [lf on-success-func on-fail-func]
  (-> lf
      (Futures/addCallback (reify FutureCallback
                             (onSuccess [_ res]
                               (on-success-func res))
                             (onFailure [_ e]
                               (on-fail-func e)))))
  lf)

(defn resolve-ip
  ([client ip] (.resolveAsync client ip))
  ([client ip on-success-func on-fail-func]
    (listenablefuture-handler
      (resolve-ip client ip)
      on-success-func
      on-fail-func)))

Kari Marttila14:01:21

I can't make Leiningen work with new Clojure 1.9.0. If I create a new app with "lein new app myapp", and run "lein repl" it works just fine. But if I change the dependency "org.clojure/clojure "1.8.0"" to "org.clojure/clojure "1.9.0"" in project.clj, and then start "lein repl", it gives some odd error: Error loading cider.nrepl.middleware.test: java.lang.RuntimeException: Invalid token: ::clojure.test/once-fixtures, compiling:(cider/nrepl/middleware/test.clj:129:57) I tried to google about this but didn't find anything that could fix this issue. Any help would be appreciated. 😀

manutter5114:01:04

@kari.marttila what version of Leiningen?

manutter5114:01:44

maybe you need a lein upgrade?

dpsutton14:01:42

that's a cider error. i think ::clojure.test/once-fixtures is invalid syntax in clojure versions lower than 1.9

dpsutton14:01:51

what version of cider are on on? i believe this was fixed

Kari Marttila14:01:15

Sorry, forget to mention that. Leiningen 2.8.1 and Java 8.

dpsutton14:01:33

what version of cider? that's the only important thing here (i think)

Alex Miller (Clojure team)14:01:45

that has been valid syntax since clojure 1.0

dpsutton14:01:08

whoops. apologies. what am i thinking of then? i thought there was a change in namespaced keys?

Alex Miller (Clojure team)14:01:13

oh, actually using a full namespace there rather than an alias is newly invalid in 1.9!

Alex Miller (Clojure team)14:01:53

so prob need to upgrade cider I would guess

Kari Marttila14:01:05

It's the plain project.clj template lein new app generates, there is no dependency to cider.

dpsutton14:01:30

are you using emacs to run clojure?

Kari Marttila14:01:11

No, just trying "lein repl" in Linux command line. Works with Clojure version 1.8, not with 1.9.

Alex Miller (Clojure team)14:01:47

or maybe you have something in your ~/.lein/profiles.clj ?

dpsutton14:01:51

did you follow the clojure for the brave and true setup?

dpsutton14:01:20

^ what alex said. brave and true uses and extremely outdated version of cider that requires the middleware in the lein profiles file

Kari Marttila14:01:11

No. Just tried to upgrade my Clojure project from version 1.8 to 1.9. I have been using Clojure for about a year now (not total newbie anymore).

Kari Marttila14:01:16

lein deps :tree | grep -i cider [cider/cider-nrepl "0.14.0"]

dpsutton14:01:42

The double colon keyword prefix only works with namespace aliases that are set
up. In this case there is not a namespace alias `clojure.test`, so these
keywords are invalid.
a commit fixed this

Kari Marttila14:01:48

This is pretty weird. I even tried this in another LInux machine - same thing.

dpsutton14:01:01

how did that dep for nrepl get there

Alex Miller (Clojure team)14:01:46

lein deps :why cider/cider-nrepl

dpsutton14:01:23

oh. didn't know about :why. thanks alex

Alex Miller (Clojure team)14:01:59

lein help deps for other tricks

dpsutton14:01:18

this was fixed on august 24 of last year. you just need to upgrade cider

dpsutton14:01:28

0.16 is current, 0.17-snapshot is "bleeding edge"

dpsutton14:01:08

-  (let [frame (->> (concat (::clojure.test/once-fixtures (meta ns))
-                           (::clojure.test/each-fixtures (meta ns)))
+  (let [frame (->> (concat (:clojure.test/once-fixtures (meta ns))
+                           (:clojure.test/each-fixtures (meta ns)))

dpsutton14:01:26

@kari.marttila did you upgrade (or remove) that cider-nrepl dep? that's only necessary if you are using CIDER, and CIDER will inject that on its own so you should never need to set it. also possible somone in your dependency chain was a little careless

Kari Marttila14:01:51

I tried to add :plugins [[cider/cider-nrepl "0.17.0-SNAPSHOT"]] => didn't work either.

Kari Marttila14:01:13

Maybe I just have to continue using Clojure 1.8.0 😢

dpsutton14:01:20

lein deps :why cider/cider-nrepl

dpsutton14:01:28

nonsense! we'll get this fixed

dpsutton14:01:48

you shouldn't need to specify any CIDER dependency and we need to figure out why there's an old version laying around

dpsutton14:01:11

@alexmiller put that in a thread but it should solve your woes. it'll tell us who our culprit is

Kari Marttila14:01:21

lein deps :why cider/cider-nrepl [cider/cider-nrepl 0.14.0]

dpsutton14:01:37

is that specified in the project.clj?

Kari Marttila14:01:26

grep -i cider project.clj => nothing.

dpsutton14:01:46

can you post the project.clj file here?

Kari Marttila14:01:48

I.e. I created a new project.clj just using "lein new app myapp" earlier.

dpsutton14:01:32

or can you cat ~/.lein/profiles.clj? (whoops with an s)

Kari Marttila14:01:33

(defproject myapp "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.9.0"]] :main ^:skip-aot myapp.core :target-path "target/%s" :profiles {:uberjar {:aot :all}})

Kari Marttila14:01:02

That's it. Thanks. My bad. grep -i cider ~/.lein/profiles.clj [cider/cider-nrepl "0.14.0"]

dpsutton14:01:09

well there you go

Kari Marttila14:01:12

Damn, I'm in shame. 🙂

dpsutton14:01:29

no shame. rubber duck debugging is valid

Kari Marttila14:01:29

A rookie error, and now it went public. 🙂

dpsutton14:01:49

it'll be erased in 10,000 messages. about four days 🙂

Kari Marttila14:01:57

I'll commit seppuku right after I fix this. 🙂

Kari Marttila14:01:32

Just joking. But I must say that I'm really gratefull for your help.

dpsutton14:01:34

and unless you are using cider-connect rather than cider-jack-in, there shouldn't be a need to specify CIDER's middleware

dpsutton14:01:40

of course. happy to help

Kari Marttila14:01:50

Yep. I must have added that when I started to learn Clojure, was experimenting with Emacs cider etc. Nowadays using IntelliJ IDEA + Cursive, and I must say that I'm really content with IDEA+Cursive.

dpsutton14:01:54

most everyone on the team i'm on use it. they are super happy with it.

dpsutton14:01:37

and colin the author participates on cider issues as well. really great person and great product

Kari Marttila14:01:11

And I also must say that I'm pretty happy with Clojure. Just implemented a micro service processing some Big data. Super cool to work with small S-expressions on a time, and Clojure is really cool to work with big data.

Kari Marttila14:01:05

I must clean my ~/.lein/profiles.clj at the same time. Probably clean everything now and add later the parts I really need now.

Kari Marttila14:01:50

I have also trained a junior to use Clojure at our corporation (continued development of that micro service). Hopefully Clojure thrives - a great language.

vijaykiran15:01:57

@kari.marttila you might want to post it on #news-and-articles 🙂

Kari Marttila18:01:56

@U051H0N54 Thanks for suggesting that. But I'm not a Clojure-guru, still learning. If #news-and-articles is the right place for that kind of blog articles, why not. 🙂

lilactown16:01:40

my team of 8 has gone full clojure over the last two weeks 😬

lilactown16:01:54

the only person with previous Clojure experience is me. hold my beer!

lilactown16:01:08

(it’s been really fun and I think everyone is enjoying it)

pny16:01:08

Guys, what's clojure way to deal with WARNING: update already refers to: #'clojure.core/update in namespace: and so on. To have more imagination 😅?

clojuregeek16:01:10

You should namespace your function update since clojure core already has one

pny16:01:34

It's in my namespace

bronsa16:01:39

@pny add (:refer-clojure :exclude [update]) to the ns that redefines update

bronsa16:01:53

if it’s not your own namespace, you’re out of luck, make a PR :)

pny16:01:44

No problems with that atm, but i thinks that's not good. Thought may be there are some best practices

bronsa16:01:26

it’s just a warning

lilactown17:01:04

does anyone have strong recommendations for a web framework out there?

lilactown17:01:18

I’ve looked at macchiato, luminus, and now peaking at duct and arachne

lilactown17:01:01

the slight hitch is that we really want to server-render reagent components. so we either need to do everything cljs (e.g. macchiato), farm out the server-rendering to 2nd service, or re-implement reagent/react’s html rendering in clj

lilactown17:01:31

but aside from that, which way would ya’ll point a team building a fairly large site?

clojuregeek17:01:02

Arachne is still in alpha 🙂 Luminus is a collection of recommended libraries by the author of Luminus

clojuregeek17:01:35

I have used Compojure for routing with good success with ring, recently I've been experimenting with Pedestal which is not exactly a framework but can be used to create a backend http://pedestal.io/

lilactown17:01:46

:thinking_face: I’ve played with pedestal as well as ring. we are making a more “page model” app so I think that ring kind of matches our goals more. but I guess we can use any ring middleware with pedestal…

lilactown17:01:44

I do like the interceptor model

clojuregeek17:01:43

Me too and I have plans to try it more, here's using ring middle ware with pedestal - https://github.com/pedestal/samples/tree/master/ring-middleware

Charles Fourdrignier18:01:51

I search a way to chain actions (like ->) but with "exception management", like Either (https://github.com/sanctuary-js/sanctuary#either-type).

Charles Fourdrignier18:01:08

What's the idomatic solution for that in Clojure ?

noisesmith18:01:17

if short circuiting on nil is good enough, some-> and some->> are great

noisesmith18:01:37

if you need actual exception handling, you could use them as a basis and put each step in a try/catch maybe?

noisesmith18:01:18

also the cats lib has an actual Either for clojure if you really want that

noisesmith18:01:31

opinions on cats diverge - some think it’s great, others think it’s a waste of time

Charles Fourdrignier18:01:42

some-> is cool, but I would like to return a value. Think to validation chaining, stopping on first error.

noisesmith19:01:29

sounds like you do want cats either then

Charles Fourdrignier19:01:10

cats looks like exactly what I want. Thank you !

Sabbatical201719:01:00

I would like to gain experience in ClojureScript by implementing a single-page web app with it. The purpose of this comment is to gather suggestions on what JavaScript and/or ClojureScript libraries or frameworks I should consider using for it. The app is an experimental interface to certain kinds of data manipulation. The concept involves manipulating a graph where the vertices are little circles (or roundrects). When I click on a circle I would like a little window to pop up into which I can type formulas etc. Additionally, the software would automatically draw various lines between the circles. I would also like to be able to drag and drop the circles from one line to another or to reposition elements, etc. I am very vague about the details in part because I expect them to evolve as I play with prototypes. Some screenshots of something that looks along the lines of what I am thinking are in https://bergie.iki.fi/blog/noflo-jekyll/. I think that I could use Quil to do much of this (since you can draw lines and circles with it), but I am hoping that there might be higher-level libraries that already have components adapted to this domain.

justinlee19:01:43

@sabbatical2017 Two questions: (1) What is your current level of expertise writing webpages in any technology. (2) Do you anticipate a lot of server interaction or is most of what your doing going to be client side?

Sabbatical201719:01:23

(1) I have almost no experience with writing web pages. (2) Mostly client side. Thank you!

justinlee20:01:06

I was a c++ programmer who left programming for a while and then came back and learned javascript. My advice: the big frameworks like re-frame and om will make things harder for you, not easier. They are designed to solve the problem of huge apps with multiple developers and introduce a lot of indirection. Because you are like me and don’t have all the experience with html, css, dom manipulation, and basic MVC concepts like how to manipulate state, my actual pedagogical recommendation is to get a few core things (like forms and maybe drag-and-drop) working with a simple react wrapper like reagent or rum.

justinlee20:01:56

Whether there are existing widgets you can incorporate, I’m not sure, because I’m not quite sure what you are trying to accomplish. But first you have to learn how to manage state, how to use react, how forms work, how css works, get a dev environment set up, etc.

shaun-mahood20:01:43

I'm going to give the opposite advice - re-frame in particular took away a lot of those concerns for me when I first learned Clojure, and it has fantastic docs and a really solid frame for you to build something around. You barely have to understand react or reagent to get something going, and it gives you a lot of the tools you need to manage state nicely. There are also some very good videos and tutorials that you can follow to fill in the gaps for you and then fill those in as necessary.

shaun-mahood20:01:23

That being said, to purely learn things about ClojureScript you've picked a pretty hard domain - so I would see if you can find similar examples already built in ClojureScript and start with the libraries they were built with. You could also start with the data model that defines what you want to do and then build the graphical parts off of that data.

mox60121:01:02

from the link you provided as an example (NoFlo), you might find interesting http://www.reactive-streams.org and http://funcool.github.io/beicon/latest/ to stay in topic

Sabbatical201723:01:53

Thank you very much for the advice! I will review all this and see if I can make any of it work with JointJS 😄