This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-11
Channels
- # aleph (1)
- # architecture (18)
- # beginners (57)
- # boot (13)
- # cider (47)
- # cljs-dev (28)
- # cljsjs (13)
- # cljsrn (39)
- # clojure (258)
- # clojure-greece (16)
- # clojure-italy (2)
- # clojure-miami (1)
- # clojure-nl (9)
- # clojure-poland (15)
- # clojure-russia (369)
- # clojure-spec (53)
- # clojure-uk (49)
- # clojureremote (3)
- # clojurescript (135)
- # core-matrix (1)
- # cursive (11)
- # datascript (3)
- # datomic (4)
- # emacs (12)
- # figwheel (13)
- # hoplon (7)
- # interop (7)
- # jobs-discuss (33)
- # lumo (28)
- # off-topic (15)
- # om (7)
- # onyx (26)
- # pedestal (10)
- # perun (1)
- # planck (10)
- # re-frame (54)
- # reagent (16)
- # ring (5)
- # ring-swagger (50)
- # rum (2)
- # spacemacs (2)
- # unrepl (125)
- # untangled (12)
@agile_geek @yonatanel I’m having to much fun with this. here is my post on The Bridge Pattern! https://drewverlee.github.io/posts-output/2017-4-10-bridge-pattern/
I want to find something that would get me some real experience working in Clojure. Sadly I'm not creative when it comes to side projects. I'm thinking helping to do some open source work, but not sure where to start when looking for a project.
@drewverlee nice use of Klipse! I haven't written a blog on Clojure for about a year but next chance I have I'm going to try and use it.
@drewverlee I'm getting Cannot load script: Error:
in all the klipse boxes.
@yonatanel does that url work for you? (if you click it)
Hi all, I'm trying to pull data from Oracle using clojure.java.jdbc and then output it to csv.
currently I'm using string?
as the predicate function, which results in each column being quoted in the csv
As I'm only looking at the vals from the returned maps, is there a way to specify columns I want quoted, for instance by index, or by doing things differently and using the map keys?
(doto (java.util.Stack.)
(.push "Latest episode of Game of Thrones, ho!")
(.push "Whoops, I meant 'Land, ho!'"))
can anyone tell me how I can use a final class like this? I need to call functions on it like this:
Azure azure = Azure.configure()
.withLogLevel(LogLevel.BASIC)
.authenticate(credFile)
.withDefaultSubscription();
that would likely be
(-> (Azure/configure)
(.withLogicLevel LogicLevel$BASIC)
(.autheticate credFile)
(.withDefaultSubscription))
not 100% certain on LogicLevel$BASIC thoughHaving clojure.spec troubles. Methinks I am missing something... Why do the offical guide's sampling generator examples barf with classpath errors? Found online suggestions to require clojure.spec.test
, but to no avail. Is there a fix so I can play with spec's generators? Here is an example to show what fails.
Modify project.clj to the latest org.clojure/clojure
:
$ lein new app test
$ cd test
$ sed -i -e 's/1.8.0/1.9.0-alpha15/' project.clj
$ lein repl
...
=> (require '[clojure.spec :as s] '[clojure.spec.gen :as gen] '[clojure.spec.test :as st])
=> (gen/generate (s/gen int?)) ;;; from
FileNotFoundException Could not locate clojure/test/check/generators__init.class or clojure/test/check/generators.clj on classpath. clojure.lang.RT.load (RT.java:458)
Need to include test.check in your deps
This is mentioned in the guide
So took out test.check but the FNFE still throws...
=> (require '[clojure.spec :as s] '[clojure.spec.gen :as gen])
nil
=> (gen/generate (s/gen int?)) ;;; from
FileNotFoundException Could not locate clojure/test/check/generators__init.class or clojure/test/check/generators.clj on classpath. clojure.lang.RT.load (RT.java:458)
oh, duh. My bad.... Thanks @alexmiller.
Fixed with
:dependencies [[org.clojure/clojure "1.9.0-alpha15"]
[org.clojure/test.check "0.9.0"]]
When Destructuring, can i have the :as
result contain the default values set in the :or
specification?
@drewverlee No, the :as
part is “as passed in”, without defaults applied.
defn foo [{:keys [a b] :or {:a "a" :b "default"} :as x}] x)
(foo {:a "hi"})
// result => {:a "hi"}
// What i want is {:a "hi" :b "default"}
That can be kinda frustrating at times.
i suppose i just combine the two to get what i want then
What I tend to do in such situations is
(defn foo [x]
(let [{:keys [a b] :as x} (merge {:a "a" :b "default"} x)] x))
i.e., make the defaults explicit and destructure after that
also, almost always if I want defaults it’s worth having a top level def for them - they can serve as documentation for someone setting their options
so keep the defaults outside the function? ok yea, that sounds right.
(def some-defaults {}).
(def foo-defaults {…})
(defn foo "foo on a bar, uses foo-defaults for options not specified" [opts bar] …)
- that way someone browsing api docs or using clojure.repl/doc can figure things out quicker
is lazy-seq
basically always used with cons
to build the sequence? I kinda get lazy-seqs, but I still don't have a really strong intuitive understanding and pretty much all the examples I've seen are of the general shape:
(defn recur-func [a]
(lazy-seq
(cons a (recur-func (f a)))))
yes (or the more advanced chunked version)
I'm a little confused on swap!
and assoc-in
I think. My code almost works, but I can't quite figure out where I'm messing up. I've got a vector of maps, and the value of a key :tables
inside that map is also a vector of maps. I've got a function that looks like (assoc-in (:tables selected-schema-map) [table-index :columns] (query-column-names-and-data-types table-name))
which gives me the proper value for my swap!
. But when I pass the above as the value, let's call it new-data
for simplicity in on my swap as (swap! my-atom assoc-in [schema-index :tables] new-data)
the swap overwrites the :tables
vector (duh) but not with what I expected.
it properly swaps in for the given index what the correct data should be, but instead of merging the previous hash-map with the new one as I would have expected, because the assoc-in
function alone does, it simply keeps the last index swapped in.
I can link someone some actual code or some snippets of what the data looks like so that my question is more clear; I just don't want to litter the channel more than I already have. 😂
assoc-in on (:tables foo) doesn’t return foo
(update foo :tables assoc-in …)
or in a swap!, they stack nicely
(swap! foo update :tables assoc-in ...)
it’s almost like forth
so my confusion in regards to what you're saying @noisesmith is when I do (swap! db-structure assoc-in [schema-index :tables] new-data)
If my atom is [ {:table_schema "vavs", :tables [{ .... }]}]
then isn't assoc-in
[index :tables] targeting that inner vector?
notice you have two different lookups going on - one for getting a value from the atom (at :tables, 8th) and another for a deeper nesting (0, :columns)
I think things will make sense if you reorganize so you only do the nested lookup in one place, so that the update-in returns the whole structure you actually want updated
It took me a bit and I feel silly now, but I got it. Thanks @noisesmith .
well, that’s a sign of learning, if what used to be confusing is now clear
@agile_geek In case your interested in the latest edition of my GOF design patterns in clojure series here is the builder pattern: https://drewverlee.github.io/posts-output/2017-4-11-builder-pattern/ 20 minutes to know what should be done, 4 hours to explain why i think thats implementation and how it relates to FP to OO. Translating these design patterns from the GOF is painful. Anyone is welcome to give feedback on these. I should make a place where people can comment.
Good day #beginners, I'm building a small database system and I'm not sure what's the idiom to structure it:
I have a Serialisation
, Replication
, Query
, State
components, they're mostly protocols / records communicating through core.async channels.
How should I group them into a single DB
object?
@lsenta I'm not sure I follow your meaning, but it's possible you might want to pick up https://leanpub.com/clojurepolymorphism, As it discussed several ways to group functions and there pros and cons