Fork me on GitHub
#clojure
<
2016-12-27
>
seancorfield00:12:53

I thought Rich had done a talk at a user group about clojure.spec but I’m not finding it there...

seancorfield00:12:43

FWIW, I was one of the early skeptics who wanted :ret checked via instrument for example-based testing / regular execution. Rich’s arguments have persuaded me otherwise (along with other people elaborating on it).

qqq00:12:45

@seancorfield : thanks for the resources

olslash05:12:32

I'm having trouble with this code https://gist.github.com/olslash/4804c246b02e5a9e7237aed3ec41ed07 -- specifically the result that's being written is about 10MB bigger than if I let OSX unzip the file, and it's corrupt

olslash05:12:02

i thought i might be doing something wrong with the io/ stuff

olslash05:12:21

anyone able to help? that gunzip fn is from a stackoverflow post

olslash06:12:43

looks like the fn works, i just had to untar as well 🙂

jiyouyou12506:12:25

does anyone known how to convert scala.collection.immutable.HashMap$HashTrieMap to hash-map: when i transform it, throws ----- Don't know how to create ISeq from: scala.collection.immutable.HashMap$HashTrieMap

iku00088808:12:49

@jiyouyou125 I am imagining it would involve an extend-type to make the scala HashTrieMap support the ISeq interface, but never done that before...

jiyouyou12511:12:53

@iku000888 thanks, i use JavaConversions.mapAsJavaMap to convert to java.util.HashMap, it’s scala world. 😂

mping15:12:29

I was looking at a clj optimization/hackerrank problem my friend showed me

mping15:12:37

and I can’t seem to improve his version

mping15:12:53

its basically a trie, here’s the repo: https://github.com/tdantas/js-clj-challenge

mping15:12:56

do you have any ideas?

mping15:12:53

actually I dont think he did a trie, its just a hashmap

josh.freckleton17:12:51

I'm trying to explore map composition, haskell type: fmap.fmap :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b) and I'm using (comp map map) but it's behaving unexpectedly... this is what I want: (fmap . fmap) (+1) [[1, 2], [3, 4]] => [[2,3],[4,5]] but this returns an obscure function: (((comp map map) inc [[1 2 3] [4 5 6]])) which takes an index, and returns the map incd vector at that index (IE [2 3 4] for 0) (this was if I did ((comp map map) inc) and applied that to a vector of vectors) what am I doing wrong? Is there a way to apply comp to map map, to see what that function is looking like/expanding to?

josh.freckleton17:12:42

(like a macro-expand but for functions?)

seancorfield17:12:34

Part of your problem here is that map can take one argument or many — and they mean different things. (map inc) is a transducer and transducers compose just fine but you can’t map a transducer over a collection, which is what you’re essentially trying to do.

josh.freckleton17:12:12

