Fork me on GitHub
#beginners
<
2019-09-04
>
sova-soars-the-sora00:09:47

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

Shabbir03:09:45

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?

dpsutton03:09:29

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

Shabbir03:09:29

Ok. What would the macro look like?

dpsutton03:09:23

it kinda depends on what your inputs and outputs are

dpsutton03:09:30

how do you envision this being called?

Shabbir03:09:30

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.

Shabbir03:09:47

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).

valerauko04:09:54

like this?

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

Mno12:09:30

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

Mno12:09:10

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

Quade11:09:28

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?

Quade14:09:10

I have no clue on that either πŸ˜…

Andrea Imparato09:09:50

about the % Form: I opened an issue and the author answered here FYI: https://github.com/cloverage/cloverage/issues/252#issuecomment-528043131

πŸ‘ 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?

alexmiller12:09:32

Write a function that checks that

alexmiller12:09:47

Predicate functions are specs

David Pham13:09:18

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

alexmiller13:09:00

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

tjb14:09:04

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?

manutter5114:09:57

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
tjb15:09:04

> f, g, h - function input

tjb15:09:14

aw man! 😞

tjb15:09:28

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

walterl15:09:55

Indeed. I was directed to it multiple times already 😜

seancorfield16:09:19

@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 πŸ˜•

alexmiller16:09:35

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

alexmiller16:09:57

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

alexmiller16:09:11

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

P69617:09:53

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]}

P69617:09:56

I'm missing something stupid here.Any help?

seancorfield17:09:59

Sets are unordered.

seancorfield17:09:14

Oh, you mean the nesting?

dpsutton17:09:15

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

andy.fingerhut17:09:27

Yeah, probably the extra set nesting

dpsutton17:09:29

(took me a second too :)

seancorfield17:09:03

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

P69617:09:07

oh. Thank you.:)

seancorfield17:09:13

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

noisesmith17:09:17

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

noisesmith17:09:29

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

noisesmith21:09:12

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

noisesmith22:09:10

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

noisesmith22:09:18

maybe a macro could make that less onerous

noisesmith22:09:38

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

noisesmith22:09:38

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

noisesmith22:09:18

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

andy.fingerhut22:09:18

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

noisesmith22:09:31

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

noisesmith22:09:52

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

noisesmith22:09:17

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

andy.fingerhut22:09:12

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".

andy.fingerhut22:09:23

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.

andy.fingerhut22:09:11

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

βž• 2
noisesmith22:09:30

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