This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-15
Channels
- # adventofcode (10)
- # babashka (28)
- # beginners (27)
- # calva (5)
- # cljs-dev (7)
- # clojure (134)
- # clojuredesign-podcast (3)
- # clojurescript (7)
- # cryogen (3)
- # cursive (12)
- # datomic (8)
- # devops (1)
- # figwheel (1)
- # fulcro (1)
- # graalvm (2)
- # jobs (6)
- # malli (2)
- # off-topic (43)
- # pathom (1)
- # reagent (4)
- # shadow-cljs (11)
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?
@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
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])
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?
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.
@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]
@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));
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
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.
I need to generate optimized code which uses React.createElement.
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?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
ah ok! thank you. looks like I needed to use clj-time.core as the namespace
@UQV85KLF5 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).