Fork me on GitHub
#clojure
<
2018-04-17
>
hiredman00:04:57

the tooling figwheel depends on (clojure.tools.namepsace, I think) has decided you have a circular dependency in your namespaces, which clojure doesn't allow either, but clojure isn't as good at detecting it

alice00:04:51

So I'm requiring something circularly I guess?

hiredman00:04:14

yes a -> a, or a-> b -> a or a-> b -> ... -> a

alice00:04:22

I haven't noticed it in my :requires, can you help me find it from the files in question? it's just 3 files

alice00:04:36

repl

(ns voke.repl
  (:use voke.handler
        figwheel-sidecar.repl-api
        ring.server.standalone
        [ring.middleware file-info file]))

alice00:04:48

(ns voke.middleware
  (:require [ring.middleware.defaults :refer [site-defaults wrap-defaults api-defaults]]
            [prone.middleware :refer [wrap-exceptions]]
            [ring.middleware.params :refer [wrap-params]]
            [ring.middleware.reload :refer [wrap-reload]]
            [ring.middleware.json :refer [wrap-json-body wrap-json-response wrap-json-params]]
            [ring.middleware.keyword-params :refer [wrap-keyword-params]]
            [clojure.string :as string]
            [clojure.pprint :as pprint]))
middleware

alice00:04:06

handler

(ns voke.handler
  (:require [compojure.core :refer [GET defroutes routes POST context]]
            [ring.util.response :refer [response]]
            [compojure.route :refer [not-found resources]]
            [hiccup.page :refer [include-js include-css html5]]
            [voke.middleware :refer [wrap-api wrap-site]]
            [config.core :refer [env]]
            [voke.api.v1.utils :refer [defresponse]]))

hiredman00:04:55

oh, it isn't figwheel, it is wrap-reload

hiredman00:04:59

what is on (handler.clj:63:15)

alice00:04:20

