This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-07
Channels
- # bangalore-clj (1)
- # beginners (255)
- # boot (29)
- # cider (16)
- # cljs-dev (13)
- # cljsrn (6)
- # clojure (200)
- # clojure-berlin (1)
- # clojure-dev (13)
- # clojure-dusseldorf (6)
- # clojure-greece (1)
- # clojure-india (1)
- # clojure-italy (1)
- # clojure-russia (33)
- # clojure-spec (28)
- # clojure-uk (27)
- # clojurescript (47)
- # cursive (32)
- # data-science (3)
- # datascript (1)
- # datomic (40)
- # emacs (39)
- # events (4)
- # fulcro (55)
- # graphql (16)
- # immutant (2)
- # luminus (2)
- # lumo (5)
- # off-topic (142)
- # onyx (50)
- # portkey (1)
- # re-frame (45)
- # reagent (80)
- # remote-jobs (2)
- # ring-swagger (3)
- # rum (9)
- # schema (3)
- # shadow-cljs (184)
- # spacemacs (3)
- # test-check (4)
- # unrepl (2)
- # yada (5)
@johanatan you can also use https://github.com/jeaye/orchestra for instrumenting :ret and :fn
what does @ before a variable mean. (let [st @state]...
from the om wiki page. Can't seem to find it googling
A good little example here https://funcool.github.io/clojurescript-unraveled/#atoms
haha yes. It seems the only way would be to know that is is short for deref
clojure has a lot of hard to google usage
the backtick, ->
, ->>
, #(+ 1 %)
, #{}
to name a few
it’s the set primitive
#{1, 2, 3}
is a set with the numbers 1, 2, and 3
#{}
, is the empty set
symbolhound is useful for these: http://symbolhound.com/?q=%40+clojure
oh yea, and #"[a-z]*"
after learning about threading I can't help but get frustrated at c# almost every time i turn the corner at work
there's also a nice list of these: https://clojure.org/guides/weird_characters
looks like I forgot a few
looks like it’s missing the ->
prefix
as well as the map->
prefix
a few people were wondering about that earlier today
those are just a part of the name of a function though, not syntaxes, which is why they weren't included
seems like it is similar to <symbol>?
predicate suffix
https://clojure.org/guides/weird_characters#__code_symbol_code_predicate_suffix
those would be nice additions to that list. Don't know who maintains it so we can recommend the addition?
it's open source: https://github.com/clojure/clojure-site
feel free to send a pr or an issue to update on that repo
also see the threading macro guide https://clojure.org/guides/threading_macros
(defn rx1 [x] x)
(defn rx2 [x] (* x x))
(defn rx3 [x] (* x x x))
(defn hpc [tensor cb]
;; cb :: double -> double
;; cb is called around 10,000,000 times
;; this is a big, hairy function
;; I would prefer to not turn it into a macro
)
(defn h1 [tensor] (hpc tensor rx1))
(defn h2 [tensor] (hpc tensor rx2))
(defn h3 [tensor] (hpc tensor rx3))
Question: is it possible to tell clojure
to inline rx1, rx2, rx3 ?
"Don't worry about it, JVM hot spotting will take
care of it" is a valid answer.@qqq Well, there's :inline
metadata but I don't know how well documented that is, and I suspect it's experimental/subject to change...
@seancorfield: yeah, I read http://bytopia.org/2014/07/07/inline-functions-in-clojure/ ... but there is a comment by @alexmiller at the bottom of the blog post suggesting caution
That was back in 2014 -- and I don't think anything has actually changed since...?
does tat mean "nothing has changed; therefore stable to use" or "alex's caution hasn't changed, still dangerous to use" ? 🙂
The latter
It's worth noting that CLJ-1227 is indicated as being caused by https://dev.clojure.org/jira/browse/CLJ-1330 which is fixed.
I meant "Alex's caution probably still stands but it hasn't been removed yet" 🙂
~(let [(vary-meta foobar# assoc :tag 'long) ...]
this is not allowed -- can I not use foobar# , and have to explicitly use a gensym ?You mean with :inline
?
the #
suffix is just a backtick thing
(context is everything @qqq 🙂 )
I assume that code is inside a macro...?
you have to use a gensym in your example
@matthewdaniel @smith.adriane @tanzoniteblack There is also the Clojure cheatsheet, with the http://clojure.org version here https://clojure.org/api/cheatsheet which has a link to this page that has some other variants that enable searching, but unfortunately not for the special characters. There is a dedicated section of the cheatsheet to most of the special characters you will find in Clojure, near the 'bottom left' of the page. It has links to other docs for most of them, including a link at the top of that section to Clojure guide page linked earlier: https://clojure.org/guides/weird_characters
is anyone familiar with scala interop? I need to construct a case object, but can't figure out how to do this from clojure
try this:
(def case-disabled RackAwareMode.Disabled$.MODULE$)
Haven’t tested that out but basing this on this stackoverflow discussion https://stackoverflow.com/questions/2561415/how-do-i-get-a-scala-case-object-from-javaI need to create one of these case objects: https://apache.googlesource.com/kafka/+/HEAD/core/src/main/scala/kafka/admin/RackAwareMode.scala
(import 'kafka.admin.RackAwareMode$Enforced$)
(kafka.admin.RackAwareMode$Enforced$/MODULE$)
Hey all! I'm trying to rewrite core.async-based code into aleph/manifold one, and can't figure out what would be equivalent for something like this:
(go-loop [x 0]
(if (> x 3)
x
(do
(<! (timeout 1000))
(recur (inc x)))))
the main problem is timeout, I have no idea what's the right way to do it with manifold deferred's: I'm making an http request with aleph and want to retry for a few times with growing backoff. Manifold docs have Thread/sleep
somewhere, but I'm a bit scared about that one. 🙂 Any pointers maybe?@asolovyov maybe manifold.deferred/timeout!
is useful.
;; o (if (p/>= g t) (float 255.0) (float 0.0))
;; o (if (p/< g t) (float 0.0) (float 255.0) )
^-- these two lines should do the same thing right ? I'm doing image processing, getting different results, and completely baffledhttps://github.com/ztellman/primitive-math/blob/master/src/primitive_math/Primitives.java @chrisblom
@chrisblom maybe, but then I have to find deferred to timeout on then...
not really, let's say http://clojure.com responds fast enough, but with an error, and we want to retry it few times in a row with growing backoff
in this case we're doing http/get, and then there needs to be a Thread/sleep or something similar
in current core.async code it looks like this:
(def process-message [...]
(go
...
(when retry?
(<! (timeout next-backoff-ms))
(process-message client url args success? ack-fn async-exception-fn (assoc retry-params :retry-attempt (inc retry-attempt)))))))
tbh, in such a situation i'd just run a function in a java executor, so i can use 'Thread/sleep' safely
@chrisblom hm, that's an option, thanks!
Hi! It seems that the community has pretty much settled on using this convention for test files: http://www.lispcast.com/clojure-test-directory (putting the test files in a separate directory that mimics the same structure as the main project). I find it pretty tedious to mimic the directory structure, and I'd like to have the tests close to the code since I will often look at them in conjunction. Does anyone have any suggestions on how to accomplish this? I would of course like to exclude the test files from production builds.
How deep is your directory structure? o.0 We are normally only creating a couple of extra directories for a new project. Most tooling that creates projects/files, like boot (and I assume lein) can also be make to create the test file in the expected place when you tell it to create the source one...
Not super deep, but I find it annoying in general to have to change the same thing in several places. I also see tests as a form of documentation, and that would be nice to have as close to the code as possible.
if you add the :test
metadata to a function, and that contains something callable, that will be run when you execute clojure.test/run-all-tests
if it contains test/is etc. it will work just like a deftest
I don't think lein test
likes this, but making a task that loads your namespaces and runs clojure.test/run-all-tests is not hard at all - you can even just run your tests from the repl
Why? It's just opening files. Does it really matter where they are? Especially if the structure is the same apart from the first word being src
or test
. You can even shell glob it when opening in most editors. Regardless, that is the same as the Java expectation, and as far as I am aware all tooling expects that structure. You could write a boot task that for example copies files named without _test
into a src
dir under build
with the same structure and ones with _test
into a test
dir under build
and then make all other boot jobs run from that dir with the structure it expects, but that seems like a lot of work. I assume you could do something similar with lein
I find it definitely matters where the files are located when exploring a project. For example, if the tests where located next to the code, I could immediately see if the module I'm currently working on has any tests associated with it by seeing if there is a test file in the module or not. I agree that writing any sort of complex task is not worth it, however.
I have seen several Clojars deployment tutorials that claim you can enter a public GPG key in your profile there, but I do not see this anywhere in the site. What a I missing?
as far as I know this feature is out of date - it wasn't being handled properly(?) and nobody had the expertise or energy to manage it correctly iirc
Hi, someone work with Immutant 2 and protobuff. When i try to convert stream -> clojure hash map (in safary) i catch
java.io.IOException: UT000034: Stream is closed
but in chrome/firefox/ie all work fineif you want to use clojure.test on a macro, i gather you'd have to do something like (eval '(my-macro ...))
if the macro could throw an assertion and your is
test is in fact testing for thrown?
, right?
@ajs Clojars dropped using your GPG key - it was used to verify that the artifacts you uploaded were signed by you when trying to promote to the "releases" repo, which was removed. See https://github.com/clojars/clojars-web/issues/415 for rationale
Ah, that is a different case - that's lein trying to use gpg to sign your artifacts before sending them to clojars
Have you looked at https://github.com/technomancy/leiningen/blob/stable/doc/GPG.md?
You can disable signing by setting :sign-releases
to false for clojars: https://github.com/technomancy/leiningen/blob/stable/doc/GPG.md#signing-a-file
I believe this should do it (in project.clj): :repositories [["clojars" {:url "
is that an actual url with /repo
or do i put one in there for my own app? i've tried this both ways and get weird errors about "missing connectors" and stuff
my data_readers.clj looks like this:
{monitor/date monitor.utils/parse-date}
I start a REPL, refresh (as in, I load all the namespaces) and this happens:
user> #monitor/date "2016 3 1"
IllegalStateException Attempting to call unbound fn: #'monitor.utils/parse-date clojure.lang.Var$Unbound.throwArity (Var.java:43)
user> @#'monitor.utils/parse-date
#function[monitor.utils/parse-date]
why?You still need to require monitor.utils before you use the tagged literal, otherwise Clojure can’t find the constructor function
Thanks for this, I was actually including monitor.utils and still had problems. It turns out that it was because I was using CIDER’s refresh functionality (C-c C-x in emacs) instead of clojure.tools.namespace.repl/refresh
! Still unsure as to why, but at least I found a way around it
how does one supress the default logger with jetty, which is set to info,
2017-11-07 13:33:20.868:INFO::main: Logging initialized @3013ms
..etc...
@hlolli it depends on the logging lib you're using - with timbre you can configure it directly in Clojure, clojure.tools.looging uses underlying java libs which usually means using properties or XML files for configuration
yes it's a mystery to me what logging lib is printing this, since this is always by default with jetty, has never bothered me. Im creating terminal app and it's distracting. Looking at ring/ring-jetty-adapter dependencies, there's no logging lib there, guessing it's coming from org.eclipse.jetty/jetty-server "9.2.21.v20170120". So maybe there's some java option I could set?
ok this fixed it :jvm-opts ["-Dorg.eclipse.jetty.LEVEL=OFF"]
in case someone googles the slack logs.
@curlyfry you can technically add tests in any file, including the file with the implementation
the reason they're in a different directory is so that you can exclude them from production deployments
Thanks for the reply! I know that's why it's in a different directory. My question was wether it's possible to exclude them anyway without too much hassle.
I was commenting a few days ago that I was having trouble calling some Clojure functions (i.e. implemented in Clojure) from my Java app. I managed to make some progress, and to call a few functions from clojure.core -- but I still haven't been able to call any Clojure functions that I've implemented myself in my own Clojure libraries. It always results in an error saying the function is unbound.
I'm suspecting that perhaps the clojure.core functions that I call are all static - and thus defined.. and perhaps the reason I'm not able to call my own functions is related to my 'main' being a Java 'main' instead of a Clojure 'main'.. and perhaps this is resulting in the Clojure functions never getting bound in the first place due to some binding step getting skipped? (since this would only occur automatically with a Clojure main?) Anyway - trying to come up with theories/solutions.
"clojure.core is the only namespace loaded by default" - that helps explain what I'm seeing a lot. On Friday, I had difficulty calling 'require' in particular for some reason -- but I'll get back to trying that right now.
` String mumbojumbo_ns_name = System.getProperty("mumbo.jumbo.system"); IFn require = Clojure.var("clojure.core", "require"); Object mumbojumbo_ns_sym = Clojure.read(mumbojumbo_ns_name); Object ns = require.invoke(mumbojumbo_ns_sym);`
but keep getting: Exception in thread "main" java.lang.Exception: prefix cannot be nil, compiling:(NO_SOURCE_PATH:0:0)
When I try the code you suggest, I get this error (I've been seeing this over the past few days as I try it):
Exception in thread "main" java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Character
Clojure.var("clojure.core","require").invoke(Clojure.var("clojure.core","symbol").invoke("your-ns-here"))
@aconanlai There's a #vscode channel -- no idea how active it is tho'...
Hello guys, I am looking for a solution for background jobs which should survive Tomcat server restart or moving application to another VM on AWS. I found https://github.com/metametadata/byplay which looks really promising because we are already using Postgres on separate machine and jobs shouldn't do any heavy lifting (mostly tasks like send email to a user after 2 weeks and stuff like that). Do you think it's feasible to use DB as a persistent storage for jobs or should I look somewhere else?
there are far worse ways to do that, I am unfamiliar with byplay, but it sounds perfectly reasonable
the idea of long running transactions doesn't sound great, in the past I've worked on systems that used postgres advisory locks instead, but I am not sure that is any better
Long running transaction are the only part I am worried about because there can be possibly hundreds of jobs waiting to execute and I am not sure how it can affect performance of the DB
Storing it's not the issue I thought that lot of opened transactions might be
generally job systems won't leave a transaction open. workers claim jobs, then relinquish them in two separate tx'es
having the number of open transactions scale with the number of stored jobs would be the result of a very special system
Ok, I've probably misunderstood the byplay documentation. It seems like worth trying to me, I am building a system with hundreds of users at maximum who generates some background tasks from time to time so it should scale
Style Question: If I have global-level configuration data, how should I make that accessible to the functions in my program? I can think of 4 ways:
1) Pass ALL configuration data in a single map as an argument to each function that needs some of the config data.
2) Pass ONLY the configuration values that are NEEDED as individual arguments to each function
3) (declare)
some vars for configuration, then (defn)
all the functions that need access to them, then start runtime, then populate the config vars
4) Start program, read in config values, then use (let)
to hold the config values while using (defn)
to create closures around the config values as needed.
I’m sure there are other ways, too.
Does this make sense?
Does anyone have any wisdom for me here?
I do 1) in combo with using stuartsierra/component which I use to also pass all stateful shared resources in the same map with the config
i’ve been using https://github.com/weavejester/environ
Personally my latest project is using https://github.com/tolitius/cprop to manage the values (via merging environment, system properties, & a config file of defaults) and storing the result loaded at known times via https://github.com/tolitius/mount
@smith.adriane I use environ too, but for example if a library needs config, I’d rather pass the config in from my app, rather than putting environ in the library
and it turns out I have a few libraries that need config
libraries should avoid imposing too much structure on the consumers of the library
it would be annoying if a library forced you to use environ
I haven’t used any of those. I’ll go check them out.
Thanks
It’s interesting to me that this is such a fundamental task in any programming language, but there are so many libraries to achieve this
I’m thinking, “shouldn’t there be an obvious, idiomatic clojuric way to do this?”
but each of the four ways I mentioned definitely have their own specific tradeoffs
there are lots of different tradeoffs
if clojure was just used for one specific domain, then you might seem more convergence
4) is definitely not “clojuric” at all
we don’t do much data hiding
right, that seemed hideous as I was typing it
for a similar reason, 2 is OK, but most people would prefer 1 to it
and 3 is really just accessor methods, which are also not “clojuric” if we are going to use that word
so that leaves 1, with a maybe on 2
and you don’t need a library to do 1 or 2 - it’s a simple convention using immutable data
i tend to write small apps, but I typically use a form of 3
(def db-conn (env :db-info))
and then have a query function that uses the global db-conn
do you use ALL-CAPS in those var names or some other convention to mark them as “coming from outside of this function” ?
or do you just remember “db-conn” is a global thing ?
Tell me about why all caps is a bad idea
I’ve been using clojure for about 4 years now off and on, but I feel like I still have a lot to learn
is there some kind of community-approved style guide that I would want to look at?
cool, thanks!
tell me all about it, bronsa
most of the application code doesn’t use the db-conn
cause it’s not passed around
the application code will just do (query "select 1")
i realize that might be a controversial way to do it, but most apps never outgrow by needing multiple database connections within the same app
and it’s easy to change once/if that’s the case
We used to do 3) when we started out using Clojure (2011) but we've switched to 1) (or 2) for subcomponents) with Component. Much nicer.
Our app has five or six DB connections @smith.adriane 🙂
So we have a Database Component with a xyz-db
element for each DB connection (we create connection pools at startup).
also I take it back, 3 isn’t accessor methods (I misread) - but it is singletons which can be a problem
Yeah, 3) is very problematic. I speak from (painful) experience 🙂
and yeah, 3 is semi-popular in clojure apps, but also a common source of problems which leads to messy refactors from 3 to 2 or 1
this is part of why people are skeptical of mount btw - it does some of the same things as eg. component or integrant without providing the biggest benefit which is not locking you into singletons, which is a hard thing to fix later if your app design is built around it
Is anyone able to run lein-marginalia
aka lein marg
against their codebase using [org.clojure/clojure "1.9.0-RC1"]
? The last clojure that lein marg
seems to work fine with is [org.clojure/clojure "1.8.0"]
in my codebase.
@aaelony I assume you're getting an error? Probably from the spec checking on some macros. Probably Marginalia has illegal ns
syntax that "just happened" to work on 1.8 and earlier...
Or more likely, some library it depends on, having looked at the source...
clj-uuid states that its squuids encode retrievably the posix time at which they were generated
anyone know of code to retrieve the posix time? i can figure out the bit math but thought i’d ask first
@aaelony I created a new empty Leiningen project, updated Clojure to 1.9.0-RC1 and added lein-marginalia "0.9.0"
and was able to run it -- but maybe the problem you encountered isn't triggered on an empty project? Can you provide more detail about the problem you are having.