Fork me on GitHub

I just got started with clojurescript and Reagent recently. I am trying to update two atom during the on-click event handler. But only one of the atom is being updated.

(defn set-state [result metric-name]
  #(reset! s/metric-bmi-index "sdfsd")
    (= metric-name "imperial") #(reset! s/imperial-result result)
    (= metric-name "metric") #(reset! s/metric-result result)))

(defn button-helper [weight height type f bmi-name]
  (let [bmi-result (f weight height)]
    [:input {:type "button"
             :value type
             :on-click (set-state bmi-result bmi-name)}]))
This #(reset! s/metric-bmi-index "sdfsd") never updated the atom. If i move it to the bottom of the function then it executed but the other one does not. Is there a way to update both atoms? Am i missing something here.


@prabhath6 #(...) is a function -- a value -- it doesn't evaluate what's in the parens because you're not calling it.


Remove the # and it will work.


Thanks will give that a try.


Which clojure library is great for Redis?


@stardiviner We started off with Carmine but switched to Redisson (because we needed Redis Cluster support).


@prabhath6 Now I look at your code in more detail, you need a bit of a restructuring there. You are conditionally returning one of two functions, but you actually want to return a single function that does the conditional work, right?


You want something like this:

(defn set-state [result metric-name]
  (fn []
    (reset! s/metric-bmi-index "sdfsd")
      (= metric-name "imperial") (reset! s/imperial-result result)
      (= metric-name "metric") (reset! s/metric-result result))))


When you call (set-state ...) you want to get back a single function (fn [] ...) of no arguments. When that function is invoked, you want it to reset! the BMI, then either reset! the imperial result or the metric result.


cool, this what i exactly needed. Thanks for the help


So, I've been looking for an excuse to move my blog from Google's platform to GitHub or GitLab Pages. I've been a huge fan of GitLab ever since we started using it at work. Given that I also wanted an excuse to do more with Clojure, I chose Cryogen as the Static Content Compiler. Here's what I ended up with: No customizations yet, but it's a good start!

馃憤 8
Bobbi Towers04:08:04

Thanks! I tried to do that awhile back and gave up because I couldn't get the CI configuration right. Following your guide worked perfectly, and now I feel silly!

Drew Verlee02:08:34

really basic clojure script question. There is (.foo) which I believe gets the property foo's value and calls it like a function. Then (.-foo) which just returns the properties value. What is (-foo) then?


(-foo) is used in a few different places


it鈥檚 often an idiom used when defining protocols


-foo also pops up when you use the .. macro


(.. foo -bar -baz) is the same thing as (.- baz (.-bar foo))


actually, to correct myself, I think that often -fn-name is used for private-ish functions in general, not just protocols


if that makes sense?

Drew Verlee02:08:01

I'm confused, so it isn't part of js interopt?


if you see it called like (-foo bar) then I don鈥檛 believe so


do you have an example you鈥檙e seeing it in?


yep, so you鈥檒l see at the top of the file:

