Fork me on GitHub
#clojure
<
2017-05-11
>
steveb8n00:05:40

@noisesmith thanks. it seems like groups is still best for long term threads. not ideal either but I’m more concerned with the content c.f. the host 🙂

noisesmith00:05:26

if it were up to me we'd all have stayed on IRC, I'm here because other people went here

qqq02:05:00

someone should write a slack alternative in clj/cljs, then write a book called "intro web programming full stack" on the design/impl;

xiongtx05:05:03

Is there a more elegant way to do the following?

(defn apply-sequentially
  "For fns = [f g h ...], return [x (f x) (g (f x)) (h (g (f x))) ...]"
  [fns x]
  (loop [fns fns
         vs [x]]
    (if (empty? fns)
      vs
      (recur (rest fns)
             (conj vs ((first fns) (last vs)))))))

noonian05:05:46

Maybe something like:

(defn sequential-applications [x fns]
  (reductions #(%2 %1) x fns))

xiongtx06:05:17

noonian: picard-facepalm can’t believe I didn’t think of that myself 😄

john05:05:54

I just did that recently too in some code: (reduce #(%2 %1) 1 [inc inc inc]) => 4

john05:05:37

Oh, but you wanted the result in a sequence

john05:05:25

yeah, reductions it is

jimmy07:05:15

hi guys, in clojure how do we pprint without , and everything must be in newline ?

(clojure.pprint/pprint {:a :b :c :d})
{:a :b, :c :d} ;; results
{:a :b
 :c :d} ;; I want this 

kwladyka08:05:36

(run! println {:a :b :c :d}) maybe you need something like this?

jimmy09:05:11

@U0WL6FA77 that doesn't work, it prints the map in vectors @U06GS6P1N I haven't messed with this one yet. But it seems to be the right way.

val_waeselynck09:05:54

doesn't seem to solve the comma problem though

jimmy09:05:43

yeah, there is no option to remove comma

val_waeselynck09:05:28

if every collection has exactly one line per item, it may be viable to remove the commas using a regexp

val_waeselynck09:05:33

assuming pprint doen't issue multiline-strings (I don't think it does)

jimmy09:05:05

I think i will stick with vim replace for now. Will dig in this one later. thanks for collab everyone 🙂

kwladyka10:05:23

hmm i think function like pr-str but print in more human readable format will be really cool, please share if you find something

kwladyka10:05:03

for example i use map to throw errors with data to debugging, reading it is uncomfortable

john17:05:43

you could play with something like (apply str (interpose \n the-map))

john17:05:15

eh, or \newline

achesnais10:05:35

when using clojure.core.reducers/fold, how would one usually go about choosing the chunk size n?

mayankpahwa12:05:21

Hi All, I am looking for some project ideas in Clojure/Clojurescript (intermediate-level). Any suggestions?

jjl12:05:58

mayankpahwa: contributing tests to open source is a great way to improve your clojure

curlyfry15:05:26

Perhaps build a webscraper using https://github.com/cgrand/enlive and then use cljs to present the scraped data in an aggregated and nicer way? Or a simple turn-based browser game using something like re-frame?

mayankpahwa05:05:57

@jjl Thanks for replying. I will do that on the side. Actually, I am looking for a full fledged end-to-end clojure project. @curlyfry Thanks for the suggestions.Not really a big fan of web scraping and I have just finished making a turn-based game called 'Chain-Reaction' using figwheel and reagent. ----- Are there any small but useful missing modules/libraries in clojure that i can write?

jetzajac13:05:53

Hello everyone. sorry for asking kind of silly question but I honestly couldn’t find actual example anywhere. How do I type-hint java arrays of objects?

cpmcdaniel13:05:50

@jetzajac try #^java.lang.String

cpmcdaniel13:05:30

I do see that this is missing from the interop page on http://clojure.org

jetzajac13:05:46

@cpmcdaniel wow. It couldn’t be simpler 😃 thanx

cpmcdaniel13:05:58

I had to look it up myself, but it took some digging

ghadi13:05:41

@cpmcdaniel @jetzajac that's the older hinting syntax, and that is not an array hint. try:

^"[Ljava.lang.String;" collection

ghadi13:05:08

The syntax is a bit baroque because it comes from java bytecode

vitruvia13:05:24

Does anyone here use Lighttable? How can I assign the same keymap to two different commands under different conditions? (for example making f12 open the console if it is closed or close it if it is already open)

ghadi13:05:17

[ signifies array and Lclassname; represents a class in the bytecode. Regarding clojure typehints, the #^ syntax has been deprecated for a while. Just need ^

slightlycyborg13:05:52

I am javac to compile a lein project manually. I am using clojure 1.9.16-alpha. Do you know why I would get this error during compilation of clojure.core.specs.alpha Unable to resolve symbol: qualified-keyword? in this context, compiling:(clojure/spec/gen/alpha.clj:131:4)

slightlycyborg13:05:41

By manually, I mean, I am using lein-droid which calls javac.

Otto Nascarella13:05:31

hi guys, I have a question that's been bugging me... what would be the difference between a function composition and a transducer?

ghadi13:05:52

Function composition is used to stack transducers

ghadi13:05:36

A stack of transducers is itself a transducer

sbauer14:05:33

@vitruvia it sounds like you would need to write a behavior or command in your user plugin and then assign it to the user keymap for f12

vitruvia14:05:42

@sbauer Thanks, looks a little advanced for me since I've never made any plugins... any suggestion for a place to start?

sbauer14:05:22

There is some documentation of varying levels of quality on making plugins in the [LT wiki](https://github.com/LightTable/LightTable/wiki) that should be a good place to start

sbauer14:05:45

If you do not have User plugin yet, you should be able to run the command Settings: Add User plugin to workspace to get one set up

vitruvia15:05:04

Alright 😃

vitruvia15:05:24

I'll read some of the tutorials and see what I can do with my current level of skill ^^

sbauer15:05:43

Depending on your specific needs, like toggling the console open or closed, it might be possible the command already exists in LT, in which case you could just modify your user keybinding file and not deal with the User plugin...

vitruvia15:05:32

In this case the command does exist, but for example if I assign opening the console to f12 and then assign closing the console to f12, it will only do one of those

vitruvia15:05:49

like even if the console is opened it won't close it or vice versa

sbauer15:05:15

hmm, something like [:editor "f12" :toggle-console] doesn't work? (assuming the editor has focus)

sbauer15:05:41

i created #lighttable so we can leave #clojure focused on clojure, if you have additional questons

josh.freckleton15:05:22

I have a helper fn with signature: (defn helper [resource f] ...) that handles resource management while running f If f throws an exception, I want to still handle closing the resource in a try's finally, but bubble up the original exception to the caller of helper... Is it good practice for the catch in a try block to just re throw the error? And will finally still be called?

donaldball15:05:08

josh.freckleton: You don’t even need the catch form if you’re not doing something besides rethrowing the original exception without alteration

josh.freckleton15:05:59

oh, like just a try + finally, no catch?

josh.freckleton15:05:39

well there I have it 🙂

borkdude18:05:15

What’s a good way to make available a named value inside the body which you pass to a macro? Use a kind of binding syntax?

borkdude18:05:25

Probably the bad way:

(defmacro foo [& body]  `(let [~'url ""] ~@body))
(foo (println url))
is not really clean I guess

rwilson18:05:02

It's fairly common for a macro to accept a binding form. Using an implicit binding form can be confusing.

jr18:05:26

user=> (defmacro foo [sym & body] `(let [~sym "foo"] ~@body))
#'user/foo
user=> (foo name-of-var (println name-of-var))
foo

jr18:05:12

just unquote the symbol in the macro body

borkdude18:05:41

I’m doing this for a macro I use in testing endpoints, didn’t want to pass the name url all the time, but for exposed macros I guess this is better

grav18:05:30

Is there something like jq (a command line tool for processing json) for edn?

ghadi18:05:48

I saw something somewhere for that... but i'd have to recommend using clojure.core functions rather than some gross (though convenient) DSL like jq

ghadi18:05:39

Don't get me wrong, I use jq regularly... but it can never beat using the language you already know.

ghadi18:05:30

maybe using lumo or planck with clojure.core functions would be an option

grav18:05:44

No, I agree, but maybe it could be implemented as just a wrapper around the core fns and a pretty printer

ghadi18:05:59

lumo and planck start up really fast, and can read edn

grav18:05:52

And they can take expressions from cmd line I guess?

noisesmith18:05:27

right, just like clojure can

noisesmith18:05:48

I mean, even clojure.core can do this if you are willing to wait about 1 second startup time

noisesmith18:05:23

it’s things like leiningen and nrepl that make it take longer, you don’t need those for edn

noisesmith18:05:31

justin@S: ~$ time echo '(+ 1 1)' | java -jar ~/bin/clojure-1.9.0-alpha15.jar
Clojure 1.9.0-alpha15
user=> 2
user=>

real    0m1.425s
user    0m2.022s
sys     0m0.181s

grav18:05:08

So I guess it’s something like curl | java -cp clojure-1.5.1.jar clojure.main -e "(-> *in* slurp clojure.pprint/pprint)"

mfikes19:05:55

With that, at least you get the speed of Fipp and color 🙂

borkdude19:05:06

@grav Command line tools are not really Clojure’s strength because of the JVM, but Lumo or Planck makes it great.

borkdude19:05:44

@grav But the REPL is even better for one time experiments of course

grav19:05:55

@mfikes What do you mean by “exposed via some stable public API meant for consumption”? How would the code example in the ticket look if it was like that?

borkdude19:05:08

(sorry, I started typing, then left and then finished what I was typing before reading all the responses)

mfikes19:05:48

@grav planck.pprint.data/pprint wasn't really meant for external use when I wrote it, that's all

grav19:05:42

ah, so they should just be exposed in planck.core?

borkdude19:05:50

@grav One other option, that is really fast, but maybe not so mature yet: https://github.com/candid82/joker

noisesmith19:05:02

justin@S: ~$ time cat ...secrets.../development.clj | java -jar ~/bin/clojure-1.9.0-alpha15.jar -e '(require '"'"'clojure.pprint '"'"'clojure.edn) (clojure.pprint/pprint (clojure.edn/read-string (slurp *in*)))'
{:logging {:loggers [{:type :stdout, :level :debug}]},
 :app {:use-database true},
 :database
 {...secrets...}}

real    0m1.185s
user    0m2.149s
sys     0m0.139s

grav19:05:20

@borkdude cool project!

borkdude19:05:48

@grav Yes, I use the linter in Emacs. For that it’s really great, because of the responsiveness

noisesmith19:05:14

so I demonstrate you can do it in under 3 seconds with clojure - but it’s obviously not being done optimally (you would probably want an actual clj file etc.)

lxsameer19:05:16

is it a bad practice to use boot and lein together ? I want boot to act like rake or make for my tasks and not the actual build system

ghadi20:05:00

I wouldn't say it's super bad, but requiring less from your users is always preferable. (If you're migrating from one to the other, you'll almost certainly have an intermediate state where both are in play.) They both have their strengths and weaknesses

rauh20:05:53

Is there a reason Records don't impl clojure.lang.IEditableCollection ?

rauh20:05:33

Alright, I see that's http://dev.clojure.org/jira/browse/CLJ-1459 , voted on it.

lxsameer20:05:46

what do people use as a similar thing like rake ?

hiredman20:05:38

lein run some.clojure.ns.thatdoes/something

hiredman20:05:34

and if you want to get really fancy you setup an alias for that in your project.clj

timgilbert21:05:21

Say, is there any reason the predicate clojure.test/function? is socked away in clojure.test instead of the main namespace? Is there a more idiomatic way for me to test whether a value is a function?

ghadi21:05:20

^ -- note that hashmaps and other things are functions

joshmiller21:05:58

There’s also fn? which returns false for maps and keywords

Alex Miller (Clojure team)21:05:30

I find I want fn? approx 0% of the time :)

timgilbert21:05:55

Aha, I see there is already an fn? predicate in clojure.core, I'll use that

hiredman21:05:01

doesn't fn? return false for multimethods?

dpsutton21:05:20

> Returns true if x implements Fn, i.e. is an object created via fn.

hiredman21:05:29

Clojure 1.9.0-master-SNAPSHOT
user=> (defmulti foo identity)
#'user/foo
user=> (fn? foo)
false
user=> 

dpsutton21:05:35

sounds like you'd be surprised at the things that are "functional" that aren't created with fn

vij21:05:08

What is the best way to transfer files through clojure between two different processes running on different hosts?

noisesmith21:05:26

I’d transfer data rather than files, if the difference matters at all

vij21:05:54

Maybe using some clojure libraries as well. But should happen as part of clojure code, so I can process that file once available.

vij21:05:24

The file could be a binary file as well. Eg,, a tgz file

noisesmith21:05:59

sure, what I’m saying is that “file” is a specific place to put a sequence of bytes

noisesmith21:05:16

and code that uses bytes generalizes better than code that uses files, the file part is trivial

vij21:05:50

So far I have got it working by creating a websocket to one of the process and receiving the file over that socket as data

noisesmith21:05:24

OK - http://clojure.java.io has two functions, copy, and file

noisesmith21:05:30

that will take care of the rest for you

noisesmith21:05:13

just be sure not to use any of the text oriented io functions

vij21:05:11

Thanks, I will try it out.

fabrao22:05:15

Hello all, how can I convert this to clojure?

TrustManager[] trustAllCerts = { new X509TrustManager()
      {
        public X509Certificate[] getAcceptedIssuers()
        {
          return null;
        }
        
        public void checkClientTrusted(X509Certificate[] certs, String authType) {}
        
        public void checkServerTrusted(X509Certificate[] certs, String authType) {}
      } };

fabrao22:05:12

This didn´t work:

((X509TrustManager.)
   (reify
     (into-array X509Certificate) (getAcceptedIssuers [] nil)
     (checkClientTrusted [certs authType])
     (checkServerTrusted [certs authType])
     ))

rwilson22:05:29

That's trying to instantiate a X509TrustManager and then call it as a fn

rwilson22:05:28

If you want an anonymous instance implementing it, you can use:

(reify X509TrustManager 
  (getAcceptedIssuers [this] 
    nil) 
  (checkClientTrusted [this chain authType]
    ;; impl...
    ) 
  (checkServerTrusted [this chain authType]
    ;; do whatever...
    ))

fabrao22:05:02

humm, thanks alot rwilson

mayankpahwa05:05:57

@jjl Thanks for replying. I will do that on the side. Actually, I am looking for a full fledged end-to-end clojure project. @curlyfry Thanks for the suggestions.Not really a big fan of web scraping and I have just finished making a turn-based game called 'Chain-Reaction' using figwheel and reagent. ----- Are there any small but useful missing modules/libraries in clojure that i can write?