Fork me on GitHub
#clojure
<
2016-06-14
>
cddr00:06:43

@bcbradley: The problem with that approach is that it requires you to load your working set into memory. There's not a lot that can't be done fairly straightforwardly in SQL, especially once you learn the more advanced features like window functions, group by, and having clauses.

seylerius03:06:49

Two questions: 1) If I'm walking a recursive structure and producing a nested sequence of strings as a result ("a" ("b" "c" ("d"))), is there something more efficient than a single flatten pass after the walk to flatten it? 2) If certain items in the recursive structure need to be watched for the first and last of their type within one type of node, and between another type of node, how would you best handle that?

seylerius03:06:18

(The first and last need extra tags in the resulting strings)

hiredman06:06:01

depending on how you are walking the tree, you should generate a flattened list as you walk it

hiredman06:06:10

easiest for depth first, but possible for breadth too (minikanren and core.logic use an interleaving mechanism to do it)

hiredman06:06:47

flatten is very gross, its use signifies sloppiness to me

lmergen08:06:43

are clojure's futures and promises using java8's native libraries for those ?

Macroz09:06:03

java.util.concurrent.Future is older than Java8 and seems to be in use if you check the source e.g. here https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/core.clj#L6697 (updated link to 1.8)

niwinz09:06:50

funcool/promesa works with java8 completable futures

krisajenkins09:06:11

@seancorfield: Yesql doesn’t support dynamic query generation. It’s likely it won’t. I’ve never used something like that that doesn’t become a real mess. If that’s what you need, you’re better off either pushing that complexity back into the database (with views, etc.), or pulling it forward into the language and accepting that you’ve given up the simplicity of SQL for the sophistication of a programming language. That’s a long way of saying, I don’t think it works very well*, if that’s what you need you should look for a different route. (* Esqueleto is the only “dynamically compose SQL queries” approach that I know of, that I’d rate.)

lmergen12:06:27

i actually like Suricatta as well

lmergen12:06:38

it's great for composable sql queries

lmergen12:06:11

I personally think there definitely is a case to be made for composable SQL queries

dominicm13:06:07

I thought hugsql was pretty composable?

plexus14:06:31

Don't know about HugSQL, since you have to hand code each query, but HoneySQL is pretty nice for composing queries

stathissideris14:06:00

full circle, honeysql was mentioned already (scroll up) 🙂

donaldball14:06:01

I like honeysql; I don’t want a dsl to compose queries, I want a data structure that can be transformed into a query.

seylerius15:06:11

The recursive structure I'm walking shows lists as a succession of :ordered-list or :unordered-list items. I need to convert each of those to an <li>, but I also need to wrap each whole list in <ol> or <ul> tags. I figure I can split lists when I descend into a block, and possibly on a paragraph. Would you pre-process the data structure to flag starts and ends of lists, and then go back through to process the HTML? Or is there some more elegant way I'm not thinking of?

stathissideris15:06:15

@seylerius: sounds like you'd want to split the lists with partition-by as a first step (they're flat initially, right?)

stathissideris15:06:15

I mean the split the items

nathanmarz15:06:50

@seylerius: have an example of the input/output you're looking for? likely very easy to do with specter

meowy16:06:52

I wrote a cute little BBCode parser in Clojure today.

meowy16:06:39

Falls flat on its nose right now when it faces invalid input, though, so that needs a slight bit of polishing.

seylerius16:06:34

@stathissideris: Nope, not flat to start. Sequence of maps, some of which contain sequences of maps (etc.)

seylerius16:06:07

@nathanmarz, @stathissideris: Here's a sample. Source file: http://sprunge.us/PQBX Parsed data structure: http://sprunge.us/AXaF

stathissideris16:06:18

is this org mode? 🙂

stathissideris16:06:03

oh it is (just read the first line)

stathissideris16:06:54

so are you asking whether to nest level 2 subsections under level 1?

stathissideris16:06:03

it makes more sense but it also has certain advantages (for example, you can get all the contents for a level 1 section in one go)

stathissideris16:06:27

an org mode parser would be a great thing to have

nathanmarz16:06:02

@seylerius: yea super easy with specter

nathanmarz16:06:09