(ns ajax.edn
  (:require [ajax.interceptors :refer [map->ResponseFormat]]
            [ajax.protocols :refer [-body]]


the -body method is a part of the AjaxResponse protocol. it鈥檚 not interop syntax

Drew Verlee02:08:20

Ah ok. That makes sense, I should have looked further.


馃槃 it鈥檚 okay. it鈥檚 a bit confusing how much syntax Clojure has sometimes, it鈥檚 hard to know what鈥檚 a special built-in form vs. what鈥檚 not

馃憤 4

I recently found out that @ is hard-coded in the clojure compiler 馃樀


I鈥檓 seeing references to :jvm-options in a project.clj Is there an equivalent way to specify JVM options when using the new CLI tools?


This article is a decent reference for special characters in Clojure: The Clojure cheat sheet has them listed in the bottom left, with very brief descriptions of each:


I see I can alias them, then include them in my command line with -O, but can I simply have them apply by default?


so I deleted a bunch of files from the .m2 directory, now when I run the command clj I get the error

Error: Could not find or load main class clojure.main
I reinstalled clojure and still does not work. Any ideas?


I am not 100% familiar with all the inner working of the clj script, but I think if you delete your /.clojure/.cpcache directory and its contents, as well as /.m2 and its contents, the next run of clj script appears to re-fetch them.


@ryan.russell011 If that doesn鈥檛 work, try running with -Sforce. I ran into the same problem


@andy.fingerhut wiping the .m2 and the .clojure directories triggered clj to refetch the dependencies needed.


Yes, -Sforce seemed to help in my little bit of testing as well.


@b-paul Thank you for the tip... if I run into issues and wiping the two directories doesn't work, I'll give that a shot as well. :thumbsup::skin-tone-3:


so it kind of seems to me that deps.edn is the way to go... this was a conversation in here a long time ago as well..... wishing there was more beginner friendly documentation for it though 馃槙


I鈥檓 trying to use the Instapaper API in a Clojure project ( and it uses xAuth to get an access token. I鈥檝e tried using the clj-oauth library and it has a function called build-xauth-access-token-request but I have no idea how to use it. Any suggestions on how I solve this?


@samarthkishor1 I think that is a typo on the instapaper docs


have you tried normal oauth?


Hi, I could do with a clue as to what is going on here. I'm trying to automate the title field of a ring-swagger setup. So far I have been hand editing the title so that my dev version carries a different title to the production version that I have running in the background. This is the start of the swagger services definition in

(defapi service-routes
  {:swagger {:ui "/swagger-ui"
             :spec "/swagger.json"
              {:version "1.0.1"
               ;; Switch to correct title before lein uberjar
               ;; TODO Automate this so swagger page always shows dev or prod version
               ;;:title "Photo API"
               :title (:title env)
               :description "Access a mongo database containing details of photos"}}}}
I have added an extra field, :title to the env setup provided by the luminus scaffolding. It all works fine from the repl in the namespace. I can see my new :title field by doing (:title env) at the repl prompt. However the swagger front page just shows Null for the title. Providing it with a string as per the commented out line above the :title (:title env) shows the string as expected. Am I doing something stupid here?


that sounds like what i had when i didn't mount/start the env component


It's getting started, the env info shows up fine in the repl, and the port number the server gets started on comes from env too.


This is awesome! An Animated Introduction to Clojure

馃槂 4
馃槑 4

Cool! Very helpful

metal 4
Karol W贸jcik10:08:10

Hi all! Is there some easy way to take always 3 elements from the channel no less no more?

Karol W贸jcik10:08:16

Or to process the channel in the way that 3 elements are grouped to the sequence. Now I'm trying to achieve it with atoms but I'm looking for more idiomatic way 馃檪


(partition-all 3) is the transducer you're looking for.

鉂わ笍 4

But the last partition may contain fewer items


It's getting started, the env info shows up fine in the repl, and the port number the server gets started on comes from env too.


Howdy! Over the past year or two I鈥檝e been learning about functional patterns and loving them in JavaScript land. Recently started reading The Joy of Clojure and gotta say it鈥檚 up there with some of the most exciting programming books I鈥檝e read, so super excited to be learning my first functional language! Any companion material to JoC you guys would recommend to a Clojure/FP n00b?


i really enjoyed working through clojure for the brave and true


Joy of clojure is pretty much jumping in the deep end. I wouldn't recommend it as a first book. I quite liked "Programming Clojure" and "Clojure Programming". Also "Web Development with CLojure"


do you think is worth to learn Common Lisp or other lisp dialects to help with clojure (and FP in general)?


Potentially unpopular opinion- I would say no, don't do that. Everyone can learn what they want to learn, of course, but IMHO the "lispyness" of Clojure is less salient a feature than immutability- which it shares with non-lisp functional languages like Haskell- and its opinions about data- which are subtle and best understood in contrast to languages that depend on types. Common Lisp has a ton of confusing (for beginners) historical cruft. Scheme/Racket are conceptually lovely but depart significantly from Clojure, which is more about pragmatic tradeoffs, an approach it shares with other "industrial" languages. The feature Clojure shares with other lisps- macros- should be rarely used in pragmatic, industrial Clojure.

馃憤 4

I am a hard-core Lisper. Just Learn Clojure(tm). It will get you accustomed to the vital Lispy qualities of Clojure: every form returns a value; no static types; interactive; and the parens are in the right place. With CL you will get a Lisp-2, which changes a lot but will slow you down on Clojure.

馃憤 8

Thanks for the replies. I was imagining that lisp could help me with the structure of the solutions written in clojure which are different from OOP or imperative-style. I wanted to get more exposed to this kind of thinking. However, makes sense to focus on clojure and just get all experience from that.


@U0FF3A4V6 why macros are not so common in industrial Clojure?


I happen to be the God of Common Lisp Macros and I think CLJ being a Lisp-1 (and the keyword fn being so easier to type than lambda) eliminates most of the code simplification need for which I used macros.


Yeah, in Clojure there almost always is a non-macro solution, which will almost always be easier for readers to understand and reason about.


"industrial" -> solve for lowest abstraction load.


lol. I had just started to make my whish list in Amazon and the book 鈥渕aster macros in clojure鈥 was on the list鈥 馃槂


Absolutely! 馃檪 Nothing wrong with learning and deepening. But like other artifacts produced in a commercial rather than artistic context, the range of the "language" used in "successful" artifacts- whether it's visual language in film, human language in books or articles, or something made by an industrial programming team- is most often best constrained to be consumable by the widest audience, and to introduce the fewest risks and least edge cases.

馃挴 4

It's worth learning other lisps for their own sake, or just for curiosity, but I don't see any great advantage in learning another lisp to help with clojure. Having said that its always good to know a few languages.....


@forrest.akin SICP and the companion lecture series are amazing I started reading the Joy of Clojure as my first Clojure book too, love it so far. I think I didn't find it as intimidating because I watched pretty much every talk about Clojure under the sun 馃檪

aw_yeah 4

Yeah, I've watched so many Rich Hickey videos at this point that it doesn't feel foreign or intimidating at all, and I actually find it resonates with me on so many levels hahaha


common lisp is worth learning if only to experience the debugging and how it compares to clojure 馃槈 #goals


Is the debugging better or worse in common lisp? Because I have found Clojure鈥檚 debugging to be godawful 馃槃


hey guys, one quick and probably dumb question I鈥檓 using the cats from funcool and to get used to the library I鈥檓 doing some experiments I鈥檝e created the follow dumb sum

(defn sum-3 [a b c]
  (+ a b c))
and I鈥檓 trying to apply using fapply
  (maybe/just sum-3)
   (just 1) (just 2) (just 3))
but not having success with that , do you guys have any experience with cats ! with single arguments ( using inc for instance ) I鈥檓 able to use properly
(m/fapply (just inc) (just 2))


@oliv okay this was confusing, since I鈥檝e never used cats before. but it looks like fapply calls the function like this: (((f 1) 2) 3)


hey @lilactown, what is f ? my dumb-sum function ?


so it鈥檚 calling your sum-3 function like: (((sum-3 1) 2) 3)


you鈥檒l want to curry it


 (maybe/just (m/curry sum-3))
 (maybe/just 1) (maybe/just 2) (maybe/just 3))


was trying to use the regular partial function


thanks mate !


forgot the 鈥渓ifted鈥 world


I get the below error on line #3 in the code. Does anyone know what is wrong with the code? I tried out (defn arr [4 3 2 1]) (arr 0) in the REPL, and that seemed to work. IllegalStateException Attempting to call unbound fn


for is not a loop, and def doesn't deal in local names


Thanks! I keep going back to OOP's way of thinking..


I am a hard-core Lisper. Just Learn Clojure(tm). It will get you accustomed to the vital Lispy qualities of Clojure: every form returns a value; no static types; interactive; and the parens are in the right place. With CL you will get a Lisp-2, which changes a lot but will slow you down on Clojure.

馃憤 8

Help a Java noob: I have an XHR wrapper library in Clojars. I am using it in a tutorial and need to hack it a bit. I can hack and push to Clojars, but ugh. Or I can symlink in checkouts. Or鈥 can I hack and lein install? Leading to this question: does a lein installed version completely shadow Clojars? So if I forget the install and just go back to hacking and deploying, I will need to鈥lein uninstall`?


If your project name (in project.clj) has a different name / version, there will be no conflict.


But if I am just hacking and the name/version stay the same, I have to think the lein install version will forever shadow the Clojars. Maybe I should just get used to bumping the version 鈥 but then the clutter on Clojars will be insane.


lein install is local if I recall correctly, while lein deploy goes to clojars


So I would have to remember to change the dependency of the project that is using your library.


I think I just talked myself into using checkouts, and Googling lein uninstall. 馃檪


Sounds like a situation to use a SNAPSHOT version @hiskennyness


I am on SNAPSHOT. I see that let鈥檚 me push the same version to Clojars and be noticed. But I do not type very well and cannot figure out the mechanics not to be prompted for credentials so I just go with checkouts. Yes, I am lame. :face_with_rolling_eyes: