Fork me on GitHub
#beginners
<
2017-04-11
>
Drew Verlee02:04:16

@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/

emperorcezar03:04:39

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.

agile_geek07:04:18

@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.

yonatanel09:04:14

@drewverlee I'm getting Cannot load script: Error: in all the klipse boxes.

dominicm09:04:49

@yonatanel does that url work for you? (if you click it)

yonatanel10:04:32

Ok, now the blog post looks fine

danp15:04:16

Hi all, I'm trying to pull data from Oracle using clojure.java.jdbc and then output it to csv.

danp15:04:55

Using clojure.data.csv for that purpose.

danp15:04:16

I have the following code...

danp15:04:37

currently I'm using string? as the predicate function, which results in each column being quoted in the csv

danp15:04:23

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?

timo15:04:01

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

noisesmith16:04:18

that would likely be

(-> (Azure/configure)
   (.withLogicLevel LogicLevel$BASIC)
   (.autheticate credFile)
   (.withDefaultSubscription))
not 100% certain on LogicLevel$BASIC though

timo09:04:02

did work except the LogLevel$BASIC thing

timo09:04:31

LogLevel/BASIC worked

johnny.martin17:04:05

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

Alex Miller (Clojure team)18:04:15

Need to include test.check in your deps

Alex Miller (Clojure team)18:04:36

This is mentioned in the guide

johnny.martin19:04:57

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)

johnny.martin19:04:54

oh, duh. My bad.... Thanks @alexmiller.

johnny.martin19:04:17

Fixed with

:dependencies [[org.clojure/clojure "1.9.0-alpha15"]
                 [org.clojure/test.check "0.9.0"]]

Drew Verlee20:04:45

When Destructuring, can i have the :as result contain the default values set in the :or specification?

seancorfield20:04:27

@drewverlee No, the :as part is “as passed in”, without defaults applied.

Drew Verlee20:04:41

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"}

seancorfield20:04:42

That can be kinda frustrating at times.

Drew Verlee20:04:48

i suppose i just combine the two to get what i want then

seancorfield20:04:51

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

seancorfield20:04:28

i.e., make the defaults explicit and destructure after that

noisesmith20:04:32

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

Drew Verlee20:04:57

so keep the defaults outside the function? ok yea, that sounds right.

Drew Verlee20:04:17

(def some-defaults {}).

noisesmith20:04:38

(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

rgdelato20:04:20

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

Alex Miller (Clojure team)20:04:28

yes (or the more advanced chunked version)

mbcev21:04:04

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.

mbcev21:04:32

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.

mbcev21:04:17

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. 😂

noisesmith21:04:33

assoc-in on (:tables foo) doesn’t return foo

noisesmith21:04:49

(update foo :tables assoc-in …)

noisesmith21:04:03

or in a swap!, they stack nicely

(swap! foo update :tables assoc-in ...)

noisesmith21:04:12

it’s almost like forth

mbcev21:04:59

that assoc-in produces the vector of maps that I want

mbcev21:04:52

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)

mbcev21:04:37

If my atom is [ {:table_schema "vavs", :tables [{ .... }]}] then isn't assoc-in [index :tables] targeting that inner vector?

mbcev21:04:31

on the swap, I mean, not the other assoc-in

mbcev21:04:40

I mean, I guess clearly it isn't. But that's where my confusion is.

noisesmith21:04:10

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)

noisesmith21:04:42

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

mbcev22:04:41

It took me a bit and I feel silly now, but I got it. Thanks @noisesmith .

noisesmith22:04:27

well, that’s a sign of learning, if what used to be confusing is now clear

Drew Verlee23:04:25

@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.

lsenta23:04:46

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?

Drew Verlee23:04:45

@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