Fork me on GitHub

For those of you using Aero ( for configuration, do you use #profile within a single configuration file, or do you maintain per-environment configs and then load the appropriate file based on the specified environment profile?


@UGTAV6LR2 I use #profile within a single configuration file, because I think repeating configuration keys in different files is error prone.


if I'm passing an optional function as an argument and want that optional function to just return false otherwise, how can I make it so I don't have to specify all the arguments that function takes in the default declaration? so I'd like to do something like this:

(defn foo [] 
 ([s] (foo s #(identity false)))
  ([s bar?] (if (bar? s) s nil)))
but i'm receiving multi arity exception. so instead i have to make the inline function declares its args:
(defn foo [] 
 ([s] (foo s (fn [_] false))
  ([s bar?] (if (bar? s) s nil)))


i wouldn't even mind listing out the optional args but then i get linter errors so instead in second example i use underscore


I think you want (constantly false)

👍 4
Vincent Cantin02:12:36

Hi, I have a question on advanced use of macros and don’t know if it is possible (in CLJS preferably, or in CLJC/CLJ). • In my use case, the users are describing web components using data structure. • Some components refer to others via keywords as id. • In order to output some render code in JS, I need my macro to access all those data structures at the same time. Is there a way to get the value of all the data of those components without forcing the user of the macro to write them all at the same place?

(defc component-a 'data-a)

(defc component-b 'data-b)

(def my-components [component-a component-b])

;; Does not work, the macro only get 'my-components
(def-optimized-react-render-fns render-fns my-components)

;; Does work, the macro get all the data, but the user has to write them all here, it is not convenient.
(def-optimized-react-render-fns render-fns ['data-a 'data-b])

Vincent Cantin02:12:34

I found something called definline in the docs, but did not understand how to use it yet. Would it be useful here?


@U8MJBRSR5 No, definline isn't going to help you here.


If you use a function, instead of a macro, you'll get the evaluated version which seems closer to what you want here?

👍 4
🎉 4
Vincent Cantin02:12:31

Yes, using a function would definitely work, as the parameters would be evaluated and I would have access to the aggregated data structure of all the components. But then … I would not be able to use the result as source code that the CLJS compiler would compile.

Vincent Cantin02:12:38

@U04V70XH6 In my imagination, I was hoping to use definline inside the defc macro so that [component-a component-b] would be expanded to ['data-a 'data-b]

Vincent Cantin03:12:59

@U04V70XH6 Using a function, as you say, is a solution. I can generate JS code as a string and use JS’s eval() to make JS accept it as code. eval('function foo(n) {return n * n;}'); console.log(foo(3));


I try to consider macros as the "last resort" and always try to solve the problem with functions first. You can't always, but a lot of time you can -- more than most people think, I suspect.


After all, the first rule of macro club is: don't use macros 🙂

🙂 4

What do you expext the macro to do?


And why can't a function do it?

Vincent Cantin00:12:02

I need to generate optimized code which uses React.createElement.

Alex Jackson17:12:49

hi folks, I'm having what I suspect is a Leiningen or environment issue but I'm having a hard time figuring out what is going on. My dependencies in my project.clj file are getting downloaded and appear to exist on my class path. however, when I try to include them through a require statement, either as part of (ns) or just a straight up (require)

(require '[clj-time :as t]) 
Execution error (FileNotFoundException) Could not locate clj_time__init.class, clj_time.clj or clj_time.cljc on classpath.
here is my project.clj file
(defproject test_project "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url ""}
  :dependencies [[org.clojure/clojure "1.10.0"]
                 [clj-time "0.15.2"]]
  :main ^:skip-aot test_project.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})
I am able to import the clj-time library if I create an empty folder with a deps.edn file that has that dependency defined and then run the repl from that folder. Any thoughts on how to troubleshoot?


Require is for namespaces


What goes in project.clj is a maven coordinate


The namespace names will be something different and you will have to look at the documentation for the libraries your using to find the namespaces it provides

👍 4
Alex Jackson17:12:41

ah ok! thank you. looks like I needed to use clj-time.core as the namespace


clj-time is deprecated and not recommended fyi


See its readme

Alex Jackson18:12:15

thanks. that was just what I was using as an example


@UQV85KLF5 FWIW, the clj-time README shows how to require the library but, as Ghadi says, it's is deprecated and we recommend Java Time instead (I'm one of the clj-time maintainers).

👍 4