Fork me on GitHub
#clojure
<
2017-01-15
>
rymndhng00:01:39

For danielsz/system users: Wondering if anyone know why (fn [req] (handler req)) wraps the handler in line: https://github.com/danielsz/system/blob/master/src/system/components/jetty.clj#L13 I'm wondering why not pass the handler directly to run-jetty

underplank02:01:17

Has anybody got an experience in building nginx-clojure

qqq03:01:06

i'm not happy with spec using qualified keywords and defreord using unqualified keywords; is there a way to tell defrecord ot use qualified keywords as selectors ?

underplank03:01:33

Does "java.lang.NoClassDefFoundError: clojure/lang/RT” usually mean I dont have the clojure.jar in my classpath?

raspasov03:01:19

@underplank I’ve seen a similar error happen when I “lein uberjar” package the project while I have “lein repl" running but never fully investigated - not sure if that’s your case though

qqq05:01:05

who's in the mood for a dumb bug in using spec? here is my entire afternoon in trying to learn how to use spec: (s/def ::foo some-func) (defn some-func [x] (assert ...) (assert ..>) (assert ...)) now, guess what? assert returns nil on success? so what's happening? I'm running this x, it's failing the spec, then I manulaly through the assertions -- each works -- but the spec is still failing? --- wtf --- repeat for entier afternoon , before realizing the some-func needs to return boolean and assert always returns nil face-palm

sophiago05:01:43

