Fork me on GitHub
#clojure
<
2016-08-25
>
escherize00:08:33

Hey guys, how's core.unify coming along? http://take.ms/UvqPi

eraserhd00:08:04

I've used it a few times successfully. Is there a problem?

hiredman00:08:22

I think it is largely abandoned. There was some discussion about removing it because of course core.logic also does unification. Some chimed in about a standalone unifier still being valuable. But I don't think anyone else has stepped up to take care of it

hiredman00:08:17

(discussion was on one of the mailing lists in the last year)

richiardiandrea02:08:49

so I have this weird error when I run tests (everything fine in the repl):

FAIL in () (NO_SOURCE_FILE:209)
expected: (= :events/bad-event (:events/type (events/ws-msg->bad-event ws-msg msg-or-ex-info)) "We can correctly create :events/bad-event events")
  actual: (not (= :events/bad-event :events/bad-event "We can correctly create :events/bad-event events"))
false

richiardiandrea02:08:30

either I am missing some keyword equality fundamentals here or there is something off

richiardiandrea02:08:05

the test is: (is (= ::events/bad-event (::events/type (events/ws-msg->bad-event ws-msg msg-or-ex-info)) "We can correctly create :booma.events/bad-event events"))

joshmiller02:08:24

@richiardiandrea I think you just have your message inside one too many )s

joshmiller02:08:52

I.e., it should be (is (= ::events/bad-event (::events/type (events/ws-msg->bad-event ws-msg msg-or-ex-info))) "We can correctly create :booma.events/bad-event events”)

richiardiandrea02:08:37

oh rrrrrright lol

richiardiandrea02:08:32

I still double and triple check before posting here about these kind of errors ... but well, what can you do 😄 thanks @joshmiller

richiardiandrea02:08:40

I should write a spec for that

hiredman02:08:15

Eastwood has some linters for common test errors

hiredman02:08:11

Another common one is '(is a b)' instead of '(is (= a b))'

yogidevbear08:08:49

Can anyone recommend a good tutorial or video on concurrent (DB) execution? I'm looking at doing a POC for work to get some info from a DB (MS SQL Server) and then fire off a few concurrent queries to retrieve related information.

hiredman08:08:51

the simplest thing would be to execute your queries inside futures, futures begin executing immediately on another thread, and you can get the result of executing the future by using deref, derefing a future will block if the future hasn't completed executing yet. you'll also need to make sure the driver (presumably some jdbc driver) can execute concurrent queries on a single connection, or else you will need to create a new connection for each future

mccraigmccraig08:08:55

@yogidevbear if your db driver has an asynchronous option then concurrent queries are straightforward, otherwise futures ... once you have responses in futures ztellman/manifold has a bunch of useful stuff for composing operations (i.e. when those concurrent queries require further concurrent queries)

yogidevbear09:08:51

Thanks guys, I'll take a look at your suggestions 🙂

mccraigmccraig09:08:10

in a similar vein @yogidevbear promesa is worth a look, and cats' alet macro http://funcool.github.io/cats/latest/#alet is a thing of beauty 🙂

dominicm10:08:44

I'm trying to update my nrepl client to use a single connection. I'm a little stuck though because if multiple threads access that connection, to ask for a new session, won't they each get the same session (and leave data on the connection too?) Any advice to handle this scenario?

dominicm11:08:34

Derp. Messages can hold a unique :id key, derp

pvinis13:08:14

using clojure, how can i make a status bar item on osx?

darwin13:08:03

@pvinis are you sure this is clojure-related question? If you are building a native osx app, then you are probably using some library to access Cocoa APIs from Clojure and via this library you should be able to talk to osx frameworks to create status menu items and anything osx-related.

pvinis13:08:50

i found out that awt can do that

pvinis13:08:15

but i looked, and couldnd fine the source, and some sites said its an old thing..

pvinis13:08:18

so im not sure

darwin13:08:35

I’m not a Java person, but if I was forced to write native osx apps in Clojure, I would try to use something more direct, some wrapper of OSX frameworks, not going through a general multi-platform Java library like AWT (my $0.02)

pvinis13:08:56

maybe i should in the end

pvinis13:08:11

and have the clojure part as a server running

pvinis13:08:21

and a wrapping native app

pvinis13:08:42

at least until react native macos is done 😄

darwin13:08:59

you could write the menu item app in swift and let it talk to your Clojure server (background process) via some protocol, e.g. json or better edn

pvinis13:08:50

probably what i will do

kevin14:08:55

@pvinis you might want to checkout BitBar: https://github.com/matryer/bitbar

pvinis14:08:33

ive seen that. i will see if i can use that

aaelony16:08:50

Hi! I'm reading this http://stackoverflow.com/questions/22716492/how-to-configure-leiningen-to-use-a-corporate-repository about how to configure leiningen to use a corporate repository, but it seems the password is right there in the :repositories value, is there any better way around this? perhaps in the ~/.lein/profile.clj ?

hans16:08:59

@aaelony: we use entries in our profiles.clj like this:

:user  {...
        :deploy-repositories [["snapshots" {:url ""
                                            :sign-releases false}]
                              ["releases" {:url ""
                                           :sign-releases false}]]
        :mirrors {#".+" {:name "Internal nexus"
                         :url ""
                         :repo-manager true}}}

