This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-30
Channels
- # announcements (15)
- # beginners (99)
- # boot (15)
- # cider (105)
- # cljdoc (2)
- # cljs-dev (17)
- # clojure (132)
- # clojure-conj (1)
- # clojure-dev (5)
- # clojure-italy (19)
- # clojure-losangeles (2)
- # clojure-nl (20)
- # clojure-spec (70)
- # clojure-uk (50)
- # clojurescript (153)
- # core-logic (9)
- # cryogen (4)
- # cursive (6)
- # datomic (40)
- # duct (5)
- # figwheel-main (10)
- # fulcro (245)
- # hoplon (1)
- # jobs (3)
- # leiningen (12)
- # mount (8)
- # nrepl (11)
- # off-topic (1)
- # pathom (16)
- # pedestal (3)
- # planck (17)
- # re-frame (3)
- # reitit (8)
- # shadow-cljs (64)
- # spacemacs (3)
- # specter (20)
- # tools-deps (21)
e.g.:
;; without macro
(some.namespace/foo)
(some.namespace/bar)
;; with macro
(open 'some.namespace
(foo)
(bar))
I don't know of anything like that off hand, but you can do require
and specify an alias name with :as
as short as one character
You could also use a let
to create names inside its body, e.g. (let [foo some.namespace/foo bar some.namespace/bar] (foo) (bar))
I guess it might not be terribly difficult to write a macro that generated let
statements like that for you, auto-generating the pairs like foo some.namespace/foo
for all public Vars inside of the namespace some.namespace
I'm making some requests on twilio api
I'm thinking about that is a problem to not use future / async with that stuff
In pratical way how I differentiate the needs for doing async channels or use future on mine requests?
@d.ian.b I usually stay away from async stuff until I have performance or latency issues with the synchronous version
I did it, it was a sintax mistake on the another call in http kit, sorry
Http kit make the future/deref part of processing
@audrius the usual idea is to modulus by 5 and then look at that value. Are you familiar with modulus and do you know how to look up whether clojure has a version of it?
@UCQ2HRAA0 one way would be this:
(defn div-by5? [x] (= 0 (mod x 5)))
I added nrepl to project.clj and ~/.lein/profiles.clj (under :plugins
and under {:user {:plugins
.. However, when I run lein repl
, lein is still using nrepl 0.2.12
how do I get lein to use new nrepl
i believe the PR to update lein to new nrepl has been accepted there just hasn't been a release ๐
oh @manas.marthi run lein nrepl
not lein repl
(note the Nrepl not repl)
Hi @dpsutton yeah tried it now...
but repl prompt is not showing up
i thought it was slow
but it never showed
"nREPL server started on port 65135 on host localhost - <nrepl://localhost:65135>"
I see this
but the prompt did not come up
I added the nerepl lien plugin to project file and lein profile as well
as i was not sure how it will pick
{:user
{
:plugins [
[lein-ancient "0.6.10"]
[venantius/ultra "0.5.1"]
[lein-count "1.0.2"]
[walmartlabs/vizdeps "0.1.6"]
[luminus/lein-template "2.9.10.74"]
[nrepl "0.4.5"]
[cider/cider-nrepl "0.18.0"] ;;0.12
[refactor-nrepl "2.4.0"] ;;2.2
[nrepl/lein-nrepl "0.2.0"]
]
}
:dependencies [
[cider/cider-nrepl "0.18.0"] ;;0.12
]
:plugins [
[nrepl "0.4.5"]
[cider/cider-nrepl "0.18.0"] ;;0.12
[refactor-nrepl "2.4.0"] ;;2.2
]
oh did not format
use `
got it..tx..
added the deps under user as well as global.. random guesses here..
tried
lein nrepl :blocked false
and added nrepl,nrepl-lein, cider-nrepl, refactor-nrepl all to project also.. (not knowing how it works)still no luck
I am using jdk10 and clojure 1.10.0-beta4
ok.. let me try clojure 1.8.0
tried java 8 and clojure 1.8.. no luck ๐ฅ
looks like it is running in headless mode
There are any way to set a precision/round for a float value?
For example, I have 34.922
. But I want 34.92
I can do
(read-string
(format "%.2f" 34.922))
But I don't know if is it a best practice to transform into a string and then into a float againat what point do you want that precision? many times just in the UI for display but you want to keep the full precision throughout the calculation.
the correct ui output? then the correct output is a string "3.14". If testing calculations it would seem that you want the "real" value
Something like this
(defn my-f
[float-value]
(format "%.2f" float-value))
(is (= "34.93" (my-f 34.932)))
or
(defn my-f
[float-value]
(read-string
(format "%.2f" float-value)))
(is (= 34.93 (my-f 34.932)))
also, strings behave differently from floats in important aspect for you: 3 == 3.00 but "3" != "3.00"
But if I want to use the return value not just for UI, but also as a parameter for another function (to use in some calculation)
So if you were not aware, floating point numbers do not give exact results from arithmetic operations, except in unusual circumstances. Depending upon the kinds of tests you want to write, this can make it tricky to have repeatable tests across code changes.
i.e. you may have test failures because a result came out 3.999999998 instead of 4.0
unless you write tests that expect an appropriate amount of difference between expected and actual results, where "expected amount" may very well depend on what you are doing.
If I have 3 different src files for my simple app: core
, persistence
, and calculation
.
The core.clj
file require the other 2.
(ns rachar-conta.core
(:require [rachar-conta.calculation :refer :all])
(:require [rachar-conta.persistence :refer :all]))
If I want to do an "integration" test, do I need to require the persistence
and calculation
namespaces on my core_test.clj
?
Something like this..
(ns rachar-conta.core-test
(:require [clojure.test :refer :all]
[rachar-conta.calculation :refer :all]
[rachar-conta.persistence :refer :all]
[rachar-conta.core :refer :all]))
Or can I just require the core
namespace and it will require all other namespaces?source code: https://github.com/LeandroTk/rachar-conta
If you require core
then you will only be able to call functions from core
- you won't be able to call the other namespaces directly.
:refer :all
does not mean that the functions from other namespaces also exist as functions of the core namespace - it just means that from the core namespace you can refer to them without a prefix.
use of :refer
is discouraged in modern clj and :refer :all
is pretty much an antipattern. just a code style note for as you learn
I'd make an exception for a test ns - it should be OK to :refer :all from the specific namespace being tested
otherwise use :as, and then use the prefix defined by as
i prefer not to for autocompletion reasons but that's a valid place where they make sense
(as shown in @dpsuttonโs example above)
@neural.works.com go read some code of yours that uses refer all and try to reason about the code and where functions are defined. It makes a world of difference in readability.
@neural.works.com there's the clojure style guide but i'm not too sure how authoritative that is but its probably worth a glance. I think it includes arguments for its conventions so its at least good to show why even if you remain unconvinced. But in general reading code on github or without an editor hooked up should convince you of the reason to not use :refer :all
I used to be in the "`:refer :all` is okay in test namespaces" camp but I've changed my opinion after several years and a lot of (test) code.
I will sometimes :refer
specific symbols that would otherwise be a bit harder to read with an alias, but mostly I try to stick to :as
.
one other thing is shadowing and the dreaded unshadowing. Ie, namespace foo/bar defines thing. You import it using :refer :all so rather than foo.bar/thing you just have thing
in your namespace.
it's not just about clobbering though (there's :rename if that's the main concern) - for me it's about knowing where some definition came from
so if you define a thing
in your current namespace you have a collision and you can't refer to something. Also, if you name a parameter (defn function [thing] (stuff thing))
and then rename it to (defn function [different-name] (stuff thing)
` you won't get an error because thing
is a function not undefined now
this just bit me because someone destructured something as uuid
and a refactor removed that binding so i was calling transaction function with the function uuid rather than the now-non-existant identifier of an object