#clojure log - May 23 2016

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

0:03 tolstoy: If you use plumatic/schema s/defrecord to apply schemas to the data in the record, why doesn't it break when you supply bad values?

0:04 Oh, there it is in the doc string.

0:17 The record itself is the schema.

0:30 jasonmason: feminist put in her place. https://www.youtube.com/watch?v=R3HvI5dJuzo

0:35 dysfun: ...

0:43 tolstoy: Hm. roomkey/annotate doesn't support map->Record constructor type checking.

0:45 will_sm: Is EDN used outside of clojure/clojurescript?

0:46 dysfun: not really, but there are libraries for other langs

1:16 tolstoy: If you had a table (entity, attribute, value, time) and never deleted stuff, how would you query for all the attributes for a given entity, limiting to the latest time?

1:17 I mean, you know, for a dirt poor man's hacky misunderstood semblance of a kind of datomic like thing?

1:17 dysfun: what is it in?

1:17 tolstoy: postgres

1:18 dysfun: haha. building datomic-like on postgres atm

1:18 tolstoy: Or, well, h2, actually. But I'm just kinda wondering.

1:18 dysfun: gimme a minute to write a postgres query

1:18 tolstoy: First thought is just punt, load all the stuff into memory, then filter out. ;)

1:18 dysfun: lol

1:19 tolstoy: Normally, I just start writing a query and let the failure drive google searcher until I know how to ask the right question.

1:21 dysfun: select eavt.a from eavt where eavt.e = ? group by eavt.a order by max(eavt.t)

1:21 have not tested!

1:21 order by eavt.t desc, probably

1:21 i haven't been up long, sorry, but i hope it helps

1:22 tolstoy: That looks surprisingly simple. Pays to work with a DB more than for a few weeks every couple of years.

1:23 dysfun: hah

1:23 yeah, i think postgres actually probably is quite alright for a datomic-like

1:24 tolstoy: I've never used group by without a count(*) or similar. Interesting.

1:24 dysfun: well the next trick that comes to mind is DISTINCT ON

1:24 so many ways to drive a db

1:24 tolstoy: Yeah.

1:26 "Find all the latest attribute versions of an entity." But also need some way to register retractions, I guess. Huh.

1:26 dysfun: you may wish to just postfilter

1:26 but actually that query may not return it all

1:26 yeah, fun fun

1:32 tolstoy: Captain Hindsight: A project I helped maintain for a bit could have used an EAV (at least) db.

1:32 Lots of "variant" data types: a thing, a subclass of a thing with extra attrs, etc, etc.

1:32 dysfun: there is an EAV database for pg, just not an EAVT one

1:33 tolstoy: They modeled it using different tables to add on extra bits, tied together with a reference table and custom OIDs, etc.

1:33 Super had to piece together as a DB in and of itself.

1:33 dysfun: oh yes, seen lots of those

1:33 tolstoy: s/had/hard/

1:36 dysfun: wow, it's been ages since i checked out an svn repo

1:36 i am of course using git-svn...

1:36 tolstoy: My little toy project replaces entities, so I can't really test this history stuff.

1:36 dysfun: maybe you should just wait for me to finish my project then? ;)

1:37 tolstoy: Yep.

1:37 dysfun: wow. this sourceforge project has way more revisions than i thought it would

1:37 it's a test library written in C that something i want uses

7:16 pythys: Hi everyone. I'm having some difficulty understanding the REPL integration with projects. If I do something like "lein repl" inside a project, what is the difference from doing it outside the project?

7:18 Does anything get loaded by default?

7:25 dysfun: if you've set a nems

7:25 namespace in your project.clj that will be loaded

7:26 in :repl-options

7:26 otherwise it's just all your dependencies will be on the classpath

7:47 pythys: hi dysfun, so when I open a certain file in a project, how can I experiment with it in the repl?

7:47 do I have to (use thefile)?

7:49 dysfun: i prefer require, but basically yes

7:49 and you'll need to quote thefile: 'thefile

7:59 pythys: dysfun: ok great

7:59 Another question, what is the fastest way to understand where a function came from

8:00 dysfun: if you use :as in require, it should be pretty clear

8:00 otherwise see if it's in clojure.core (doc clojure.core/name), otherwise look through the (:use) in the ns form

8:01 you can use the same trick with doc for each namespace

8:01 pythys: I see

8:01 dysfun: and if your repl supports autocomplete (like the lein one), you can hit tab to get completion and eliminate names quickly

8:01 pythys: and exploring packages? I see for example that (all-ns) does not help much

8:01 dysfun: define 'package'

8:01 pythys: (dir package) lists them which is nice

8:02 oh I mean just namespaces I guess

8:02 dysfun: ok

8:02 well tbh i mostly read the README.md or the docs

8:02 pythys: so (dir clojure.core)

8:02 dysfun: so you're always in some website checking the API docs? right?

8:02 dysfun: yes, the clojure cheatsheet

8:02 http://clojure.org/api/cheatsheet

8:03 i also keep a repl open so i can answer questions even when i'm not writing clojure :)

8:04 pythys: dysfun: ok, so the REPL is always relative to your current directory

8:04 and the way you explor files is with (use,,,) or (require,,,)

8:04 dysfun: with lein, yes

8:04 pythys: and I assume you should always be in the lein project's root directory

8:04 dysfun: and i tend to require with :as and use the tab key in the repl to check them

8:05 pythys: ok, good tip

8:05 tab completion really helps