aaelony16:08:26

@hans: thank-you, that looks much more sane

idiomancy16:08:29

Hello All! Just joined the slack, is this the right place to get some development support?

dpsutton17:08:48

yes this is the perl users group

idiomancy17:08:37

If so, I have an interop question.. I'm trying to make some libgdx game goodness, and I need to access the libgdx keys: https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Input.Keys.html I have libgdx core in my project deps: [com.badlogicgames.gdx/gdx "1.9.3"] but I'm not entirely sure how to use it. one answer I came across involved the following line, and I dont really understand the use of the $ in it: "com.badlogic.gdx.Input$Keys/toString"

idiomancy17:08:57

the perl users group. finally, I'm home

idiomancy17:08:16

cant wait to get all my questions about rampart answered, @dpsutton

idiomancy17:08:22

So, the tldr is, what the heck is the $ in "com.badlogic.gdx.Input$Keys/toString"

jcsims17:08:27

@idiomancy in my experience, it’s an inner class in Java

jcsims17:08:50

i.e. Keys is an inner class of Input

idiomancy17:08:55

that makes sense given the source. Keys being a kind of enum

idiomancy17:08:04

thanks, @jcsims I'll bash my head against this for a little bit to see if I can get this working.

jcsims17:08:16

what is it you’re trying to do?

idiomancy17:08:02

Essentially, I'm trying to manipulate the libgdx classes, but the Interop seems to be really complex, because its split into n packages and libraries.

idiomancy17:08:30

and the beginner level interop that I know is insufficient.

jcsims17:08:57

are you passing those static fields as args or something?

idiomancy17:08:08

But, ultimately, the specific thing Im trying to do boils down to (in Java) "if (Gdx.input.isKeyPressed(Keys.SPACE)) {doThing}"

idiomancy17:08:59

but, like, I'm not sure what imports I would have to make in order to get "(if (Gdx.Input/isKeyPressed Keys/SPACE))" to work

jcsims17:08:32

I can’t recall exactly - the static field access on a static class might be com.badlogic.gdx.Input$Keys/SPACE

jcsims17:08:48

oh - you can import a nested class if you’re just using that

jcsims17:08:53

the first couple sections here might be helpful: http://clojure.org/reference/java_interop

idiomancy17:08:53

hmm.. whats the import for that look like? that would probably be much easier

idiomancy17:08:25

hahaha, yeah, I need to stop trying to learn from raw viking programming and RTFM

idiomancy17:08:52

thanks, @jcsims, i will read up.

sarcilav17:08:14

it should be something like :

(:import (com.badlogic.gdx Input
                         Input$Keys))
within your ns declaration @idiomancy

idiomancy17:08:44

ahh, I had no idea you could put more than two forms in those lists

idiomancy17:08:11

I thought it was just (<package> <class>) pairs

sarcilav17:08:54

you’re welcome 🙂

idiomancy17:08:10

cool, yeah youre dead on, Cursive even autocompletes it

idiomancy17:08:09

@sarcilav oh.. weird.. do I have this usage correct?