(use 'com.rpl.specter)
(use 'com.rpl.specter.macros)

(transform
  [ALL
   :content
   (multi-path
    (continuous-subseqs #(= (:line-type %) :ordered-list))
    (continuous-subseqs #(= (:line-type %) :unordered-list)))
    ]
  (fn [aseq]
    (let [type (-> aseq first :line-type)]
      [{:line-type (if (= type :ordered-list) :ol :ul)
        :content (setval [ALL :line-type] :li aseq)
        }]
      ))
  data
  )

nathanmarz16:06:32

here's a gist showing the before/after on part of what you posted: https://gist.github.com/nathanmarz/1a5728e8a0e12e08c02d98aa1df675aa

nathanmarz16:06:59

I didn't see the recursion in the example you gave, but this can easily be made recursive as well

stathissideris16:06:13

@nathanmarz: "The First Section" is missing from your gist

nathanmarz17:06:04

for brevity, I only took part of the sample input

seylerius17:06:55

@stathissideris: More specifically, I'm trying to capture starts and ends of lists so I can wrap them in <ul> and <ol> tags as needed.

seylerius17:06:30

I'm expanding upon @gmorpheme's organum. The basic version of organum (with a bugfix I added because it was parsing table-row as #".*" due to excess escapes) can be found at https://github.com/seylerius/organum

seylerius17:06:34

Going to fold my parsing and formatting additions into organum, probably.

jswart19:06:14

@seylerius: I would solve this with reduce. The step function passed to reduce would act as a state machine and achieve what you want.

jswart19:06:46

reduce is basically a “wrapper” around loop/recur and will give you a lot of control and ease in this case

jswart19:06:11

if I wasn’t swamped at work I would make an example but I can’t, I have this old blog post though. The bottom of the post is what I’m talking about http://jcswart.github.io/2014/01/25/clojure-like-im-five-reduce-functions/

jswart19:06:38

notice how I keep “state”

jswart19:06:52

you can do the same to detect start and ends of the lists

seylerius19:06:52

@jswart: Thanks. I'll need to take a look at that. I'm still learning about reduce.

seylerius19:06:39

@jswart: I see... You're passing state inside a vector containing your accumulation. Could probably toss that afterwards by having the very first call be something like (first (reduce dispatch-node org-nodes)), if dispatch-node returns [parsed-nodes state]

jswart20:06:50

yep, however you want to set up

jswart20:06:21

could be a map, vector, etc.

ghadi20:06:13

btw, these days it's recommended to use the init argument to reduce (reduce f init collection)

ghadi20:06:41

rich has mentioned the implicit first item of collection as init was a bad idea

Alex Miller (Clojure team)20:06:46

"bad" is maybe too strong - perhaps "unnecessarily complex" :)

nathanmarz20:06:40

What would the better design have been in retrospect? Implicit init of (f) when it's not provided?

ghadi20:06:11

aka the IReduceInit interface

nathanmarz20:06:44

yea, that makes sense

nathanmarz20:06:04

is the reason for having implicit init with transduce just for consistency with reduce?

roberto20:06:57

prefer explicit over implicit (I remember that tenet from my python days)

shriphani21:06:57

Hi. I’m trying to use lein uberjar and I’ve got a skip-aot (some dependencies look for env vars and so on). How do I make this executable?

jswart21:06:13

once you have the jar you can run java -jar YOUR_JAR, is that what you mean?

shriphani21:06:13

well so I am trying that

shriphani21:06:08

but running with java -jar, I can’t find my core namespace

jswart21:06:57

Ah, sorry. There might be an :aot you have to set as well but I don’t use lein so I’m not really sure.

seylerius21:06:28

If you're trying to mine useful information out of the output of something like ffmpeg that modifies its output stream, and you want to use that info for a progress bar, how would you go about doing that?

jswart21:06:55

Your question is kind of vague, but that is what I would do.

seylerius21:06:53

@jswart Specifically what I'm aiming at is the total length of one of the input files (which doesn't get edited), and the current time through the encoding process (which changes as it progresses, eventually reaching the total length).

seylerius21:06:35

The standard output stream doesn't share that usefully.

jswart21:06:04

does it share anything? you could grep for the pieces, put them in a file and the wc -l the file. The number of lines == the progress.

jswart21:06:48

Doing this back and forth between clojure doesn’t seem super fun though, and if you have a lot of files its like just better to show which files are done and which are pending, etc.

jswart21:06:54

But I have no idea your use case

gmorpheme21:06:30

@seylerius I'll happily incorporate any contributions to organum. alternatively happy to redirect people to your fork if you prefer as realistically I have zero time to spend on it!

seylerius21:06:38

@gmorpheme: Glad to finally catch up with you. I'm probably going to be doing a fair bit to it, so perhaps switching to my fork will work best for the longer term. Planning to fill out the parsing some (inline formatting, table items in rows, etc.), and add basic HTML output (perhaps in hiccup format).

seylerius22:06:36

Need both of those for for an editor I'm making in support of another project.

seylerius22:06:05

(The bigger project is a decentralized office suite focused on activists, analysts, and journalists. Main tools: org-editor; distributed, encrypted file storage; evidence storage; knowledge graph database; team-oriented comms suite)

seylerius22:06:32

@jswart: Here's some sample output: http://sprunge.us/bfIa The duration of the second of the two files is 5.4s. The first input file is a picture. It's a simple program to slap a GUI on the ffmpeg command that glues an image to an audio clip.

gmorpheme22:06:27

@seylerius: sounds great! I'll keep an eye on it. I'll change the readme to point people at your fork when I get a chance

seylerius22:06:45

@gmorpheme: I'll mod the readme and namespace on my end, then, to differentiate, and to credit you for creating the original project.

gmorpheme22:06:30

@seylerius Thanks. Most appreciated. Probably tomorrow now (pretty late here).

seylerius22:06:03

@gmorpheme: Thanks for creating it in the first place. It's particularly handy. Also, if you find yourself with stupid amounts of free time after I've got the basic structure ready, this project will be huge and in need of good coders.

gmorpheme22:06:58

Oh I'm not short of stuff to be working on I promise you:) But I'll watch with interest at least