Fork me on GitHub
#beginners
<
2017-08-02
>
petr.mensik07:08:08

Hey guys, this should be easy one but I can't figure it out - how to get value of this enum with Java interop? https://pdfbox.apache.org/docs/2.0.4/javadocs/org/apache/pdfbox/pdmodel/PDPageContentStream.AppendMode.html I tried PDPageContentStream/AppendMode/APPEND and PDPageContentStream$AppendMode/APPEND but none of these worked 😕

donyorm07:08:07

@petr.mensik should be PDPageContentStream$AppendMode/APPEND, not sure what's going on there. Can you post example code that's not working? What exact error are you getting?

jumar08:08:49

@petr.mensik you have to either import the inner enum class or use fully-qualified name:

(import org.apache.pdfbox.pdmodel.PDPageContentStream)
org.apache.pdfbox.pdmodel.PDPageContentStream

clojure-repl-experiments.experiments> (org.apache.pdfbox.pdmodel.PDPageContentStream$AppendMode/APPEND)
#object[org.apache.pdfbox.pdmodel.PDPageContentStream$AppendMode 0x7215768f "APPEND"]

clojure-repl-experiments.experiments> (PDPageContentStream$AppendMode/APPEND)
CompilerException java.lang.RuntimeException: No such namespace: PDPageContentStream$AppendMode, compiling:(*cider-repl clojure-repl-experiments*:65:39) 

clojure-repl-experiments.experiments> (import org.apache.pdfbox.pdmodel.PDPageContentStream$AppendMode)

org.apache.pdfbox.pdmodel.PDPageContentStream$AppendMode
clojure-repl-experiments.experiments> (PDPageContentStream$AppendMode/APPEND)
#object[org.apache.pdfbox.pdmodel.PDPageContentStream$AppendMode 0x7215768f "APPEND"]

noisesmith13:08:23

you don't need parens around an Enum - for historical reasons it's allowed, but parens indicate you are calling something and you don't call an enum

noisesmith13:08:57

eg. would you use Math/PI or (Math/PI) - both work

petr.mensik08:08:32

Thx, already solved with importing the enum

tdantas08:08:27

do you guys knows any “blog app” repository ? need to see a “real” application with authentication

donyorm08:08:55

@oliv This is probably not the best example, but yogthos' blog at http://yogthos.net has some authentication (it looks like it's outsourced, but I'm not sure). https://github.com/yogthos/yogthos.net

pithyless08:08:05

I’m looking for an idiomatic way of “threading” a large map of calculations, where each step depends on the previous:

(-> {}
    (assoc :foo (init-foo))
    (assoc :bar (init-bar with-foo))
    (assoc :baz (init-baz with-foo-and-bar)))