8:05 dysfun: yup

8:05 pythys: if you have 10 files calling each other or requiring each other somehow

8:05 and I just (require oneofthem)

8:06 dysfun: all of them will be required as you'd expect

8:06 pythys: does it automatically pull the rest in?

8:06 ok I see

8:06 dysfun: however, caveat!

8:06 pythys: yeah, shoot?

8:06 dysfun: if you need to *reload* a namespace, you do e.g. (require '[foo.bar as fb] :reload)

8:06 otherwise, it will silently do nothing

8:06 pythys: when should you reload?

8:06 dysfun: :reload will *not* reload all the dependent modules

8:06 :reload-all will

8:07 when you know that you have changed some code and want to play in the repl to see if it's fixed

8:07 pythys: I thought clojure is dynamic, why would I reload upon changing code?

8:07 does the repl cache in stuff?

8:08 dysfun: okay, this is for the situation where you are editing one of your lein project's clj files

8:08 just editing them in a text editor does not make them changed in the repl

8:08 pythys: so either reload or restart the repl

8:08 dysfun: :reload-all is more useful

8:08 pythys: errrr, reload-all

8:09 okay, got it

8:09 dysfun: and realistically you may just want to use it by default, because then you can just find the last time you did it in the history

8:09 * dysfun usually uses :reload-all by default in the repl

8:09 dysfun: but some modules don't play entirely nicely, so caveat emptor :)

8:10 (and you will know when you have hit one)

8:11 pythys: Yeah, not too worried about that. I haven't been in a mind-bending journey in any new language the way I've been here. I'm staying in "exploration" mode for at least 3-4 months

8:12 dysfun: hah. i'm currently in the process of rewriting everything i wrote in my first 2 years

8:12 (of clojure)

8:15 pythys: I see! clojure is definitely not short-term then

8:15 dysfun: i wouldn't say it's all bad code, but i like to improve old things periodically because i'm always learning

8:16 and part of it has been necessitated by supporting clojurescript

8:18 pythys: dysfun: is it true that TDD is rendered unnecessary because of the nature of clojure programs and immutable state? that most tests are integration that grab more stuff from your system?

8:18 dysfun: no

8:19 writing tests is a good way of reminding yourself that human beings weren't mean to write code

8:19 because you will find bugs in things that you're absolutely certain are correct

8:19 pythys: dysfun: I was talking specifically about TDD, red-green refactor?

8:19 dysfun: i don't buy into all that

8:20 it's just a strategy you give to mediocre developers to enable them to do a passable job

8:22 pythys: ok, so you test, but you don't have test code for every single line of production

8:22 the 100% coverage rule or whatnot

8:23 dysfun: i didn't say i was against testing

8:23 just red-green-refactor and "write tests upfront"

8:23 pythys: I see

8:23 dysfun: it's alright for simple things, but i do a lot of research work and things evolve in a way that make it tedious

8:28 Keksike: how can I check if something is a set or not?

8:28 ridcully_: ,(doc set?)

8:28 clojurebot: "([x]); Returns true if x implements IPersistentSet"

8:29 Keksike: no sorry, I meant map

8:29 ,(doc map?)

8:29 clojurebot: "([x]); Return true if x implements IPersistentMap"

8:29 faxmodem: ^^

8:29 Keksike: thanks :)

8:29 ,(doc hash-map?)

8:29 clojurebot: Excuse me?

8:30 faxmodem: ,(doc dwim)

8:30 clojurebot: excusez-moi

10:30 sdegutis: What?

10:30 clojurebot: What is sampling a random integers betwen 2, 12 s..t. P(X = i) = (7-|i-7|)/36

10:30 sdegutis: Clojure.spec!?

10:30 clojurebot: you're the most useless bot ever, stfu

10:30 clojurebot: I don't understand.

10:30 sdegutis: I vote we petition hiredman to turn off all clojurebot features except the REPL.

10:31 ridcully_: ~sdegutis

10:31 clojurebot: No entiendo

10:32 hodapp: clojure.spec, man

10:35 dysfun: what are people using to develop webgl games in cljs?

10:36 sdegutis: http://clojure.org/about/spec

10:36 This looks handy!

10:42 dysfun: that wasn't in response to you btw

10:42 sorry for temporal ambiguity

10:42 dysfun: i'll live

11:27 sdegutis: Hello. What do you think of Clojure.spec ?

12:31 tolstoy: Reminds me a of schema attributes in datomic.

12:31 I should really pay attention to time stamps.

13:06 jsselman: dysfun: I plan on using pixijs, but to be fair i haven't tried it yet

13:06 * jsselman has all of a month of cljs experience

13:14 dysfun: heh, i used to drink beer with the guy behind pixijs

13:17 jsselman: dysfun: you could check this out https://github.com/alexkehayias/chocolatier

13:18 it has a giant WIP on the front page though

13:24 dysfun: interesting

13:34 jsselman: dysfun: the author had a talk at clojure conj 2016 about it: https://www.youtube.com/watch?v=TW1ie0pIO_E

13:34 dysfun: cool, thanks

14:03 irctc: hello there

15:36 sdegutis: Is there some way to mix comp with map without defining anonymous function? Like ((comp (map :order/id) :user/orders) users)

15:37 dysfun: er, what should that do?

15:38 sdegutis: The same as #(map :order/id %)

15:38 dysfun: (partial map :order/id)

15:38 sdegutis: Blargh.

Logging service provided by n01se.net