This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-02
Channels
- # beginners (118)
- # boot (73)
- # cider (2)
- # cljs-dev (65)
- # cljsrn (18)
- # clojure (49)
- # clojure-argentina (4)
- # clojure-italy (19)
- # clojure-portugal (1)
- # clojure-russia (1)
- # clojure-spec (34)
- # clojure-uk (102)
- # clojurescript (202)
- # code-reviews (3)
- # core-async (5)
- # cursive (11)
- # datomic (25)
- # emacs (1)
- # graphql (22)
- # hoplon (6)
- # keechma (59)
- # leiningen (10)
- # luminus (31)
- # lumo (78)
- # off-topic (141)
- # om (32)
- # om-next (2)
- # onyx (6)
- # parinfer (55)
- # pedestal (3)
- # protorepl (3)
- # re-frame (8)
- # reagent (8)
- # ring-swagger (1)
- # rum (20)
- # specter (1)
- # sql (5)
- # test-check (11)
- # vim (13)
- # yada (7)
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 đ
@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?
@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"]
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
eg. would you use Math/PI
or (Math/PI)
- both work
Thx, already solved with importing the enum
do you guys knows any âblog appâ repository ? need to see a ârealâ application with authentication
@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
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'')
so something like
(as-> {} bar
(assoc bar :foo (init-foo))
(assoc bar :bar (init-bar bar))
(assoc bar :baz (init-baz bar)))
Thanks @U61HA86AG, I forgot as->
could be used for this đ
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]])
@U3L6TFEJF no Specter? đ
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?
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
yeah, Iâm looking for a ârealâ app written in clojure with authentication and some SQL database
@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
how can I represent a semi colon in a string in Clojure?
@grounded_sage Just put it in a string, it's not recongized as a comment when you do that
my text editor says otherwise. With parinfer its fudging everything
[: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=\"\"
"}}]])
needing to do dangerous inner html as Rum or React messes the provided data attributes by netlify
@grounded_sage seems like a bug in atom: https://clojurians.slack.com/files/henrik/F6EHK6HHT/screen_shot_2017-07-27_at_16.04.08.png
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
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
hey all, as i continue to learn clojure, i want to contribute to some open source projects. does anyone know of any projects?
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.
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?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
(update-in {:a {:b #{:set}}} [:a :c] (fnil conj #{}) :new-val)
{:a {:b #{:set}, :c #{:new-val}}}
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.
@triwave Check out http://www.luminusweb.net/ (channel at #luminus), it's a great resource for beginning web development
@donyorm - awesome, I did read up on that, and it looked really promising.. Ill check it out
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
Yeah, I'm in the middle of reading that resource now. Its very straightfoward and an easy read.
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
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
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
@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?
@triwave there's a good book on the topic https://pragprog.com/book/dswdcloj2/web-development-with-clojure-second-edition
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
@itaied You mean "in addition to clojure.test
?"
for the most part I find clojure.test sufficient, expectations has some nice features though
(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")
also the lein difftest
plugin is often useful
okay just to make myself clear, my tests are written in clojure-test
, but to display better output there are these two additional plugins
ultra is a leiningen plugin that attempts to pull together all the leiningen plugins most people will want
ah cool. I was wondering. I couldn't find a reference in project.clj so assumed it was something else
one of the things it does is make lein test
's output much nicer. another thing that does that is humane-test-output
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
as opposed the this next one which is
starter_kit
âââ src
â âââ app
â âââ starter_kit
â âââ core.cljs
âââ static
is the above correct?
what do you think the namespaces are here? it's going to depend on what you soecify as the root dir.
Good point. The root dir in both examples is starter-kit
Further, in this, I am trying to understand segmented namespaces and how they relate to folders
probably not. you would normally specify src
as the root dir for eval. so app.core
would be the ns for 1st example.
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.
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?
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.
your top level starter_kit
can be anything - it's outside of scope. your project name and namespaces need not be related.
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
an aside, but also "core" is severely overrated as a name
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.
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)
on the jvm, there are a few contexts where namespace automatically becomes a package, and "top level packages" break in weird ways
@noisesmith: avoid in clojure too? i thought it was just cljs.
Interesting. Are there any suggested alternative to core
. This does seem to dominate the example projects I have seen
it's an even bigger problem in jvm clojure
@tkjone if you run lein new
it generates foo/src/org/me/foo.clj
by now core.cljs
(`core.clj`) is a pretty well-established convention, but it is not required.
it's a bad convention
could you expand on that a little, @noisesmith?
@noisesmith what do you use?
p.s. thank you both for being so helpful @mobileink and @noisesmith
it's a placeholder auto-generated by a tool that has no smart way to pick something better
the namespace can just have a meaningful name, there's no generic answer to what that name should be though
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/...
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 core
works just as well.
@noisesmith agreed, that's my prefered arrangement.
the heirarchy implies that everything in dir foo/ is an implementation detail of foo.clj
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.
Some like to use an impl
subdirectory to clarify when thatâs the case
@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
there should be exactly one place where that full path matters, right?
and I'm primarily talking about libraries, apps can be much more flexible and idiosyncratic
i've also done the opposite:
src/foo/bar.cljs ;; implementation
src/foo/bar/core.cljs ;; driver
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
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.
leiningen puts -main in core, clojure puts that in main and puts the language standard functions in core
anyway, sorry for the big derail it's a "thing" for me
It is helpful
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.