(ns neofight.core
  (require [clojure.core.async :as async])
  (:import
    (com.badlogic.gdx ApplicationListener)
    (com.badlogic.gdx Input Input$Keys)
    (com.badlogic.gdx.backends.lwjgl LwjglApplication)))


(def INPUTS-LISTENTED-TO
  [Keys/SPACE])

;=> *out*

 CompilerException java.lang.RuntimeException: No such namespace: Keys, compiling:(C:/Users/Tyler/code/neofight/src/neofight/core.clj:13:1) 

jcsims17:08:48

I think you still have to refer to it as Input$Keys, but I may be wrong...

jcsims17:08:58

e.g. Input$Keys/SPACE

idiomancy17:08:08

oh! okay. Awesome. okay, you guys are the best, I swear I will read that whole java interop page before I ask another question

alexmiller19:08:21

you have (require …) instead of (:require …)

alexmiller19:08:40

and it is I think more common to use [ ] rather than ( ) in :import, although either is ok

kvlt19:08:21

Hi all. I have a large lazy list of datomic transactions that need to be run (~500k transactions). Evaluating these fn's is not very quick and I was hoping for some way to execute this using multiple threads. Has anyone done something like this before?

nickt19:08:50

hey y'all. I'm trying to learn about macros, and I'm wondering if there's a way to turn something like this:

(defmacro add
  [a b]
  `(+ ~a ~b))
into a macro which will inline the result of a + b instead of inlining the addition operation

nickt19:08:34

I just tried this:

(defmacro add
  [a b]
    `~(+ a b))

nickt19:08:41

but it doesn't seem like clojure liked that one

jr19:08:58

(defmacro add [a b] (+ a b))

quoll19:08:05

The point of the quote is to insert code into that place, rather than the results of running that code. If you want the result, then you don’t want to be quoting what led to that result

nickt19:08:05

ahhh cool

nickt19:08:18

awesome, thanks!

nickt19:08:17

is it possible to write a macro to inline a constant?

nickt19:08:54

(defmacro ident [x] x) hahaha

dpsutton19:08:04

that's an inline

dpsutton19:08:17

inline a call to identity

idiomancy20:08:28

@petr I have not, but I assume you are aware of core.async for multiprocessing?

nickt20:08:37

hey @dpsutton I tried that (defmacro ident [x] x) and it didn't quite do what I want

nickt20:08:22

I was hoping for something like this: (def cool-number 5) then (ident cool-number) would expand to 5

dpsutton20:08:48

have you tried (identity cool-number)

idiomancy20:08:11

I assume he just used identity as a trivial example

nickt20:08:34

I'm just trying to inline values

nickt20:08:41

which I guess is a form of identity

dpsutton20:08:55

oh sorry. I thought we were kidding around

dpsutton20:08:13

i'm not sure its possible

nickt20:08:31

even if the values are known constants?

dpsutton20:08:44

because if you do it at compile time, how could we know that cool-number just points at a literal

nickt20:08:05

aren't def declarations immutable?

nickt20:08:37

or constant

dpsutton20:08:00

