Fork me on GitHub
#beginners
<
2019-12-15
>
matt.wistrand00:12:40

For those of you using Aero (https://github.com/juxt/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?

jysandy06:12:35

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

alidcastano00:12:24

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

alidcastano00:12:26

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

dpsutton00:12:36

I think you want (constantly false)

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: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?

seancorfield02:12:14

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

seancorfield02:12:34

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

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

@ 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

@ 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)); https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval

seancorfield03:12:48

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.

seancorfield03:12:01

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

didibus17:12:34

What do you expext the macro to do?

didibus17:12:45

And why can't a function do it?

vincent.cantin00:12:02

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

alex.lee.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?

hiredman17:12:10

Require is for namespaces

hiredman17:12:50

What goes in project.clj is a maven coordinate

hiredman17:12:57

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

alex.lee.jackson17:12:41

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

ghadi18:12:25

clj-time is deprecated and not recommended fyi

ghadi18:12:06

See its readme

alex.lee.jackson18:12:15

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

seancorfield20:12:02

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