(-> #'site ;; line 63 below (wrap-site))

alice00:04:35

It's where my routes are declared

alice00:04:40

(def app (routes (-> #'site (wrap-site)) (-> #'api (wrap-api))))

hiredman00:04:05

ah, ring reload doesn't use tools.namespace of course, but uses ns-tracker

alice00:04:32

what's that mean for me?

hiredman00:04:31

dunno, I haven't used ns-tracker so I have less of an idea what is going on

hiredman00:04:48

what are you doing where you see that exception happen?

alice00:04:48

well shit

alice00:04:03

It happens when I try to (start-server)

hiredman00:04:15

have you restarted your repl?

alice00:04:52

Many times

alice00:04:54

and my editor

hiredman00:04:08

it looks like it scans the entire src/ directory by default, so if you have any other files in there, even unused, they could trigger this

tsc03:04:37

is this a known bug in clojure 1.9.0? it seems if :clojure.spec.alpha/invalid is within the body of certain clojure macros, everything blows up... for example, using clojure.test/is:

(is (= ::s/invalid (s/conform string? "1")))
=>
 Call to clojure.core/let did not conform to spec: In: [0 3] val:
  :clojure.spec.alpha/invalid fails spec: :clojure.core.specs.alpha/bindings
  at: [:args :bindings :init-expr] predicate: any?
when placed within a fn:
(let [conformed? #(not= ::s/invalid? %)]
 (is (conformeded? (s/conform string? "1"))))
=> false

emccue04:04:54

any refactor tips?

emccue04:04:37

This macro got out of hand quick

emccue04:04:00

the idea was to take some java pojo and call (pull-keys obj [:id [:name :getName]]) and produce the map {:id (.id obj) :name (.getName obj)}

emccue04:04:19

when I started to add logic for doing this recursively I ended up with that letfn

emccue04:04:37

and there still isnt logic for nested renaming

emccue04:04:48

then I had to deal with some vavr Options so I figured I could provide a function to be called for everything extracted

emccue04:04:19

that worked pretty well, but I definitely feel like im committing design sin

Alex Miller (Clojure team)04:04:15

have you looked at bean?

Alex Miller (Clojure team)04:04:24

it does something similar to this

emccue04:04:15

yeah, unfortunately it doesnt seem to work with my objects

emccue04:04:19

Im consuming classes produced from https://immutables.github.io/

emccue04:04:47

So im not quite sure why not

emccue04:04:01

but I also have the good fortune to not fully comprehend what a bean is

Alex Miller (Clojure team)04:04:40

looks like that lib can produce different code styles - stuff like name() is not the “standard java bean” style and won’t be picked up by bean, but the getName() style should be

Alex Miller (Clojure team)04:04:01

not sure if you can ensure you’re using that style

emccue04:04:44

I could I suppose but Im kinda torn

emccue04:04:24

I have 2 client libs I wrote for two of the the apis we talk to

emccue04:04:47

And my team writes in java primarily

emccue04:04:20

so .name() and the immutables library make working with that data on the java side fairly pleasant

emccue04:04:02

but at the same time, when I get the opportunity to work on something by myself, its hard to use clojure because I have to undo that strict typing to get idiomatic maps

emccue04:04:36

not to mention stuff like Option and Try which are in there, which make for some clunky code on the clojure end

emccue04:04:13

I almost want to make a .untyped() endpoint just for me and use cheshire or something

Alex Miller (Clojure team)04:04:21

well, not trying to talk you out of it :)

Alex Miller (Clojure team)04:04:34

it’s fun to get stuff like this working too

emccue04:04:02

Its kinda ironic really

emccue04:04:17

the more functional the java code, the harder it is to work with in clojure

benzap04:04:01

I wonder if there's a way to tie the immutables library into the clojure protocols to make it play nicer

benzap04:04:13

or would it even be worth it? It's been a while since i've done java interop stuff, let alone tying into clojure's core protocls

Alex Miller (Clojure team)04:04:37

immutables seems like a generator, seems like you could generate the Clojure implementation of the interface and that would be ideal

Alex Miller (Clojure team)04:04:09

a defrecord that implemented the interface and also exposed data as keyword accessors for example

emccue05:04:32

That seems like an interesting road to go down

emccue05:04:30

My instinct would be to add some code that just straight up converts the immutable into a clojure map

emccue05:04:19

unfortunately that would mean writing a good amount of java code in an area of java I dont really understand

emccue05:04:00

generating the clojure code is also an option, but I would probably end up writing a completely separate code generator that just reads the annotations

emccue05:04:05

Not sure which would make the least hacky code

emccue05:04:18

with me behind the wheel that is

mourjo09:04:17

Hi, I was looking for a thread-safe version of with-redefs, it seems to be working for me in a toy example when I use with-local-vars, are there any caveats here? Original

(defn ten [] 10)
(def x (doall (pmap (fn [_] (with-redefs [ten (constantly nil)]
                              (ten))) (range 20 100))))
(ten) ;; gives nil
With local vars:
(defn ten [] 10)
(def x (doall
        (pmap
         (fn [_] (with-local-vars [ten (constantly nil)]
                   (ten)))
         (range 20 100))))
(ten) ;; returns 10

mourjo09:04:15

This^ won’t work for fully qualified vars. 😞

hmaurer10:04:39

Hi! What is the best way in Clojure to “transform a deep data structure from leaf to root”? e.g. apply some function to the leaves, then one level up, and so on

hmaurer10:04:25

ah nevermind, I think that’s exactly what clojure.walk/postorder does

pesterhazy10:04:04

@hmaurer isn't that what postwalk does? (clojure.walk/postwalk-demo {1 {2 {3 4} 5 6} 7 8})

fmnoise14:04:06

does anybody know what's happened with http://planet.clojure.in and their fb group?

fmnoise14:04:24

no activity for more than a week

lmergen14:04:05

domain expired

lmergen14:04:18

original owner doesn't respond

lmergen14:04:34

and "they" are planning to relaunch the site on a different domain

4
lmergen14:04:43

at least, that's what i heard

schmee17:04:38

GraalVM has been officially released! 🎉 http://www.graalvm.org/

32
schmee17:04:05

I’m going to try to run some Clojure on it, if anyone else tries it out please share your results 🙂

elarouss17:04:45

Hi, i have a map like this {:type :type1 :children [{:type :type2 :children [..] ..]}, and i want to write a spec for it . there is 4 types and an item with a certain type can only exists inside a specific type too (like :country :city :street ), how do you suggest i can achieve that ?

lispyclouds17:04:04

@schmee Are you gonna be writing a Clojure frontend for it?

schmee17:04:46

I’m going to try 🙂

schmee17:04:42

as a smart person once said: “don’t try anything, just do it”!

lispyclouds17:04:39

awesome 😄 I tried a simple frontend with Graal sometime back, found this: http://epub.jku.at/obvulihs/content/structure/501665

lispyclouds17:04:55

but didn’t see any source code for it anywhere

lispyclouds17:04:21

If you’re giving it a shot then I’m up for it too 😄 Had been following Graal for sometime

sveri17:04:23

> Are you working on a Java application? Do you want a faster runtime? Enhance your code with JavaScript! Either this is bad wording or I want some proves. Since when does javascript speed up Java applications?

tbaldridge17:04:37

@sveri lol what's that from?

sveri17:04:04

@tbaldridge from the graalvm intro page: http://www.graalvm.org/ Under "Get Started"

sveri17:04:48

I assume they speak of the native image capability, but how that relates to javascript, it still doesnt make sense 😄

bronsa17:04:46

>since when does javascript speed up Java applications? since graal can optimize js code faster than javac+hotspot can optimzie java code :)

sveri17:04:07

I just wanted to give it a try, but no open source prebuilt binary is available for windows. A pity. Maybe someone else wants to do some comparisons.

schmee17:04:01

I’m curious about the “Enterprise edition”, seems to boast “Improved performance and smaller footprint”

schmee17:04:17

wonder how big the difference is

dominicm17:04:41

Would a truffle clojure be faster in startup?

schmee17:04:45

with regular Graal it would be even slower

schmee17:04:01

but if it could be made to run on SubstrateVM somehow, it would be almost instant

schmee17:04:25

I’m not sure if that is technically possible since SVM has a lot of restrictions around reflection and dynamic class loading

tbaldridge17:04:00

Yeah you wouldn't want to build a Clojure/JVM on SubstrateVM. You'd want a "clojure native" on SVM. Something with good C interop, and all the good/bad that comes with that

schmee17:04:01

you could build a Java bytecode interpreter in Truffle and use that for interop like they’ve already done with LLVM bytecode

schmee17:04:12

I think that is already on the roadmap

tbaldridge17:04:16

That's also possible. Someone did that with PyPy, they wrote a Prolog interpreter in RPython and then integrated it into a PyPy build. So you could have Python and Prolog talking to eachother, but each with their own VM semantics.

tbaldridge17:04:32

PyPy does that as well with regexs (they have their own JIT/runtime)

schmee18:04:18

cool, in fact a regex JIT just landed in Graal as well 🙂

schmee18:04:53

this whole new generation of JITs is incredibly exciting 😄

ajs18:04:56

^long , ^Long and (long ...) which is preferred?

schmee18:04:53

use (long ...) for local variables and ^long for function arguments

ajs12:04:49

@alexmiller I believe the reason for my confusion about liberal use of placement for type hints (other than fn arg lists) is this from the book "Programming Clojure" :

Clojure supports adding type hints to function parameters, let bindings, variable names, and expressions. 
So this suggested that using it for locals (as suggested yesterday to avoid) was reasonable in tight loops. Also the word "expressions" seems rather vague, which suggests you could use them everywhere.

ajs18:04:04

what about for bindings for loop

schmee18:04:01

those are local variables 🙂

ajs18:04:45

so something like this makes no sense (loop [^long somelocal foo] ... ) and should be (loop [somelocal (long foo)] does the type hint persist on different iterations of the loop? perhaps type hints have no meaning outside the context of a function arg?

Alex Miller (Clojure team)18:04:34

the compiler detects primitive long locals and tries to retain them in a loop

ajs18:04:21

Do type hints work inside a destructured form in a function arg?

Desmond18:04:36

since functions are data in clojure, can i send a function in a network request? does anyone have an example?

Alex Miller (Clojure team)18:04:50

unless you send it as code then eval it on the other side

chrisbetz19:04:47

@drawls sending code over the wire raises a lot of security questions and you should think twice before doing that. Or three, four times maybe.

huthayfa19:04:34

👋

4
👋 12
Garrett Hopper19:04:43

Is there a better way to interactively redefine proxy functions from a repl than this?

(defn make-proxy []
  (proxy [Parent] []
    (function1 [])
    (function2 [])))
(defonce p (make-proxy))
(update-proxy p (proxy-mappings (make-proxy)))

Garrett Hopper19:04:07

The only alternative I can think of is to make each proxy function call out to an actual clojure function of the same name. Then I can easily redefine that clojure function at runtime. That doesn't feel very clean though.

schmee19:04:43

have you tried https://github.com/clojure/tools.namespace? I’m not sure if that refreshes proxy bindings, but it handles most other things so I assume it will

Garrett Hopper19:04:26

Huh, I didn't think about that. It's been a while since I've used it. I've always been more in favor of manually evaluating things from Emacs. It's worth a shot though.

ajs12:04:49

@alexmiller I believe the reason for my confusion about liberal use of placement for type hints (other than fn arg lists) is this from the book "Programming Clojure" :

Clojure supports adding type hints to function parameters, let bindings, variable names, and expressions. 
So this suggested that using it for locals (as suggested yesterday to avoid) was reasonable in tight loops. Also the word "expressions" seems rather vague, which suggests you could use them everywhere.