Fork me on GitHub

my web server is not serving pages ... everything is a 404.. it will show me the 404 page i specify though. hrm.


Hi all. ((fn [a [b c]] (println a)) 5 [7 9]) works but ((fn [a (b c)] (println a)) 5 (7 9)) doesn't. Is there a way to make the later work? As in even if the 7 were a function it wouldn't get called and would just get bound to b. I guess the question is, can the "higher-level" function being called dictate if the "nested" functions actually get called?


the binding doesn't change (fn [a [b c]] .... Clojure is strictly evaluated. Which means it will evaluate all args to a function and then call the function with the results. If you like you can write a macro that does what you want but there's probably better ways to get where you need to be


Ok. What would the macro look like?


it kinda depends on what your inputs and outputs are


how do you envision this being called?


There's no particular use case in my mind. I'm just exploring the language for now. I am wondering can we write some kind of structure where nested function calls don't happen if the function on top wants to prevent it. Perhaps this can be molded to some kind of debugging/logging tool.


So, perhaps (debug (f 4 2)) be somehow able to see the f, the 4 and the 2 instead of seeing the result of (f 4 2).


like this?

(defmacro debug [expr]
  (clojure.pprint/pprint expr)


I'm sorry couldn't you just quote it? ((fn [a [b c]] (println a)) 5 '(7 9))


seems to run just the same... but maybe I'm missing the idea.


Hi everyone! πŸ™‚ What do you guys use to generate reports for the coverage of your unit tests? I’m currently playing around with Cloverage, but I’m struggling to get it to output a single report with a summary of my test coverage. I have one master project with several sub-projects, but Cloverage seems to work only on level project. Does anyone have experience with this tool (or a similar one), and know how I can get it to output a single report with a test coverage summary, including the sub-projects? Cheers!

πŸ‘ 1
Andrea Imparato12:09:40

I use it as well and I think that cloverage as you said works only on level project

Andrea Imparato12:09:03

btw, do you know perhaps what does % Form means in the table results?


I have no clue on that either πŸ˜…

Andrea Imparato09:09:50

about the % Form: I opened an issue and the author answered here FYI:

πŸ‘ 1
David Pham12:09:08

In specs, how can I check that two values in a map, which are sequences, have the same number length/size/count?


Write a function that checks that


Predicate functions are specs

David Pham13:09:18

@alexmiller I am sorry, I don’t see how it solves the issue.


  #(= (-> % :a count) (-> % :b count))
  {:a [1 2 3] :b [4 5 6]})


hey everyone i have a quick question: when reading/looking at other codebases i see a lot of single letter variables. are descriptive variables/args frown upon?


I like expressive variable names myself. There’s a few common conventions like f for functions, coll for collections, and so on. But definitely, if you like descriptive names, go for it.

πŸ‘ 2

> f, g, h - function input


aw man! 😞


but this is a good page to bookmark, thanks @clojurians-slack100!


Indeed. I was directed to it multiple times already 😜


@tjb The use of short variable names is fairly common in functional programming because you often have functions that are a lot more generic, so they accept arguments that sometimes just don't even have "sensible" names. Personally, I'd probably have gone for filter-opt in the example you linked, since I'm used to f meaning "function".

πŸ‘ 1
Andrea Imparato16:09:38

is it possible to use a function to generate a clojure spec or it has to be defined only in a def statement?

Andrea Imparato16:09:07

i'm trying to do something like

(defn user-input-regex [max-bound]
  (re-pattern (str "[0-" max-bound "]","[0-" max-bound "]")))

(defn generate-input-spec [max-bound]
  (spec/def ::input-spec (spec/and string? #(re-matches (user-input-regex max-bound) %))) )

Andrea Imparato16:09:14

but it seems to not be working πŸ˜•


spec/def (and spec/and) are macros here that capture their forms so it will use the symbol max-bound, not the closed over value


it is possible to do this with a macro that does that replacement however


(this is an area with substantial changes in spec 2 fyi)


I'm trying something on refernce types. So, I've one ref. (def available (ref #{})) . I'm setting it up using ref-set. `(ref-set available (into #{} (mapcat (fn[levels] (map #(vector (key levels) %) (range 1 (inc (val levels))))) {0 3})))` which gives me ref as :- #{[0 3] [0 2] [0 1]}, which is i want. Now i want to set this value using "alter". So i am trying something like below. `(alter available conj (into #{} (mapcat (fn [levels] (map #(vector (key levels) %) (range 1 (inc (val levels))))) {0 3, 1 2}))` Which gives me :- #{#{[1 1] [0 3] [0 2] [1 2] [0 1]}} . But i am expecting something like :- #{[0 3] [0 2] [0 1] [1 1] [1 2]}


I'm missing something stupid here.Any help?


Sets are unordered.


Oh, you mean the nesting?


its not the ordering, there's a set in a set


Yeah, probably the extra set nesting


(took me a second too :)


(alter available into (mapcat ...))
instead of conjing a new set in?


oh. Thank you.:)


@parth.12282 ref is very rarely used in Clojure, just FYI. atom is more common.


a good rule of thumb is to use an atom with data under keys of a hash-map until contention / retries become a problem


usually contention / retries never become a problem

Misha Vakulich21:09:29

hello, I stuck with a problem of default interface method call in clojure

Misha Vakulich21:09:37

I have really ancient project written on mix scala/java/clojure and I have to upgrade the code to be java 1.8 compatible and scala generates a lot of interfaces with default methods

Misha Vakulich21:09:19

the problem is when I use gen-class to generate class which implements these interfaces. gen-class generates it's own methods for all interface methods definition and override the defaults exposes-methods does not help


I don't use gen-class much but I find that surprising - most clojure functions that create new classes simply ignore methods not specified, letting you get a NoSuchMethodError at runtime

Misha Vakulich22:09:12

it is really interesting to decompile bytecode generated by gen-class it creates all the methods and see if they are actually bound to clojure functions, and when they not bound - it will raise NoSuchMethodError


oh - that would interfer wouldn't it - I guess one tedious option is to make method functions that delegate to an instance of the superclass


maybe a macro could make that less onerous


concrete inheritance in clojure tends to be clumsy, generally

Misha Vakulich22:09:13

spend several days on that, no luck,

Misha Vakulich22:09:32

and low on macros experience


it's a very thin java class, that calls a configured clojure namespace for every method implementation


it might be simpler to make a small java file and delegate to clojure for the "meat" of everything


Also if deftype does what you need (it might not), I do not believe that it shares that property you found about gen-class


can deftype do the right kind of interface-with-default-methods inheritance for this? I wouldn't expect it to.


I was under the impression it didn't do any sort of concrete inheritance


there's proxy and proxy-super except proxy-super is a bit buggy in multi threaded code

Misha Vakulich22:09:47

the problem is that is core library, and a lot of code depends on the class generation. so changing to proxy is not an option, will try deftype other option is to create Abstract class with explicit overriding of method, and then gen-class


I just actually looked up Java interface with default method, and what I found said it was introduced in Java 8, and while the latest Clojure versions support only Java 8 and later, there is very little in Clojure that takes advantage of features added to Java that "late".


I have little experience in this area, so out of my depth here, but will throw in a half cent (because worth less than the usual 2 cents) that when Clojure class creation methods run out of steam, Java is the escape hatch that of course gives you full access to all supported options/features.


And those can often be made very 'thin shims' that have most/all of their implementation in Clojure.

βž• 2

I might make a small lib to simplify that kind of shimming

Misha Vakulich22:09:34

solution via abstract class works, updated repo, just FYI