Fork me on GitHub

i’m having trouble with the brave book; specifically the reduce function


I highly recommend ‘How to Design Programs’ for learning functional programming, particularly recursion. It’s freely available at


Ah! Will look into it, thank you.


for example, what are these types of functions called so i can youtube videos about them?

The symmetrize-body-parts function (starting at ➊) employs a general strategy that is common in functional programming. Given a sequence (in this case, a vector of body parts and their sizes), the function continuously splits the sequence into a head and a tail. Then it processes the head, adds it to some result, and uses recursion to continue the process with the tail.


@tiotolstoy Search for "recursive functions"


(the other term to search for @tiotolstoy is "higher order functions")


Ok… me thusfar… • Visual Studio Code with Calve. • Went through Clojure for the Brave. • Did all Clojure Koans. (Icheated on the later ones by looking at the solutions. • Now planning on reading/going through “Web Development with Clojure, Third Edition” by Dmitri Sotnikov and Scot Brown ( ) Or are there other recommended paths for learning?


Write code. Haha. I did a lot of reading myself, but nothing beats working on your own project. At some point while studying I felt like I was just going through the motions and not paying as much attention. That never happens when you are trying to solve problems that you care about. Knowledge seems to stick better when you’ve earned it with sweat and blood, at least in my experience. Also, check out other people’s code repositories, or read the source for libraries that you use. You will wonder why people do things a certain way, and it teaches you a lot.

Aviv Kotek08:05:04

what would be the easiest way to go with any auto-complete tool on given data? (without integrating any search engine) fwould need to get some string and return some amount of relevant data (`starts_with` for example) simple start could be just to implement a "like_starts_with" SQL query with any clojure-jdbc. maybe there's some work with libraries on this? can't find much


Have you considered using a Java library with interop?

Aviv Kotek09:05:13

heh good idea 🙂

Ben Sless09:05:58

Does your data fit in memory?

Ben Sless09:05:45

So why not a map? 🙃

Ben Sless09:05:00

besides implementing the trie yourself

Ben Sless09:05:21

Clojure maps have good performance characteristics

Ben Sless09:05:51

What you'd want ideally is a trie which also saves the top N children of each node for easy access

Aviv Kotek09:05:46

yea building a trie is some-work

Aviv Kotek09:05:57

it could be nice for fun but I guess i'll just move the solution outside clojure-scope

Aviv Kotek09:05:20

thinking on again a simple auto-complete just needs to fetch the data - store it in memory and use 3rd-party for that

Aviv Kotek09:05:53

Writing the question here helped me understand how to tackle the problem 🙂 thanks guys!

Ben Sless09:05:31

Think about what you'll do about the data changing over time

Aviv Kotek09:05:23

yea, data is small and won't change so basically you can load it all up once, then it's no-fun and just use some libraries. those tasks become harder when data is dynamic, then some search-engine helps out


how can I create an HTML string from hiccup? I would like to generate HTML and show it on a web page as part of a reagent app so that the user can copy the html and use it somewhere else


Hiccup has an html function which does what you want (I think)


Not sure about reagent’s version though


Anyone interested in dependent types? There is “In Further Praise of Dependent Types” post on HN frontpage now that I didn’t understand at all, but the idea sort of maybe sounds interesting… It also led me to a comment mentioning Idris and how the author of Idris gave a talk about using it’s type system to define matrix transposition, and I found that video, and it’s so hard to folllow, and it’s lines and lines of type definitions for what is #(apply mapv vector %) in clojure, but still, all those static guarantees sound interesting, perhaps not very practical in currently existing statically typed languages…

Ben Sless13:05:16

They look interesting. Do you want to link some of the sources? I remember checking if it's possible with spec, came across things like


my comment there with a link to a video of matrix transposition


@UK0810AQ2 interesting gist, I wonder if there can be a spec-like static type system…


Haha, I thought that's #off-topic for some reason :)


ah I meant to comment on this this morning and now doubly wish I did, as I in fact have a project for a spec-like inferred static type system (with structural typing, rather than nominal typing and eventually maybe something that may amount to dependent typing); this is an area of experimentation I wish to explore


in my case, the extra type safety I wanted to experiment with is seeing what is possible additionally encoding pure prolog-ish rules and facts, like "x > n and n > n2 then x > n2" (sorry, its been like 6 years since I've used prolog) and then, into a type, "x > 3"


I really wanted to explore Shen at some point, as I could have sworn it was implied you could encode any predicate statically (I have no sort of rigorous basis to know if that's possible or what's possible here), but that sort of fizzled out, as I remember having a lot of trouble just getting a decent repl going / finding proper support for it (that being said, I was willing to try again eventually)


In my case, I'm still messing with a format for representing the types, right now there's a haskellian shorthand for expressing them (but they're also being stored as that shorthand) that looks like [:-> :Int :Int :int], [:=> [:Num :x] :x -> :x -> :x]


(great this is long) naturally the idea is to express them underneath explicitly, so that trying to read the different 'properties' of the type would just involve, well, being able to ask for them directly, with a type looking like

{:typeclasses [[:Num :x]] 
 :type [:-> :x :x :x]} 
Interestingly the first example I think of, in the first time I saw a conversation covering this idea of explicit vs implicit data (a little while after I'd first really thought about) where I thought 'yes, that's it, they're thinking this exact same idea' was I believe a conversation of yours on whether to represent some part of cljfx implicitly as a vector or explicitly as a map


woah, nice!


I like specs (that are also data) for type representation 🙂


One area I especially want to examine is where the line draws between static typing giving you a strength of sorts at a cost of what you can express, and when its just flat out unobtrusively detecting some unambiguous contradiction in your intention (such as writing something like (def a {:a 1 \:b 2}) (:c a) -- not the best example, since this is something you would get an error for anyways (and one ) --> but something like that maybe where (:c a) is a little less direct and buried somewhere else). After all, for those who still want full dynamic expression, by definition this would be maximizing that experience 😄


Hello folks, I’m having an issue using the java.time package. It is definitely running Java 8. When running (java.time.LocalDate/of 2019 1 1) it throws IllegalArgumentException: No matching method of found taking 3 args.


does wrapping the longs in (int ) help? usually clojure is good at checking for int methods when provided with longs, but it's worth a try


:face_palm: turns out the test was passing in a keyword not an int.


well that explains it (btw 1 isn't an int in clojure, it's a long)


I thought the issue was related to the environment configuration or how it was being imported. This is the first time I’m using the Java interop functionality.


Good to know. Thank you!


I’ve confirmed that it works in a REPL as well as the java docs.

Jakob Durstberger17:05:52

I know naming functions with ? when they return a boolean is idiomatic, but would you do the same for keywords like {:active? true} vs. {:active true} vs. {:is-active true}


I've seen both the first two in the wild but I don't recall seeing the last one - it smells a bit too much of Java probably.

Jakob Durstberger18:05:57

> it smells a bit too much of Java probably. Definitely does, just thought I wouldn’t leave it out

Jakob Durstberger18:05:26

@U6N4HSMFW I like the reasoning that it gets confusing when you use destructuring and therefore won’t do it. Thanks 🙂


That article is a good read by the way: I agree with everything in it. The distinction between a Boolean and a predicate is the key.

AJ Jaro18:05:58

I actually prefer the third option as it hints towards the type of value it’s referring to.


Yeah, whilst I agree with the article in its principles I wouldn't say that I always stick to those rules in practice - I do find it makes for more readable code to use keywords with ? sometimes.


So I have a bbb.clj file with ns myproject.bbb and defn bbx in it, when I test/execute bbx it works just fine I have core.clj with ns myproject.core and I include a require [myproject.bbb as abc] I then call in core.clj (abc/bbx) and it does not execute. Currently under the impression that by referencing bbx via require [myproject.bbb as abc] it should be working. Is this correct? Odd thing was that it was seemingly working previously


Do you have :as with a colon, or as with no colon? The latter is incorrect.


If it isn't too many lines, you are welcome to copy and paste your entire ns form into chat, so we can see what it looks like character-for-character


yes I have :as in place


It reports it cannot find bbx when executing the call from core


[myproject.bbb :as abc]


Is your project published anywhere? It is difficult to know what is going wrong without more information than you have given so far.


No it is not published - I am an early learner


Are you willing to copy and paste the entire (ns ...) form in the file that contains the [myproject.bbb :as abc] expression?


(ns myproject.core (:gen-class) ;;(:import (org.apache.logging.log4j Level LogManager)) (:require [cheshire.core :refer :all] [clj-http.client :as client] [ :as djson] [ :as io] [clojure.pprint :as pprint] [clojure.spec.alpha :as spec] [clojure.string :as string] [myproject.bbb :as abc] )) (abc/dispatch_fn "6738549661") (ns myproject.bbb (:gen-class) (:require [cheshire.core :refer :all] [clj-http.client :as client] [ :as djson] [ :as io] [clojure.pprint :as pprint] [clojure.spec.alpha :as spec] [clojure.string :as string]) (defn dispatch_fn [myval] (do something ..........) )


I had to truncate the code


I am under impression the code calling the defn in the referred file bbb.clj should execute When I call it within bbb.clj it works fine


and what is the error message?


Unhandled clojure.lang.Compiler$CompilerException Error compiling src/myproject/core.clj at (45:1) #:clojure.error{:phase :compile-syntax-check, :line 45, :column 1, :source "/Users/xxxxxx/Google Drive/development/projects/myproject/src/myproject/core.clj"} 6808 clojure.lang.Compiler/analyze 6745 clojure.lang.Compiler/analyze 3820 clojure.lang.Compiler$InvokeExpr/parse Caused by java.lang.RuntimeException No such namespace: abc 221 clojure.lang.Util/runtimeException 7384 clojure.lang.Compiler/resolveIn 7358 clojure.lang.Compiler/resolve 7319 clojure.lang.Compiler/analyzeSymbol 6768 clojure.lang.Compiler/analyze 6745 clojure.lang.Compiler/analyze


if you has an :as abc in the ns block, this error means that the namespace aliased as abc did not compile correctly


and this would happen after reloading - the first time your ns just wouldn't load


Resolved, I had to get out of spacemacs and reload. Followed by updating packages etc. Restart and now it works. No change in code written. there must have been a bug in one of the packages I updated on the weekend

😁 4
👏 4

Thanks for the interest to all

Michael W18:05:20

Is there a way to get all keywords in a map that match a pattern? I have many keywords that start with :subnet_ or :pool_ like ':subnet_id :pool_id :subnet_name :pool_name', etc How can I pull out all the :subnet_* entries?


you can use filter across (keys m) , inside the filter you can use name to get a string form a key, and starts-with or re-matches to find a given prefix



scratch=> (filter (fn [k] (clojure.string/starts-with? (name k) "foo_")) (keys {:foo_a 0 :foo_b 1 :bar_a 2}))
(:foo_a :foo_b)

😂 4

ns:myproject.core ns:myproject.scope I I :require [project.scope :as s] (defn abc [] ,,,) I I (s/abc 123) ;; it works!! ;; (abc 123) ;; it works!! actually it is (abc somenumber) actually it is (abc somenumber) ns: myproject.scope.test I (deftest qwerty (abc 123)) ;; does not work Question---------- for myproject.scope.test do I require [project.scope :as s] thus: (deftest qwerty (s/abc 123)) -OR- do I require [project.scopecore :as c] thus: (deftest qwerty (c/abc 123)) -OR- both?? to make my test execute


at the top - myproject.core should not be able to use abc directly


and no user of myproject.core should be able to use abc as if it were in core - require is not transitive like that


OK so how do access abc. Do I use '(require.... statements? from core


right, if you have :require [myproject.scope :as s] you should use s/abc


I added that in


and this should be done in every ns that wants to call abc directly


I updated my question to reflect that in the interim


c/abc doesn't work, you can only get abc from the ns that defines it


Nevertheless, so whereever I want to access abc I need to state :require [myproject.scope :as s]


right, you can use a different alias of course, but that's the concept


So I have to have :require [myproject.scope :as s] in myproject.test as well


right, usually what we do is pair a test ns to a code ns, and only test one ns per test


What is interesting is that I did include :require [myproject.scope :as s] in myproject.scope.test as well but it does not execute - I get no such namespace


that should be working, you might have some broken state that needs to be reset / restarted


I ran the "test" call in the code ns and it still works. Same with core


Not in the test, yet all have [myproject.scope :as s]


any file that has a valid require should be able to use definitions in myproject.scope, if there's something else wrong you need to describe the specific error because I can't see what the problem is from what you've shared so far


I am learning clojure.testing so it must be my deftest is incorrect. I will have to investigate (deftest aaa ((is (= 0 (s/abc "123")))) fails to work


😁 Now it works!! I give up Thx @noisesmith


you have too many parens around is there btw - remember that clojure doesn't have "free parens" - they change the meaning of something


(x) in clojure is like x() in other programming languages - it means you want to call x


,Funny ting is (deftest azz (is (= 1 1) )) works (deftest aaa ((is (= 0 (s/myproject.scope "123")))))


like I said, (x) means call x


so ((x)) means call x, then call the thing it returns


yes - (s/myproject.scope "123") returns a value


is returns nil, so ((is ...)) is an npe it will probably error, unless the thing you put inside is directly returns a function you can call


so it becomes (is (= - result))


((is ...)) for any ... is an npe as is returns nil


doesn't matter what is inside


oh wait - it returns the thing you check, my bad


so if = returns true, it will blow up because true isnt' a function


is • (is u v op)

Set the value of a var to value of another var with the operation
 applied. Non-relational.
So it seems is is not a t/f test


we want clojure.test/is not clojure.core.logic/is


(ins)scratch=> (doc clojure.test/is)
([form] [form msg])
  Generic assertion macro.  'form' is any predicate test.
  'msg' is an optional message to attach to the assertion.

  Example: (is (= 4 (+ 2 2)) "Two plus two should be 4")

  Special forms:

  (is (thrown? c body)) checks that an instance of c is thrown from
  body, fails if not; then returns the thing thrown.

  (is (thrown-with-msg? c re body)) checks that an instance of c is
  thrown AND that the message on the exception matches (with
  re-find) the regular expression re.


So (deftest azz   (is (= 1 1) ))


right, that's a correct usage of test/is


(deftest aaa   ((is (= 0 (s/myproject.scope "123")))))


that fails because neither true nor false are functions


the extra parens announce that you want to call the return value of is


and = can only return true or false


so = result in (is (true OR false)) which is not allowed


in the context of invocation, neither true or false is valid, correct


the fix is to not use extra parens


parens request invocation


how do you mean


using my example


((f)) error, true isn't a function


yes it is an outcome


"outcome" doesn't mean anything in clojure, it's a boolean


how do i then get is to apply to the state


(=1 1 ) is true


just change ((is ...)) to (is ...) the extra parentheses cause your error


that is a type there is only one set () on outside of is (deftest aaa   ((s (= 0 (s/myproject.scope "123")))) how it got here I dont know


(deftest aaa   (is (= 0 (s/myproject.scope "123")))) how it got here I dont know


fat fingers 😉


if you just evaluate (s/myproject.scope "123") what does that return?


fail cannot find namespace s


no such namespace


yet I have it in the ns


s/myproject.scope looks weird - I don't think it's even possible to have a var with that name


Unable to resolve symbol: scope in this context when I remove the s/


well myproject.scope isn't a var, it's potentially a namespace


what you want is something like s/abc


Guys I have been working on my stuff since 8 a,m BST. I am now whacked and perhaps I am making mistakes now. I appreciate your assistance but I think I need to call it a day and have a kip With a clearer mind Thanks @noisesmith

Patrick Farwick23:05:55

So i have a deps.edn project I am trying to use cljfmt to format. When I run

clojure -Sdeps '{:deps {cljfmt {:mvn/version "0.6.4"}}}' \
  -m cljfmt.main check
it returns lines that are incorrect and also "no such file: project.clj" When I run the same command with fix it just returns the "no such file: project.clj" and does not seem to change the file at all


it puts "project.clj" into its default-paths, which can be changed by providing more args after check / fix


so you could try cljfmt.main fix src test deps.edn

Patrick Farwick23:05:41

++ that did seem to work


anything after fix or check, if present, should be used instead of the default which contains project.clj - for bonus points one could make a PR on the project that doesn't try to access project.clj if it doesn't exist (at least not fail over it...)

Patrick Farwick23:05:01

Looks like there is an open PR that addresses the issue:


wow, nrepl versions 0.7.0 and 0.8.0-SNAPSHOT both crash on ::foo/bar keywords claiming they are invalid


Like repo is to eval just that keyword. Blows up in >0.7.0?


@dpsutton right, but that keyword ::foo/bar is only valid if foo is aliased in the current ns. Regardless, it shouldn't crash the client though.


it's just a syntax error / unable to resolve


Right. The fix sounds difficult. And there’s something similar in piggieback as well. How to read input


if I use lein repl :connect instead of using nrepl directly via clj it works just fine


I thought the ticket said it was only tty


The bencode transport was unaffected


maybe I found a second issue, or maybe clj is somehow using the tty transport the way I invoked it


I problably should have brought this up in #clojure rather than #beginners, but at least I have my workaround