;;; So basically something like:
(let [x   (assoc :foo (init-foo))
      x'  (assoc :bar (init-bar x))
      x'' (assoc :baz (init-baz x'))]
  x'')

sundarj08:08:15

so something like

(as-> {} bar
  (assoc bar :foo (init-foo))
  (assoc bar :bar (init-bar bar))
  (assoc bar :baz (init-baz bar)))

pithyless09:08:12

Thanks @U61HA86AG, I forgot as-> could be used for this 🙂

sundarj09:08:34

anytime 🙂

schmee09:08:22

just for fun, here is a version with reduce (that I haven’t tested :D):

(reduce (fn [acc [k f]] (assoc acc k (f acc))) {} [[:foo init-foo] [:bar init-bar] [:baz init-baz]])

sundarj09:08:00

@U3L6TFEJF no Specter? 😉

schmee09:08:21

haha, well now I have to 😄

sundarj09:08:52

hahahah im not sorry

pithyless08:08:56

The thread of course doesn’t work and the let is subpar, I don’t necessarily want to give each step a unique name. Any suggestions?

tdantas08:08:12

checking it out @donyorm

tdantas08:08:12

seems to be a simple web server serving static assets

donyorm08:08:13

There's some sort of comment system at the bottom of posts. It may just be a disqus tie-in. I'm not sure how disqus works

tdantas08:08:12

yeah, I’m looking for a “real” app written in clojure with authentication and some SQL database

tdantas08:08:20

just to get the feeling

Sam H09:08:39

@oliv There was a talk at EuroClojure, discussing auth libs: https://speakerdeck.com/joyclark/simple-and-secure She linked a WIP example app using the libs: https://github.com/innoq/quackers

grounded_sage10:08:15

how can I represent a semi colon in a string in Clojure?

donyorm10:08:59

@grounded_sage Just put it in a string, it's not recongized as a comment when you do that

grounded_sage10:08:40

my text editor says otherwise. With parinfer its fudging everything

Sam H10:08:02

most likely an editor bug, what’s the code snippet and which editor are you using?

grounded_sage10:08:23

[:div { :dangerouslySetInnerHTML {:__html "<form name=\"contact\" 
                                                      data-netlify=\"true\" 
                                                      action=\"thank-you\"
                                                      style=\"flex-direction: row
                                                             display: flex>
                                                             color: white
                                                             font-size: 18px\"
                                                  <div style=\"\"
"}}]])
  

grounded_sage10:08:53

needing to do dangerous inner html as Rum or React messes the provided data attributes by netlify

grounded_sage10:08:23

ok cheers. Lame but thanks. Might just have to open up emacs to do the fixes. Unless I can get it working without the innerhtml

Sam H10:08:10

supposedly fixed in v0.22.4 but henrik was already on that version ¯\(ツ)/¯

grounded_sage12:08:43

Turns out I didn't need it anyways. Netlify had a great article on how to do it inside of React based applications. Was easier for me because I also do SSR. Was also a pop up so I did a sneaky z-index and hidden hack

Joe G13:08:42

hey all, as i continue to learn clojure, i want to contribute to some open source projects. does anyone know of any projects?

Drew Verlee16:08:00

After a month of trying to make ruby and python behave like declarative languages (or maybe i should say clojure) I have learned their is a wide gap between a FP first language and a FP maybe language.

daiyi16:08:03

hey! so I'm trying to add stuff into maps of sets, e.g:

(def data {:places {:na #{"california" "oregon"}
                    :eu #{"berlin"}}})
I want to: 1) add something to a set. this works:
(update-in data [:places :eu] conj "hamburg")
2) add something to a set, but it doesn't exist yet. this works but seems silly:
(update-in data [:places :sa] clojure.set/union #{"medellĂ­n"})
What's the best way to do these two things?

dpsutton16:08:49

instead of conj, use (fnil conj #{})

dpsutton16:08:54

https://clojuredocs.org/clojure.core/fnil The long and short is when there's a nil value (ie, get returns nil) use this value instead. And that value you supply is #{} empty set

dpsutton16:08:28

(update-in {:a {:b #{:set}}} [:a :c] (fnil conj #{}) :new-val)
{:a {:b #{:set}, :c #{:new-val}}}

daiyi16:08:40

magic, thanks!

triwave17:08:02

Hey guys, new to clj and was wondering if anyone had any recommendations and or resources to get started with web development in clojure. I love the sound of figwheel / live page reloads on code saves.... curious what the best practices look like / what to use to get started.

triwave17:08:11

Perhaps a boilerplate or something would be a good place to start

donyorm17:08:13

@triwave Check out http://www.luminusweb.net/ (channel at #luminus), it's a great resource for beginning web development

triwave17:08:37

@donyorm - awesome, I did read up on that, and it looked really promising.. Ill check it out

donyorm17:08:10

Also http://www.braveclojure.com/ is a great resource for Clojure in general, and if you haven't read some sort of book on Clojure, I'd recommend starting there

triwave17:08:40

Yeah, I'm in the middle of reading that resource now. Its very straightfoward and an easy read.

donyorm17:08:12

It's a great book. Let me know if you need any help with luminus, I've been working with it a fair amount recently. Yogthos (the developer) is also really active in that channel

triwave17:08:37

awesome! thanks

triwave17:08:18

I feel as a newbie to clj, I may benefit more from researching, deciding and utilizing various packages myself, it might help with understanding everything. Once I get that knowledge, Ill likely look towards luminus more

donyorm17:08:23

That makes sense. Luminus can seem like a bit too much black magic at first 🙂

bfabry17:08:03

yeah that's what I'd do if I wanted to learn the web stack, I'd build up a toy app pulling in each thing and gluing it together myself from scratch

hmaurer18:08:05

@triwave o/. Do you have a specific goal in mind while learning clojure? e.g. are you more interesting in Clojurescript? Backend web applications (e.g. API)? Or else?

hmaurer18:08:04

If web development if your goal, I would play with Ring at first. No other lib. It’s what I am currently doing and I find it very helpful to get a grasp of the basics

itaied19:08:40

For testing, what should I use, humane-test-output or ultra?

seancorfield19:08:25

@itaied You mean "in addition to clojure.test?"

noisesmith19:08:22

for the most part I find clojure.test sufficient, expectations has some nice features though

seancorfield19:08:34

(no idea what "ultra" is... for what it's worth, at work we use clojure.test for some of our tests -- ones that are more procedural in style and need to intersperse assertions throughout the code -- and we use Expectations for most of our "unit tests")

noisesmith19:08:46

also the lein difftest plugin is often useful

itaied19:08:34

okay just to make myself clear, my tests are written in clojure-test, but to display better output there are these two additional plugins

bfabry19:08:35

ultra is a leiningen plugin that attempts to pull together all the leiningen plugins most people will want

dominicm20:08:29

Ultra uses humane test output

bfabry21:08:49

ah cool. I was wondering. I couldn't find a reference in project.clj so assumed it was something else

bfabry19:08:48

one of the things it does is make lein test's output much nicer. another thing that does that is humane-test-output

athomasoriginal23:08:20

Hey all, I am trying to better understand segmented namespaces. As best I can understand, the following folder structure is NOT a segmented namespace

starter_kit
  ├── src
  │   └── app
  │       └── core.cljs
  └── static

athomasoriginal23:08:32

as opposed the this next one which is

athomasoriginal23:08:48

starter_kit
  ├── src
  │   └── app
  │       └── starter_kit
  │           └── core.cljs
  └── static

athomasoriginal23:08:57

is the above correct?

mobileink23:08:20

what do you think the namespaces are here? it's going to depend on what you soecify as the root dir.

athomasoriginal23:08:58

Good point. The root dir in both examples is starter-kit

athomasoriginal23:08:40

Further, in this, I am trying to understand segmented namespaces and how they relate to folders

mobileink23:08:52

probably not. you would normally specify src as the root dir for eval. so app.core would be the ns for 1st example.

mobileink23:08:37

your 2nd example has a problem. a dash in an ns translates to underscore in path - you want starter_kit. that gives you an ns with 3 segs.

mobileink23:08:50

i'll let you take a geuss

athomasoriginal23:08:44

Hmmm, I guess to reframe the question, for me, it's not so much the ns, but which one of the above organizational structures is preferred in clojure/clojurescript?

mobileink23:08:50

matter of taste. the only "rule" i know of is to avoid single-segment nss in cljs. which is not really a rule, just a strong recommendation.

mobileink23:08:37

your top level starter_kitcan be anything - it's outside of scope. your project name and namespaces need not be related.

athomasoriginal23:08:05

So, if I understand correctly, both of the above examples are fine, a matter of taste, because they avoid single-segmented ns, but I would be breaking best practices if I did something like this:

starter_kit
  ├── src
  │   └── core.js

noisesmith23:08:59

an aside, but also "core" is severely overrated as a name

mobileink23:08:18

i believe that is correct. it would work, until not. google around and you can find some (brief) explanations of why single-seg nss are best avoided.

noisesmith23:08:48

it was introduced by leiningen as an auto generated name as a way to avoid single segment namespaces but still auto generate a file structure (inspired by clojure.core of course)

noisesmith23:08:40

on the jvm, there are a few contexts where namespace automatically becomes a package, and "top level packages" break in weird ways

mobileink23:08:54

@noisesmith: avoid in clojure too? i thought it was just cljs.

athomasoriginal23:08:06

Interesting. Are there any suggested alternative to core. This does seem to dominate the example projects I have seen

noisesmith23:08:08

it's an even bigger problem in jvm clojure

noisesmith23:08:40

@tkjone if you run lein new it generates foo/src/org/me/foo.clj

mobileink23:08:20

by now core.cljs (`core.clj`) is a pretty well-established convention, but it is not required.

noisesmith23:08:35

it's a bad convention

athomasoriginal23:08:07

could you expand on that a little, @noisesmith?

athomasoriginal23:08:48

p.s. thank you both for being so helpful @mobileink and @noisesmith

noisesmith23:08:56

it's a placeholder auto-generated by a tool that has no smart way to pick something better

noisesmith23:08:19

the namespace can just have a meaningful name, there's no generic answer to what that name should be though

noisesmith23:08:52

but I like the java-ish url like naming, and if my project is foo, I put the main ns in src/org/noisesmith/foo.clj then I put helpers in src/org/noisesmith/foo/...

mobileink23:08:08

i find it is often the case that i need some ol' name, no real semantics except "start here". i like kernel or driver, but coreworks just as well.

mobileink23:08:28

@noisesmith agreed, that's my prefered arrangement.

noisesmith23:08:24

the heirarchy implies that everything in dir foo/ is an implementation detail of foo.clj

didibus18:08:45

Hum, I wouldn't have thought that. I guess its the java background, I'd expect the sub foo package to contain things like public pojos used by foo, and pubkic exceptions, etc. So if it was Clojure, I would more assume that the public interface for foo is broken up over many namespace.

donaldball21:08:49

Some like to use an impl subdirectory to clarify when that’s the case

athomasoriginal23:08:33

@noisesmith does src/org/noisesmith/foo.clj breakdown for larger clojurescript projects? I am just learning clojurescript, but I come from large React applications and in that world the entry is index or app - you could do more specific, but it almost does not have that much extra meaning either way

noisesmith23:08:27

there should be exactly one place where that full path matters, right?

noisesmith23:08:56

and I'm primarily talking about libraries, apps can be much more flexible and idiosyncratic

mobileink23:08:15

i've also done the opposite:

src/foo/bar.cljs ;; implementation 
src/foo/bar/core.cljs ;; driver 

noisesmith23:08:37

and that's a valid interpretation of what "core" means, and the fact that it can mean both "x" (the core entrance point) and "the opposite of x" (the core of functionality things are built in) is a decent argument against the term core

didibus18:08:35

I think often core is both those things. But I kind of like what you're saying. I might start having a main and a core.

noisesmith23:08:56

leiningen puts -main in core, clojure puts that in main and puts the language standard functions in core

mobileink23:08:21

will probably switch from core.cljs to driver.cljs

noisesmith23:08:05

anyway, sorry for the big derail it's a "thing" for me

mobileink23:08:57

names matter

didibus18:08:45

Hum, I wouldn't have thought that. I guess its the java background, I'd expect the sub foo package to contain things like public pojos used by foo, and pubkic exceptions, etc. So if it was Clojure, I would more assume that the public interface for foo is broken up over many namespace.