Fork me on GitHub
#clojure
<
2015-11-12
>
stig00:11:19

I’ve got integer?, float?, number? but no byte? — how do I test if something is a byte?

stig00:11:31

(I have a function that only makes sense to be called with a byte, and I wanted to slap a {:pre [(byte? b)]} assertion on it, but discovered that byte? does not exist.)

johanatan00:11:32

Maybe add 0 <= n <= 255 as pre-condition in addition to integer? ?

johanatan00:11:45

[Not ideal but should work]

stig00:11:29

I came up with: {:pre [(isa? (type b) java.lang.Byte)]}

stig00:11:46

not quite as succinct, but seems to work simple_smile

stig00:11:43

@johanatan: thanks, that could work too, although would have to be (<= Byte/MIN_VALUE b Byte/MAX_VALUE) I think...

stig00:11:49

since bytes are signed.

kharus01:11:09

Is there any way to copy all project dependencies to some folder with lein? I want to package project but I don’t want to produce uberjar. So I’m thinking of moving all deps jars to some folder and package it.

nowprovision03:11:35

@kharus, you could use my script http://www.nowprovision.com/easy-access-to-dependency-source-code--2 this will put them in a depref directory then just rsync -av depref/ src/

cfleming03:11:27

@kharus: You can use the lein-libdir plugin or just use the :local-repo function, which is probably better if you want to run your lein project using those deps.

nowprovision03:11:32

@kharus actually thinking about my script won't work for this as its only first level dependencies that are pulled out, follow @cfleming suggestions

kharus03:11:26

Ok. Thanks.

danielgrosse08:11:06

I would like to create a solution, where I connect a frontend app, using javascript to a clojure app over websockets. I need a way of authorization and think pubsub fullfills my needs. Which solution would you prefer? - clj-wamp, which is currently only supporting wamp v1 - rabbitmq but the websockets support isn’t available for the langohr package - redis, where I don’t know much about

dm309:11:42

why can't you connect to the clojure frontend directly?

danielgrosse09:11:52

I have to check the client against an database, to prove its legibility. after that, the connection should be shown in the backend application. Only when the connection is choosen within the backend app, the real communication should start. I have multiple backend clients which has to get only shown frontend clients who called the frontend app over that specific account.

danielgrosse09:11:34

Maybe there are other ways, which I doesn’t had considered yet. But the Wamp approach suites my needs at most.

sgerguri12:11:30

So I've been reading Clojure Applied and there's this section on maps vs records right at the start. We talked about this with a colleague who has been writing Clojure professionally for longer than I have (only ~6 months in my case) and his position seems to be 'use maps everywhere, don't bother with records unless you have protocols you want to extend them with'. I'm not so sure on this. I kind of like having an entry point into a 'component' - be it a namespace, web service or whatever - which accepts a map, then turns it into a record and passes that around. Related to that is the matter of type hinting - when I do have a record does it make any sense to provide type hints in function signatures that accept a record as their argument? Or is there no net benefit to doing that/it's not idiomatic?

Alex Miller (Clojure team)12:11:19

there is no benefit to doing so, so I don't usually do that

sgerguri12:11:55

Thanks @alexmiller - do you also prefer to pass maps instead of records to represent program data, even if it's internal stuff?

Alex Miller (Clojure team)12:11:15

well I'm the author of Clojure Applied, so those are my opinions :)

sgerguri12:11:32

I know, that's why I'm asking! simple_smile

Alex Miller (Clojure team)12:11:54

it really depends on what I'm doing

Alex Miller (Clojure team)12:11:20

for domain data that is used internally, I think there are many benefits to using records over maps

sgerguri12:11:35

What I like most about records is that they are self-documenting. I find trying to glean the structure of a map from the function call chain (as different functions in the chain may access different parts of it) unnecessarily difficult.

Alex Miller (Clojure team)12:11:06

for the case of using a data container (not information entities) then maps are probably better

Alex Miller (Clojure team)12:11:28

and if I'm interacting with external stuff, I prefer to commit only to maps

sgerguri12:11:07

This is an internal domain data container I'm talking about, but it's also mostly being used in just one namespace. Thanks!

ordnungswidrig13:11:04

What’s the best way to call a function with signature (fn [& {:as opts}]) when you have the opts as a map?

ordnungswidrig13:11:42

Best I found is (apply x (apply concat opts)) which is nasty

martinklepsch13:11:01

@ordnungswidrig: (apply x (mapcat identity opts)) is probably just as nasty? Maybe there’s a mapply in a utility library you’re using simple_smile

ordnungswidrig13:11:20

@martinklepsch: any apply-> which be a good thing: (apply->> {:a 1 :b 2} concat x)