(def cool-number (future (factorial 39))

jr20:08:14

(defmacro ident [x] (var-get (resolve x)))

jr20:08:45

why do you want such a thing?

nickt20:08:04

@jr hm that gave me a null pointer

nickt21:08:10

I'm asking about this for cljs actually... I want to inline constants via macros so that the js output from the cljs compiler can be statically analyzed more thoroughly

idiomancy21:08:19

is type hinting a thing in cljs, @nickt ?

nickt21:08:35

@idiomancy not sure, I'm pretty new to cljs

idiomancy21:08:14

Presumably that doesnt give you the level of control you need

idiomancy21:08:53

Man, you're blowing my mind right now. You want a macro that causes a value to expand to itself.

bfabry21:08:19

haha it's so confusing, it's like a weird puzzle

nickt21:08:46

I gotta run, but I'll check back in a bit. If you have any idea if/how to do this... I would so appreciate it

idiomancy21:08:03

would it be too much to ask for the specific example that is giving you trouble (not enough for static analysis)

idiomancy21:08:25

Im sure people here are way better with "how to do x" than "how to do x in this specific way"

idiomancy21:08:31

theyre workaround wizards here

dpsutton21:08:01

you could dig around in ztellman/ridley

dpsutton21:08:18

he does some setting of vars in the local environment, interacting with the compiler

nickt21:08:42

(def my-class
  (.createClass js/React #js
    {:displayName (macros/ident constants/form-field)
     ...}))

dpsutton21:08:59

perhaps a get but something similar to this (.set ^Var Compiler/LOCAL_ENV ....

dpsutton21:08:29

and perhaps the macro takes things that are known literals?

nickt21:08:31

so cljs will output something that looks like this:

var my_class = React.createClass({ displayName: "form-field-string" });

nickt21:08:51

or rather, that's what I want it to output

nickt21:08:57

what it currrently outputs is something like this:

jr21:08:20

the var is in another ns

bfabry21:08:35

^ yes. the macro doesn't know what constants/form-field refers to

nickt21:08:45

var my_class = React.createClass({ displayName: my_ns.constants.form_field });

jr21:08:50

(var-get (ns-resolve ns sym))

bfabry21:08:56

you could pass a fully qualified symbol if you wanted. my-app.constants/form-field

bfabry21:08:20

then (var-get (resolve x)) would work

nickt21:08:35

hm I still get the null pointer exception

nickt21:08:56

I tried (macros/ident hello-world.constants/blue)

nickt21:08:15

where macros/ident refers to (defmacro ident [x] (var-get (resolve x)))

bfabry21:08:18

seems to work for me

bfabry21:08:26

boot.user=> (defmacro ident [x] (var-get (resolve x)))
#'boot.user/ident
boot.user=> (defn foo [] (ident clojure.pprint/pprint))
#'boot.user/foo
boot.user=> (foo)
#object[clojure.pprint$pprint 0x22bce3d4 "[email protected]"]

jr21:08:28

write the macro in the hello-world.constants namespace and refer it where you need it

jr21:08:39

then all vars will be local

nickt21:08:04

I'm not sure cljs is cool with that

nickt21:08:42

you have to explicitly require-macros with cljs

nickt21:08:14

Anyway, gotta run. I'll check back in a bit, thanks y'all!

dpsutton21:08:09

this is what i've got so far, but i'm getting an error PersistentList cannot be cast to symbol

oahner21:08:00

~body doesn't look right

dpsutton21:08:16

but the idea is to get the values for the vars passed in and then walk the tree replacing them

nickt22:08:44

@dpsutton hey awesome I want to give that a shot

nickt22:08:48

where do I get walk from?

dpsutton22:08:16

(require '[clojure.walk :as walk])

dpsutton22:08:55

notice this does have serious issues with scoping. I think that ztellman/riddley has done some work on this

dpsutton22:08:18

And I'll bet zach would actually dig something like this, as I can see him inlining vars a bunch

dpsutton22:08:49

he's a big fan of fast this, fast that, rewriting things like satisfies and memoize

nickt22:08:18

I think I'm using it wrong hahaha

nickt22:08:10

it's a function call?

dpsutton22:08:37

yeah. We are using it to walk over the body of what we want to inline vars on

dpsutton22:08:55

its a function but we call it at macroexpansion time

dpsutton22:08:11

and for you to inline vars, those vars need to already exist so hopefully that's already been taken care of

nickt22:08:20

so how would I use it in this kind of context:

(def my-class
  (.createClass js/React #js
      {:color iss.constants/blue
       :fontSize (macros/add 1 2)}))

dpsutton22:08:53

what does add 1 2 do?

nickt22:08:02

I was playing around with inlining expressions

nickt22:08:14

(defmacro add
  [a b]
  (+ a b))

nickt22:08:24

just hacking stuff, this doesn't produce useful javascript yet

nickt22:08:40

for this example you could ignore it

dpsutton22:08:42

ok. I was thinking something like this

nickt22:08:37

how would I get that constants/blue?

dpsutton22:08:39

addition is fast, you just want to make sure that the google closure compiler doesn't see a and b but the values they represent, i thought

dpsutton22:08:44

assuming you already had these values

dpsutton22:08:49

but this kinda only works on the repl

nickt22:08:41

hmm yea it still gives me a null pointer exception in my little project

nickt22:08:57

I gotta run again actually, but this is awesome thank you for your help

nickt22:08:02

I'll ping you if you're around next time I'm on