Fork me on GitHub
#beginners
<
2019-07-06
>
joshkh12:07:09

does anyone have any experience with pdfboxing? in my example i'm trying to save the first page of a PDF as a file, but i get the following exception (and corrupt pdf file output):

(-> (pdf/split-pdf :input "/tmp/example.pdf")
  first 
  (.save "/tmp/page-1.pdf"))
Execution error (IOException) at org.apache.pdfbox.cos.COSStream/checkClosed (COSStream.java:82).
COSStream has been closed and cannot be read. Perhaps its enclosing PDDocument has been closed?
where the first page's type is org.apache.pdfbox.pdmodel.PDDocument

telekid16:07:13

Is it considered bad practice to keep atoms (or other mutable state) as values within immutable data structures? I tried this little experiment so that I could see what was going on:

client> (def t {:atom (atom nil)})
#'client/t

client> (update-in t [:atom] #(reset! % true))
{:atom true}

client> t
{:atom #atom[true 0x63a9848e]}

telekid16:07:23

Or is this a pattern that shows up regularly?

alexmiller16:07:05

Not uncommon, totally fine

alexmiller16:07:36

You get to choose the granularity of your state - a map with several atoms or an atom holding a map

alexmiller16:07:44

More atoms gives you more granular state and smaller updates (with the caveat that they can’t be coordinated transactionally)

alexmiller16:07:00

In general with Clojure, people tend to make things pretty coarse as atom updates are usually very fast

telekid16:07:15

awesome - thanks!

alexmiller16:07:39

cgrand (as usual) had a pretty advanced take on this with refs in https://github.com/cgrand/megaref

alexmiller16:07:22

That’s an oldie but should still work just fine today afaik