it's been a while since i've used core.async and i'm trying to figure out how to go about mapping a function to multiple channels. i'm not sure if map or tap will accomplish what i need: i have a function that takes a coll and returns a new coll and want to have it fan out separately onto multiple channels with each passing it an incremented index. so pmap or a concurrent for except returning separate instances when the channels close (so i can store them in a hash-map as well as feed the new colls back into the function. any pointers on what i should use for this?

underplank07:01:12

Hmm. I’m trying to build an uberjar that will run a standalone jetty server. I have my main hooked up in my leiningen profile but everytime I do lein uberjar it tries to execute the main function as well, which starts the Jetty server and fails the uberjar build.

qqq07:01:40

Is the problem "if I remove the main function, then I can't run/test my code locally" ?

qqq07:01:09

I'm using uberwar, not uberjar, and my solution is: 1) no main, 2) fire up repl, 3) manually call whatever jetty/ring would ahve called; then develop

underplank07:01:28

No its not that. Its more I want to run the uberjar in a container to test some stuff. and it seems easier to run it as a standalone executable uberjar.

underplank07:01:05

Oh nvm. looks like its working now.

qqq08:01:41

(clojure.tools.namespace.repl/refresh) appears to loading up imaginary namespaces

qqq08:01:53

they're names that I once had checekd into git, but certainly do not exist in current src directory

qqq08:01:07

(defrecord foo [foo]) ^^ is this code that works in clojure but not cljs? if so, why? [this is what appears my bug to be]

sophiago08:01:18

@qqq try something like (defrecord Foo [bar])

qqq08:01:03

I'm now curious why this code appears to behave differently in clj vs cljs and whether it's intentional.

sophiago08:01:50

i'm more surprised it's working in clj

sophiago08:01:05

it's a circular definition. also class names should begin with a capital...i've never used a record in any other way so am not sure what that even does. seems you would just use deftype instead

beppu08:01:29

agreed on the naming

beppu08:01:05

(I don't see how it's circular though.)

sophiago08:01:16

i'm far from certain on any of this, but i'd guess it's not really working in clj as intended

sophiago08:01:52

i may be confused about it being circular (it's quite late here). just that the argument name is the same as the class name...

beppu08:01:16

My guess on the cljs side is that the generated javascript has some kind of naming conflict that doesn't happen on the jvm side.

qqq08:01:02

I'm not claiming that

(defrecord foo [foo]) 
is a good idea; I'm hoping someone who actually understands the compiler internals here can explain what's going on.

sophiago08:01:02

i've never used records in cljs, so can't say

sophiago08:01:42

@qqq well, there's one way to know for sure 🙂

beppu08:01:09

(defrecord foo [foo])
ReferenceError: self__ is not defined
    at repl:27:1
    at repl:193:3
    at repl:201:3
    at repl:206:4
    at ContextifyScript.Script.runInThisContext (vm.js:25:33)
    at Object.exports.runInThisContext (vm.js:77:17)
    at Domain.<anonymous> ([stdin]:41:34)
    at Domain.run (domain.js:221:14)
    at Socket.<anonymous> ([stdin]:40:25)
    at emitOne (events.js:96:13)

qqq08:01:09

@beppu: yes, I managed to get that error too

qqq08:01:14

I have no idea what it means.

qqq08:01:37

In fact, it confused me for a good 5 minutes before I realized I had a line that said (defrecord bidi-table [bidi-table])

qqq08:01:43

which led to the (defrecord foo [foo]) question 🙂

beppu08:01:01

I think it's a cljs bug.

qqq08:01:31

Should we move this to #clojurescript so someone there can file a bug?

qqq08:01:53

@sophiago: how is that related? that is someone talking about reify and protocol

sophiago08:01:37

the cljs compiler is mostly protocols. that error is about the spread operator, but it's likely the same issue occurring with protocol dispatch

qqq08:01:00

Are you a CLJS dev or just randomly guessing

qqq08:01:58

@sophiago , @beppu: I've re-posted this over a #clojurescript -- thanks for attempts at helping 🙂

sophiago08:01:31

np. i ask for help enough on here i figured i'd try. if it were me i'd first see if it replicates when you properly capitalize the class name and then check the cljs source on github. it's all written in clojure with extensive comments so quite accessible

tianshu09:01:21

Meet a problem when deploying with jenkins, leiningen plugin.

installs/leiningen-2.7.1-standalone.jar -Dfile.encoding=UTF-8 -Dmaven.wagon.http.ssl.easy=false -Dleiningen.original.pwd=/var/lib/jenkins/workspace/caiba-data -cp /root/.lein/self-installs/leiningen-2.7.1-standalone.jar clojure.main -m leiningen.core.main run
Error: Could not find or load main class clojure.main
Build step 'Build project using leiningen' marked build as failure
However if I cd into that directory, run lein run, everything works fine.

gcommer09:01:19

are you running as root when you manually lein run by chance?

gcommer09:01:31

cause /root/.lein/self-installs/leiningen-2.7.1-standalone.jar looks sketchy

tianshu09:01:54

yes, but my dev machine only has one root user for now.

gcommer09:01:51

is jenkins running as root?

tianshu09:01:18

Er.. no, my FOOLISH, jenkins will run as user jenkins... sorry for my question.

schmee11:01:18

how do you invoke a list of functions?

schmee11:01:27

right now I’m doing (map #(%) fns) but that feels a bit cryptic

andrea.crotti11:01:41

suppose I want to create a map like (silly example)

{1: 1, 2: 2}
one way is to do something like
(into {} (for [x (range 2)] {x: x})))

andrea.crotti11:01:51

is there an easier way to do that though?

schmee11:01:39

(zipmap (range 3) (range))

schmee11:01:51

andrea.crotti ^

andrea.crotti11:01:00

ah great thanks

andrea.crotti11:01:34

definitively better

nblumoe17:01:03

@tbaldridge I am doing a spike with fn-fx now. when running the app from an uberjar, the app closes immediately after rendering the UI. It works flawlessly from the REPL though. Something might be off with the JavaFX lifecycle management when running from a jar. Are you aware of anything I would need to take care of to make it work from an uberjar?

nblumoe18:01:54

figured it out, one needs to extend the superclass javafx.application.Application from :gen-class

nblumoe18:01:57

(ns fn-fx-ui.core
  (:require
   [fn-fx.fx-dom :as fx-dom]
   [fn-fx.controls :as controls]
   [fn-fx.diff :refer [component defui render should-update?]])
  (:import (javafx.application Application))
  (:gen-class :extends javafx.application.Application))

tbaldridge18:01:39

@nblumoe yeah, I imagine that's because everything runs on background threads, and they're probably all set to close down once the main thread exits.

nblumoe18:01:53

Yep. But now not all threads get stopped when I close the (last) window. Like described here: https://github.com/friemen/async-ui#standalone

nblumoe19:01:51

@tbaldridge I am trying to figure out how to invoke a dialog (FileChooser) from fn-fx. Did you think about those in the lib design? Should that be done via the diff-mechanisms?

genec21:01:29

@schmee That's cool, but why does the second (range) work? I would have written (zipmap (range 3) (range 3))

joshjones21:01:44

the second argument is only realized as many times as the first argument. So, while (range) is an infinite lazy sequence, only 3 elements are realized since (range 3) realizes 3 elements

joshjones21:01:20

the way it's written, you can change one value (the "3"), instead of having to change two values as you would have written @genec

genec21:01:45

@joshjones So, zipmap is calling the second range 3 times (lazily) because of the first (range 3) call. Thanks, that's cool.

joshjones21:01:04

also I noticed earlier when I read this that you wrote {1: 1 ...} be careful and don't confuse maps with javascript objects .. there is no 1: ... there is :1 which is a keyword though

genec21:01:50

@joshjones How would you write it to have the keys be :1, :2, :3 ...?

joshjones21:01:35

one way would be:

(zipmap (map (comp keyword str) (range 3)) (range))

joshjones21:01:37

if you want to actually start it at 1 instead of 0, fyi:

joshjones21:01:40

(zipmap (map (comp keyword str) (range 1 4)) (drop 1 (range)))

genec21:01:49

@joshjones Thanks, that's excellent. Very helpful.

qqq21:01:43

unless I'm using protocols / polymorphism; is there ever a reason to use records over maps? I thought records would provide some additional abstraciton; but in practice, it's just been a mess of extra layers of abstraction

schmee22:01:00

qqq records have better performance since they are implemented as Java classes

schmee22:01:17

but unless you have measured that regular map performance is your bottleneck I’d stick to maps

tbaldridge22:01:42

And even when you need polymorphism, you still have multimethods

qqq23:01:12

so if the main advantage of records is java interop, and I'm doing cljs, is there no reason to use records?

grounded_sage23:01:12

What is the best way get a section of a string and move it. I want to get this media query and all future media queries. Then place them at the end of the string in the order they're are supposed to be in.

.Sm{flex-wrap:wrap}@media(min-width:30rem){.Sg{flex-direction:row}.Si{padding-right:0}.Sh{padding-left:0}}.Sk{width:2em}.Se{padding-left:1.5em}.Sj{margin-right:3em}.Sb{display:flex}.Sc{flex-direction:column}.Sl{flex-direction:row}.Sd{align-items:baseline}.Sf{padding-right:1.5em}