good point, I did try too: (comp #(map %1 %2) #(map %1 %2))

josh.freckleton17:12:25

but I'm getting a bit lost

josh.freckleton17:12:29

in what the fns are doing

seancorfield17:12:32

comp expects to work with functions of a single argument.

josh.freckleton17:12:57

should I curry the maps then?

seancorfield17:12:14

(map (partial map inc) [[1 2] [3 4]]) should work.

josh.freckleton17:12:00

hm, my exercise is to play with composition, and i wanted to try next composing 3 maps...

seancorfield17:12:17

Clojure != Haskell.

josh.freckleton17:12:43

sure, but the data access pattern that lenses allow interests me, since it's so composable

seancorfield17:12:50

But you perhaps need to look at transducers which might get you closer?

josh.freckleton17:12:19

I love transducers and hadn't considered them as an alternative to lenses...

josh.freckleton17:12:03

basically, I want to create a protocol that allows a uniform data access interface that I can extend to databases, datascript, clojure maps, or anything really, even API endpoints

josh.freckleton17:12:26

lenses seem to afford me the composition I need if this protocol should work

seancorfield17:12:54

Sounds like Specter…?

josh.freckleton17:12:35

if I recall, specter is largely built from macros, which I would imagine suffer when it comes to composing them, and I flat out don't know how to implement them as a protocol that could be extended... a slightly sideways question that would help me solve this, it's tough when clojure evals something to, eg: #function[clojure.core/comp/fn--3483] to know whats going on...

josh.freckleton17:12:50

do you know of a way to "function expand", short of doing it by hand?

seancorfield17:12:49

The only way I can think of is to name all your anonymous function sub-expressions...

nathanmarz17:12:29

@josh.freckleton the core of specter is a simple protocol for navigation

nathanmarz17:12:49

it composes extremely well, that's the whole point of the library

nathanmarz17:12:33

your example in specter is just (transform [ALL ALL] inc [[1 2 3] [4 5 6]]) => [[2 3 4] [5 6 7]]

josh.freckleton17:12:38

@nathanmarz could you show me the same example in spectre using composition? like, I might expect: (comp (transform [ALL]) (transform [ALL] inc))

nathanmarz17:12:01

the composition is just done by making a sequence

nathanmarz17:12:19

if you want a navigator which goes into sequence of sequences, just do (def my-nav (comp-paths ALL ALL))

nathanmarz17:12:33

then you could do (transform my-nav inc [[1 2 3] [4 5 6]])

josh.freckleton17:12:46

awesome, thank you! I think this looks like a useful way of data nav, but I'm wondering if I can't bring into clojure some of the mathy/generalized goodness of haskell/category theory

josh.freckleton17:12:02

let me know if I'm misguided and just not seeing that yours really is my answer 😉

seancorfield17:12:06

Remember, Clojure != Haskell 😆

nathanmarz17:12:18

i personally find haskell's lenses overly complicated

seancorfield17:12:22

Seriously tho’, that’s why I thought of Specter in the first place.

nathanmarz17:12:34

there's no reason to have a distinction between "Lens" and "Traversal"

seancorfield17:12:58

BTW @nathanmarz do you have a highlight / alert for the word “specter” in here? 🙂

seancorfield17:12:59

Heh, didn’t mean to invoke you during the holidays!

josh.freckleton17:12:15

thanks to both of you for jumping in to help! sorry if I'm a bit bull-headed about bringing in haskell idioms. I like their "promises" that their generalities offer

seancorfield17:12:08

I really think you’re going to create more pain for yourself trying to write Haskell in Clojure — the idioms are completely different.

gfredericks17:12:50

and you can't guarantee nearly as much

gfredericks17:12:11

and you can't make polymorphic constants

josh.freckleton17:12:57

ok, maybe I should reconsider. what I'm trying to do is this: for web apps, I notice a huge cost in repeating oneself at the db layer, api, frontend api access, UI, etc., but data essentially remains "the same" wherever it is... I don't want to need to SELECT from a db, and GET from an endpoint, and (get ...) from a map, so I was hoping to abstract that and lenses seemed like a fruitful direction to search in... Imagine if you had 2 SELECTs you wanted to perform, and could compose them intelligently together, instead of needing to write and maintain ad hoc SQL?!

josh.freckleton17:12:57

or two http GETs for that matter!?

seancorfield17:12:58

I went down that path recently … and gave it up as soon as I tried to use in the production code 🙂

josh.freckleton17:12:24

interesting, you wouldn't have written up about your adventure, would you have? 🙂

seancorfield17:12:18

I’d talked about it here ages ago… or maybe on the mailing list? When I was first thinking of going that route… and everyone tried to dissuade me from it… They were right, it was clumsy and painful.

seancorfield17:12:42

Basically, without a type system like Haskell’s, this stuff is virtually impossible to use in real world code.

dpsutton17:12:08

in haskell, "if it compiles, it works"

dpsutton17:12:21

but there's lots of steps where it seems like it should compile

dpsutton17:12:33

imagine if you just got back from ghc "no"

josh.freckleton17:12:43

hm... I'm not sufficiently dissuaded, because this sounds so powerful if it existed! I just tried to search for your old conversations, would you be able to point me to them, or in a direction you think would shed light on why this isn't possible, or why I should reconsider?

josh.freckleton17:12:31

@dpsutton I'm not sure I understand how that relates... sure haskell has a killer compiler, and type system, clojure's lack of those tools precludes this idea from working?

dpsutton17:12:53

my point was just that I can't imagine being lost in types in haskell without the type system itself

dpsutton17:12:04

trying to reason that without any guidance, like in a dynamic language, would be painful

dpsutton17:12:15

my coworker is big on type theory and lenses

dpsutton17:12:35

and if he describes them as "magic", I can't imagine trying to wade through that without a very persnickety compiler

dpsutton17:12:52

that was my point

josh.freckleton17:12:58

ah, thank you 🙂

josh.freckleton18:12:05

ya, that makes sense too

dpsutton18:12:12

it certainly could be done

seancorfield18:12:43

I think idiomatic use of the language is radically different between Haskell and Clojure https://clojurians.slack.com/archives/clojure/p1482861511006760

seancorfield18:12:23

The efforts to try to create Haskell versions of Clojure’s transducers showed that well…

seancorfield18:12:10

Clojure’s transducers are simply not idiomatic in Haskell — you’d naturally take a different approach (an approach that would be non-idiomatic in Clojure).

qqq20:12:25

What is the state of art in Clojure parsing? OMeta? Peg/SquarePeg? Parsec/Parsatron?

geoffs20:12:36

It's handled all the parsing needs I've come across, so I've never researched what else might be available

miikka20:12:14

@josh.freckleton Have you seen this? http://calmm-js.github.io/partial.lenses/ - it's an attempt to bring lenses to JavaScript, and as such, one answer to the question of what lenses should look like in a dynamic language. To me, it looks a lot like Specter.

qqq20:12:08

@geoffs: I feel like "generate all possible parses" is the wrong solution to the "possible ambigious grammer" problem

dpsutton20:12:48

I don't believe it does that by default

dpsutton20:12:54

You can ask for all parse trees

dpsutton20:12:05

with the idea being that making unambiguous grammars could be really tricky

dpsutton20:12:11

but you normally get only one

josh.freckleton20:12:23

@miikka (thanks for pointing that out to me, I'll check it out)

geoffs20:12:25

> Optionally produces lazy sequence of all parses (especially useful for diagnosing and debugging ambiguous grammars).

aengelberg20:12:53

Generally, ambiguous grammars = slow grammars

aengelberg20:12:59

(in my experience)

aengelberg20:12:47

But insta/parses can expose most ambiguity issues.

qqq20:12:11

Yeah, so one of the nice things about Peg is that rules have priority ==> no ambiguity. similarly with Parsec.

aengelberg20:12:18

Well, the reason ambiguous grammars are slow is that the parser churns trying to generate and branch out from many possibilities. So introducing priority won't necessarily solve that, just change the order in which things are tried.

aengelberg20:12:42

(btw, there's an #instaparse channel if you'd like to sidebar on this)

aengelberg20:12:09

Example of parses NOT properly exposing ambiguity:

(def p (insta/parser "S = 'b' <A> <A> <A> <A> <A> <A> 'b'; A = 'a'+"))
(time (count (insta/parses p "baaaaaaaaaaaaaaaaaaaaaaaaaaaaaab")))
"Elapsed time: 2608.163607 msecs"
1
(the ambiguous part is being hidden with <>)

seancorfield21:12:22

(FWIW, we’re a happy Instaparse customer at World Singles: we use it to allow Customer Service to enter search rules in “English” and it parses them into criteria and dimensions for the Discovery search engine)

seancorfield21:12:02

So, pseudo-English -> Clojure data -> JSON -> search engine -> results 🙂

qqq21:12:46

is core.match still being maintained? is it (1) it's ditched or (2) it's so complete that it no longer needs changes?

seancorfield21:12:41

@qqq I wonder consider it mature and “complete” at present.

qqq21:12:34

@seancorfield : thanks for confirmintg, the lastest I ee is 0.3.0-alpha4, and the alpha4 did not provide confidence on it being completed

seancorfield21:12:36

(even tho’ there are 33 open issues logged against it in JIRA)

seancorfield21:12:54

Regarding the “alpha” label, a lot of the contrib libraries tend to be pretty stable even in alpha, i.e., safe to use in production unless they explicit say not to do so.

olslash21:12:20

dnolen came in a week or two ago when i asked the same question

olslash21:12:24

maybe his answer is still in history

seancorfield21:12:31

tools.namespace, data.xml, java.jdbc are all currently offering “alpha” versions and we use all three of those in production — along with Clojure 1.9 (alpha 14 in production)

olslash21:12:44

basically he said he has new ideas but no time to work on them, that it's stable, and being used in production

qqq21:12:57

got it; I'm just suggesting people would be slightly more comfortable if it was 0.3.1 instead of 0.3.0-alpha4 🙂

seancorfield21:12:02

@olslash The 10,000 message limit here means we get less than a week of archives, I’m afraid.

olslash21:12:09

yeahi thought as much

olslash21:12:17

i asked about "alpha" as well -- he said it was basically a meaningless marker

seancorfield21:12:40

“alpha” just means the API may still change before the next “gold” release.

seancorfield21:12:22

But any individual version is just fine to use. You usually only have problems shifting across versions (which you could have anyway, even with non-alpha versions).

seancorfield21:12:47

Although that may change after Rich’s “Spec-ulation” keynote at Clojure/conj 😸

seancorfield21:12:20

That all reminds me, I need to nail down java.jdbc and get a “beta” release out! 🙂

dpsutton21:12:42

its unoptimized in js

dpsutton21:12:43

and is fine in java

dpsutton21:12:02

it uses try/catch which is a goto in java but unfortunately removes all optimizations in js

dpsutton21:12:19

he considers it stable but has a few things he wants to do before releasing a non beta version

dpsutton21:12:26

per conversation at conj

dpsutton21:12:52

I've submitted one pull request to it and I'm still working my way through the paper on how to go from a back tracking automata to the decision tree style compiler

dpsutton22:12:21

but any core projects are extremely stable in the sense that they do not change without great contemplation