ordnungswidrig13:11:47

@martinklepsch: replacing (->> {:a 1 :b 2} (apply concat) (apply x))

bensu13:11:38

Hi! Weird question, after firing up a project after a week (without changes!) lein deps suddenly wants to retrieve [joda-time 2.9.1] which as far as I can tell, doesn't exist, and it predictably fails to find it

bensu13:11:08

does anybody know how to do something similar to lein deps :tree without lein trying to retrieve the deps first?

mpenet13:11:04

:offline? true

mpenet13:11:18

well, you need to add this in your project.clj

mpenet13:11:27

dunno if you can do something similar via cli

bensu13:11:43

thanks! I'll try with that

bensu14:11:16

@mpenet: thanks! it helped diagnosed the problem

mbertheau16:11:28

How would I use (not (my-pred? x)) in (-> x ...) or (->> x ...)?

mpenet16:11:02

juste use some-> or some->>

mpenet16:11:34

worked before your edit :}

snowell16:11:24

Has anybody seen an error like this before? I get it after bringing in cheshire:

(require '[cheshire.core :as ches])

CompilerException java.lang.IllegalAccessError: tag does not exist, compiling:(cheshire/generate_seq.clj:1:1) 

snowell16:11:53

Specifically in lein repl

jr16:11:54

@snowell: yeah that’s probably clj-http

jr16:11:04

upgrade to the latest major for the chesire fix

jr16:11:21

er just upgrade chesire since you’re using it directly

snowell16:11:37

I’m bringing in 5.5.0, which seems to be the latest

snowell16:11:23

@jr Hah, got it. I had updated leiningen, just not in project.clj. That seems to have done the trick

snowell16:11:33

I also updated cljs-http, just for good measure simple_smile

jr16:11:02

nice. confusing errors are confusing

snowell16:11:20

Still more helpful than javascript errors!

eraserhd16:11:12

I am writing a leiningen plugin for managing “aspects” of a project (note: terminology might be really bad - this is why I’m posting here). An “aspect” is a collection of dependencies, file templates, and perhaps some migration code.

jstew16:11:53

I wish there was something like clj-http that's async AND supports proxies. Such an animal doesn't exist, so I'm stuck with sync 😕

eraserhd16:11:55

I think this is a good idea, but I’m having trouble coming up with a good name, or the one-line description.

jstew17:11:34

sub-project? (borrowing from the term "submodule")

eraserhd17:11:11

@jstew Hrmm… to me, that implies that it can be compiled or run separately. Example “aspects” I have so far are “midje”, “logging”, “config-management”, and one for our internal documentation requirements.

eraserhd17:11:02

Oh, and “development repl”.

mpenet17:11:57

jstew: I'd gladly take a PR for this on mpenet/jet

jstew17:11:36

@mpenet: That looks super nice! It's the first I've heard of jet, I'll check it out.

bojanx10017:11:57

Hi! Does anyone uses internalization in clojurescript, any experience with "com.taoensso/tower" or any other library. Thanks.

bojanx10017:11:30

sorry, wrong channel

pbostrom17:11:32

@jstew: this is what we use: https://github.com/cch1/http.async.client -- a coworker and I recently took over maintaining it

borkdude18:11:26

Is the Clojure 1.8 socket REPL server suited for interprocess communication?

borkdude18:11:29

for example: connect from a non-Clojure technology and send expressions, receive results, deserialize to whatever you're programming in (Ruby, etc)?

robert-stuttaford18:11:15

i think it’s just a socket server, on top of which a nrepl handler has been provided. but it’s still just a socket, with which you can do anything you please

borkdude18:11:19

what do you get back from the socket, when you eval "(+ 1 2 3)", only "6" or more information? sorry, didn't try it yet

borkdude18:11:15

I'll try it later this evening

thheller18:11:53

@borkdude you just get 6, no other information

borkdude18:11:11

Someone asked how to embed Clojure in a Ruby application. I thought this could work.

thheller18:11:42

that'd be pretty unsafe

thheller18:11:54

since it just eval

Lambda/Sierra18:11:05

The socket-repl is lower-level than something like nREPL. You specify the function that evaluates things, so you can control what it does and how it returns things.

borkdude18:11:34

@thheller: If you control both processes, does it matter?

thheller18:11:05

depends on what you put on the socket

Alex Miller (Clojure team)19:11:07

The provided socket repl works on text streams

Alex Miller (Clojure team)19:11:56

But the socket server is separate from the repl - you can make your own repl that communicates with any protocol you want

triss19:11:34

hmmmm... is there a simple way to make Clojure always println to the REPL window?

triss19:11:14

I'm debugging some core.async stuff but my println's inside of go-loops aren't showing

triss19:11:18

should I be looking at alogging library?

ghadi19:11:56

that or use a centralized logging channel

ghadi19:11:28

with a large buffer. consume the channel from one thread and print

triss19:11:36

I've got a really simple think I thought would be doing logging like this:

(go-loop []
  (println (<! ch-recv))
  (recur))

triss19:11:29

shouldn't that print everything thrown down ch-recv?

ghadi19:11:48

lots of things could be involved (nREPL)

triss19:11:28

yup. nrepl is involved.... also using ring, could that be causing probs?

triss19:11:41

I guess a logging lib is way to go then?

ghadi19:11:32

it's not the libraries used but the way printing is handled with nREPL/lein

borkdude19:11:34

I've had a problem before when things were logged three times... turned out to be nrepl + timbre problem.

ghadi19:11:22

you can always collect some logs in an atom rather than println

ghadi19:11:33

then inspect the atom locally

triss19:11:46

ghadi: awesome idea. thanks

mpenet20:11:15

can't you add-watch on the atom and println from there :} ?

mpenet20:11:51

maybe that's what you meant

mitchelkuijpers20:11:41

@jstew: Have you considered Aleph?

jstew20:11:04

@mitchelkuijpers: Yes, and it appears as there are no docs pertaining to being able to configure a proxy during runtime, but according to a github issue it may be possible.

jstew20:11:52

I may end up having to submit patches somewhere. Not a big deal, just a little extra work simple_smile

mitchelkuijpers20:11:02

Yeah the docs are a bit lacking unfortunately, haven’t tried configuring a proxy to be honest. But you get basically the same api als clj-http

jstew20:11:04

That's a huge plus.

eraserhd20:11:29

Who’s using rewrite-clj?

arohner21:11:58

weavejester: would you accept a patch for https://github.com/weavejester/hiccup/issues/108 ?

arohner21:11:16

sablono (hiccup for CLJS) already supports it, and I’d like to unify some .clj & .cljs code

danmidwood22:11:02

I'm slightly puzzled by something, I have something in the repl that's adding meta data to things (maps, vectors, etc) that's causing problems in another part of my app that has to deal with these objects. The metadata is basic file things, like the following for one of the maps: {:file file:/Users/dan/repos/projects/company/mvp/src/clj/company/api/post.clj, :line 182, :column 20, :end-line 186, :end-column 36}

danmidwood22:11:07

Does anyone recognise this? Or already know where it might be coming from?

eraserhd22:11:35

This is for something entered in the repl?

danmidwood22:11:55

No, it's just normal namespaces in a file

danmidwood22:11:49

I don't see it when I run the app outside of the repl though, only when I open the repl port and connect to the running app

eraserhd22:11:25

Interesting. Oh… you mean its printing it in the repl?

danmidwood22:11:22

No, the problem that I'm having is that the objects (maps, vectors, etc) are being sent to redis through Carmine, which encodes the data including meta data

eraserhd22:11:22

There’s a print-meta dynamic variable that could be bound in your repl somehow.

danmidwood22:11:13

Which then leads to a point where the objects can be identical, but the encoding in redis is not

eraserhd22:11:04

Is your app deployed as an AOT jar? I don’t know what that does to metadata.

danmidwood22:11:43

It's only in development that I see this, I'm running the app through "lein repl" with a :repl-options {:init ...} in the project file that starts the app running. At this point everything seems ok. Then I connect emacs/cider to the repl port and it starts adding the meta data

pshk4r22:11:35

I want to use prismatic/schema for data coercion but it throws disallowed-key errors for the keys that are not described in a coercer schema. I want it just to ignore them. Has somebody faced the same issue? What is the reason for such a behavior? I can't really understand why it's so strict about this.

pshk4r22:11:04

@val_waeselynck: thanks. the thing is: I don't want to drop undescribed keys, I want it to not to coerce them. See, I receive a lot of fields, like 20 for example, all of them in string format obviously. And only 3 of them should not be strings but numbers or whatever. So instead of describing all 20, I would like to just ask coerce fields :money, :year, :age and leave everything else as it is. At the moment, schema expects me to describe all the 20 fields and I see no logic here.

val_waeselynck22:11:08

@pshk4r: something like {:money Int, :year Int, :age Int, Keyword Any} maybe ?

val_waeselynck22:11:45

or {:money Int, :year Int, :age Int, Keyword Str}

pshk4r22:11:58

that's exactly what I expected, thanks a lot!

pshk4r22:11:58

I love Clojure community ❤️

eraserhd22:11:11

@danmidwood Weird. I don’t know what the problem is, but I have ideas on how to isolate it - binary chop on nrepl middleware after trying a different nrepl client to ensure that it isn’t CIDER’s doing.