Fork me on GitHub
#beginners
<
2018-06-08
>
ryan.russell01100:06:59

I do have to say... the people helping out in here for us Clojure newbs are refreshing. Not a judgmental comment anywhere that I've seen, and everyone has been so patient and willing to walk beginners through questions. It is a stark contrast from what I've been used to where asking a question could get your head ripped off... (for example.. the Arch community is notorious for this... at least from what I've seen..).... anyway... kudos to the more experienced Clojure devs in here!! 🙂

michael.gaare00:06:49

I got banned from arch irc channel before even saying anything :rolling_on_the_floor_laughing:

ryan.russell01100:06:27

haha.. doesn't surprise me. I've been running arch for about 4 years now... and have never even tried to interact with their community. Great distro (imo)... but yeah... not even worth trying to be a part of the community.

seancorfield00:06:26

@ryan.russell011 The Clojure community has always had the guidance to be polite, respectful, and welcoming — that comes down from Rich Hickey himself, as well as reinforced by all the Cognitect (formerly Relevance) and Clojure/core folks. The conferences have had a Code of Conduct for several years — and this Slack also has a Code of Conduct — so there’s a culture of treating people decently. And we also deliberately set up a separate #beginners channel here for folks new to Clojure and those folks who opt-in to help them (it’s why there’s nearly 13K people in #clojure and only 4.5K here). There’s also a #programming-beginners channel for folks who are new to programming as a whole.

ryan.russell01100:06:18

that is super amazing! Well done!

seancorfield00:06:58

Besides, how can we take over the world if we don’t encourage more people to use Clojure? :world_map:

kyselyradek01:06:56

How many of you started with Clojure (or other functional-first lang) after feeling burnt-out on imperative? 🤔

ryan.russell01101:06:08

I actually got some Haskell experience first. After that, when I went back to Java, I noticed Java felt clunky and I actually noticed how verbose it was. I still feel like it is a good language, but it has its purpose and I felt like most the time it just wasn't needed for most the things I was doing. I then started looking into Scala, but it also felt too Java-like... Clojure has a simple elegant-ness that I am very much enjoying and I am hoping to one day be proficient with it lol.. and hopefully be able to contribute to this channel as a person that can answer questions!

seancorfield01:06:01

My arc is a bit unusual I think… I did some Lisp and other FP stuff at university but my professional career was assembler, COBOL, C, C++, Java, ColdFusion(!), Groovy, Scala, and finally Clojure (starting in 2010). So it was more returning to my roots. But, yeah, I was pretty tired of OOP and dealing with the boilerplate associated with that sort of approach.

kyselyradek02:06:13

Question: how do you require relative namespaces? “Programming Clojure” goes through first imports and mentions > If you see the first 10 Fibonacci numbers as listed here, you have successfully installed the book samples. But doesn’t mention anything about how to install them..

noisesmith02:06:54

"install" is a weird term for namespaces - clojure looks up code that's required via the classpath

noisesmith02:06:25

either it's in a jar which is on CP, or there's a directory on the CP with your code in a nested folder relative to the namespace definition

kyselyradek02:06:49

And what is classpath, please?

noisesmith02:06:22

it's the places a jvm looks for things, a start-time parameter

noisesmith02:06:38

if you use leiningen, it's leiningen's job to set classpath for you

kyselyradek02:06:16

How do I even retrieve the current classpath?

kyselyradek02:06:37

I found java -cp ... sets it, but that doesn’t help

noisesmith02:06:45

in the repl, (System/getProperty "java.class.path")

kyselyradek02:06:07

(System/getenv "CLASSPATH") I guess

noisesmith02:06:31

it can be set from command line and not just env though, use getProperty

noisesmith02:06:58

but if you are using a tool, it manages that for you

noisesmith02:06:08

its config decides where source files should be

kyselyradek02:06:14

Aah, I see now

noisesmith02:06:48

to get more specific I need to know more about your toolchain - leiningen project, boot? raw command line calling java?

noisesmith02:06:17

OK, the default with lein is for source to be under a src directory

noisesmith02:06:28

foo.bar ns would be in src/foo/bar.clj

kyselyradek02:06:52

But does that apply to REPL as well?

noisesmith02:06:10

if lein starts clojure, that's where it wants your source

kyselyradek02:06:18

Aah, I see now

noisesmith02:06:18

regardless of repl, run, or build

noisesmith02:06:35

but there's a config in project.clj that can be modified

kyselyradek02:06:10

Okay, okay, now I get it

duminda02:06:13

Hi guys, As you can imagine, I am a beginner. I am trying to take up Clojure. Managed to convince my boss to let me work on a web service + frontend in Clj/Cljs (Compojure, re-frame). It is a small project and I haven't messed up much so far. I am not a hugely talented programmer like many people here so some of the stuff I mess up because I don't have good understanding. I am just an average programmer (So, you will never find me at Google or Facebook.) I would like to get engaged with any open source project that can use some man hours. Testing, documenting, it doesn't matter. Can you suggest a project been done by decent human beings (Not 200 IQ assholes) which can use some help from a beginner like me? I can probably put in five or six hours a week, and I would like to contribute in any way I can. I think I would learn better and faster that way too.

sundarj04:06:13

one that immediately comes to mind is the app that displays the logs for this Slack: https://github.com/clojureverse/clojurians-log-app

duminda04:06:58

I will have a look. Thanks

sundarj04:06:13

no worries 🙂

kyselyradek02:06:33

I am used to relative imports from JS, but this is based on (CLASS)PATH

kyselyradek02:06:05

Okay, thanks a lot! I’ve been literally playing with cding for 30 minutes trying to figure out how to import those files 😂

noisesmith02:06:06

@kyselyradek yes, it works just like a path in your shell - it controls which places you get code from

kyselyradek02:06:14

Yup, thanks, really! 😄 This channel is a blessing 🙏

noisesmith02:06:12

one advantage to that method of doing things is it means you can use code that is inside a zip file (a jar is a zip with a special set of contents), or even directly from a URL

noisesmith02:06:41

and it won't want to load things just because they are in the current directory (which I guess is a kind of security feature)

kyselyradek02:06:50

Actually, weird thing, it works on clj repl but not using lein repl

ryan.russell01102:06:08

quick question... is the caret before Currency doing actual type checking? or is just metadata to describe what currency should be (without actually type checking)?

(defrecord Currency [divisor sym desc])
(defrecord Money [amount ^Currency currency]

noisesmith02:06:38

type hints are not type checks

noisesmith02:06:48

they are an assistance to the compiler

noisesmith02:06:07

with records they are not needed

ryan.russell01102:06:22

this example is from Clojure Applied

lockdown-02:06:33

so the book is wrong?

lockdown-02:06:44

or there might be another reason?

ryan.russell01102:06:56

I think he is just saying ordinarily they aren't needed... which doesn't mean you can't have them

ryan.russell01102:06:21

Not that there is a "wrong" or "right"

lockdown-02:06:49

seems noise then?

noisesmith02:06:19

the compiler doesn't throw errors for nonsense type hints in most cases, and I guess there might be a case where the compiler could make better numeric code if it knows something about what's in Currency...

ryan.russell01102:06:33

and this: https://www.quora.com/When-should-I-use-type-hinting-to-make-Clojure-statically-typed (don't let the title mislead you... the first response clarifies a poorly written question here)

ryan.russell01102:06:23

so.. here is the whole record from the book

(defrecord Money [amount ^Currency currency]
  java.lang.Comparable
    (compareTo [m1 m2]
      (validate-same-currency m1 m2)
      (compare (:amount m1) (:amount m2))))
I am assuming the type hint is used here because of the interop with java.lang.Comparable

lockdown-02:06:08

@noisesmith but is that type hint telling the compiler what's in Currency?

noisesmith02:06:22

well that code isn't even using currency so there's not enough there to really say - the definition of Currency is what would tell it what's expected to be in there

lockdown-02:06:00

he pasted the definition of Currency before

lockdown-02:06:12

(defrecord Currency [divisor sym desc])

noisesmith02:06:21

well he posted Money before too and that was empty

noisesmith02:06:18

I'm assuming clojure applied is building up to something interesting where there's a point to the type hint, I'd have to double check it's been ages and there's parts I only skimmed

ryan.russell01102:06:05

lol... to alleviate some of the confusion about my amazing copy/paste skillzzzz

ryan.russell01102:06:46

obviously there is more... I was just curious as the the functionality of the ^ lol... the actual code is pg 8 in the Clojure Applied book

ryan.russell01102:06:46

obviously there is more... I was just curious as the the functionality of the ^ lol... the actual code is pg 8 in the Clojure Applied book

sundarj04:06:03

just so you know, this falls under the metadata syntaxes, see here: https://clojure.org/reference/metadata

lockdown-02:06:27

@noisesmith so in general you don't need type hints for defrecords because the clojure compiler already knows about its methods?

noisesmith02:06:35

right, and the way defrecords and protocol methods dispatch it doesn't need the same kind of expensive reflection it needs to use on classes and interface methods from native java

lockdown-02:06:16

hmm, slack was down for me

stardiviner03:06:37

Is it necessary to clear ~/.m2/ old (deprecated) dependencies? And How ?

noisesmith04:06:57

you can safely delete anything in m2 as long as you only install by normal methods

noisesmith04:06:18

it's a cache, you'll just need to wait for the stuff to download again

noisesmith04:06:46

if you use mvn or lein etc. to install something local by hand, it will be missing until you do that again, for obvious reasons

duminda04:06:29

Any way to say (require [korma.core :refer :all :except update])?

stardiviner04:06:41

@noisesmith I see, thanks

noisesmith04:06:33

I don't know of a way to figure out which versions your projects use or not, but deleting the whole thing is a thing people do

noisesmith04:06:04

@duminda you can use :rename to give update a name that doesn't clash with clojure

noisesmith04:06:34

or use a db library that has been updated since the clojure.core/update function came out :P

duminda04:06:08

@noisesmith: "or use a db library that has been updated since the clojure.core/update function came out :P" Any suggestion?

mario.cordova.86204:06:29

I am learning about providing support for inserting Clojure maps into JSON columns in a postgres db. An article explain that, its as easy as extending a protocol. It provides an example

(extend-protocol jdbc/ISQLValue
    clojure.lang.IPersistentMap
  (sql-value [value]
    (doto (PGobject.)
      (.setType "json")
      (.setValue (json/write-str value)))))
I have a few question that I am going to try and articulate.

noisesmith04:06:28

@duminda honeysql and hugsql were both kept up to date last I checked - at least more active than korma

mario.cordova.86204:06:38

The protocol is implemented by someone and in that example listed, it is being called by the JDBC driver?

noisesmith04:06:48

clojure.java.JDBC is invoking that protocol method on its argument

noisesmith04:06:13

by extending that method to map, that tells clojure.java.jdbc what to do when it sees a map

stardiviner08:06:23

1. Unhandled org.sqlite.SQLiteException
   [SQLITE_ERROR] SQL error or missing database (incomplete input)

stardiviner08:06:40

Why it report missing database?

sova09:06:18

incomplete input = SQL error methinks

sova09:06:03

is there a reason your query vector is 2 strings instead of one?

ajay.rivendell09:06:27

I think you need to mention a database in the configuration [db] and that database must be already created ... here is sample configuration (def mysql-db {:dbtype "mysql" :dbname "clojure_test" :user "clojure_test" :password "clojure_test"})

sova09:06:22

maybe (sql/query ["" ""']) is happy with 2 strings or however-many, after i have read the docs it seems like that would work. check out: https://en.wikibooks.org/wiki/Clojure_Programming/Examples/JDBC_Examples

ackerleytng13:06:31

Is there a way to undo evaluation of all the forms in a file? Sort of like un-intern defs and stuff

jumar13:06:41

@ackerleytng You can (remove-ns (.getName *ns*))

ackerleytng13:06:20

Oh nice, thanks! And then restart for anything in that namespace?

jumar14:06:28

What do you mean by restart?

jumar14:06:31

Just re-eval.

ackerleytng14:06:22

nice. thanks!

ackerleytng13:06:39

Without restarting the repl?

manutter5113:06:17

@ackerleytng You can do this, maybe this is what you’re looking for? (require :reload '[my.thing :as thing])

manutter5113:06:13

It’s not quite what you asked for, and it sometimes leaves things hanging around that you want to get rid of, but it’s useful in a lot of cases.

manutter5113:06:21

There’s also https://github.com/clojure/tools.namespace but I haven’t used it personally.

jumar14:06:11

I'm not sure why but c.t.n.r/refresh tends to break things in our project but I've never been able to figure out why

:error-while-loading c.b.c-m-a-test
#error {
 :cause "namespace 'c.b.c-m-a' not found"
 :via
 [{:type clojure.lang.Compiler$CompilerException
   :message "java.lang.Exception: namespace 'c.b.c-m-a' not found, compiling:(c/b/c_m_a_test.clj:1:1)"
   :at [clojure.core$throw_if invokeStatic "core.clj" 5807]}
  {:type java.lang.Exception
   :message "namespace 'c.b.c-m-a' not found"
   :at [clojure.core$apply invokeStatic "core.clj" 659]}]
 :trace
 [[clojure.core$apply invokeStatic "core.clj" 659]
  [clojure.core$load_libs invokeStatic "core.clj" 5925]

jumar14:06:49

After that I have to restart the repl.

manutter5113:06:46

seems like it might have something you could use, though.

ackerleytng05:06:31

hmm i was looking for a workflow tip sort of, to avoid having to restart the repl

manutter5100:06:33

In that case (require :reload '[some.ns :as s]) might be your best bet. It reloads the namespace and redefines any functions you have changed in the underlying source (but not anything defined with defonce, and I think also not any protocol handlers). That's not quite what you originally asked for, so maybe that's not what you wanted, but that was as close as I could come, and I hope it's useful.

cbowdon18:06:45

Is there a test coverage tool that supports boot? I can only find Cloverage, which apparently only supports lein

phil67219:06:57

I couldn't find one when I looked, would like to help out with that project sometime. Thinking of https://github.com/cloverage/cloverage/issues/211 and boot support would be nice too

seancorfield19:06:54

Many Leiningen plugins can be run directly from Boot, and creating a boot-* version of most lein-* plugins isn't too hard... take a look at http://corfield.org/blog/2017/11/17/boot-localrepo/ for my path through that with lein-localrepo...

seancorfield19:06:55

And since the blog post doesn't link to the repo https://github.com/seancorfield/boot-localrepo

cbowdon21:06:39

Cool, thanks both!