#clojure logs

2015-08-29

00:02gfredericks,(inc 41)
00:02clojurebot42
01:01neoncontrailsWhy does this happen?
01:01neoncontrails,(defn recursive-last [s] (if (seq (rest s)) (recursive-last (rest s)) s))
01:01clojurebot#'sandbox/recursive-last
01:01neoncontrails,(recursive-last '(3 4 5))
01:01clojurebot(5)
01:01neoncontrailsOoh that's not what my REPL says. Hooray!
01:13neoncontrailsSo I notice that 4clojure.com doesn't seem to allow continuation-passing style
01:14neoncontrailsIn the absence of which... how does one solve a problem like https://www.4clojure.com/problem/19#prob-title ?
01:16neoncontrails,((fn [x] (nth x (- (count x) 1))) [1 2 3])
01:16clojurebot3
01:18neoncontrailsThere must be an equivalent expression that fits within the parameters of the question
01:55ashwink005can anyone guide me as to how to build a web app using clojure, PostgreSQL, and HTML?
01:55ashwink005any good online resource
01:59ashwink005helloo
01:59ashwink005can anyone guide me as to how to build a web app using clojure, PostgreSQL, and HTML?
02:06wasamasahttp://www.parens-of-the-dead.com/
02:06wasamasaand don't worry, nobody will hold your hand unless you've paid them to :>
02:08ashwink005wasamasa: I mean a basic web app that reads, edits docs
02:08ashwink005nothing too fancy
02:08wasamasayou would be surprised
02:08wasamasaespecially if you're thinking along the lines of google docs
02:09ashwink005no no I just want a wiki kinda project. Simply allow user to create an entry, update one etc.
02:09ashwink005this look way to scary
02:10wasamasasuch is programming
02:10ashwink005lol thanks anyways :)
02:10wasamasathe skill of breaking down a problem into small enough chunks to turn them into something the machine can understand
02:11neoncontrailswasamasa: well *I* appreciate the link, I'm adding this to my todo list ;)
02:11wasamasaneoncontrails: you're welcome
02:11wasamasaneoncontrails: it's by magnars which I've originally known for the videos from http://emacsrocks.com/
02:45myguidingstarddellacosta, I am looking at your friend-interactive-form-tutorial
02:45myguidingstarbut i can't login
02:45ddellacostamyguidingstar: hah, was just working on some oauth2 fixups
02:45myguidingstarI've updated stuff https://github.com/myguidingstar/friend-interactive-form-tutorial
02:46ddellacostamyguidingstar: what is the error you are getting?
02:47ddellacostamyguidingstar: also, this is pretty freaking old, not sure how much things have changed with the recent versions of friend?
02:47ddellacostawhoops, didn't mean to make that a question...haha
02:47ddellacostamyguidingstar: anyways, tell me what exception/error/wrong behavior you are experiencing and I'll see what I can suggest
02:47myguidingstarafter entering user+pass, the page still says I didn't log in
02:49myguidingstarfriend seems a black box to me :)
02:49ddellacostamyguidingstar: which page, which user, etc.?
02:49ddellacostamyguidingstar: it is a bit tough to wrap your head around. :-/
02:50myguidingstarI just use http://localhost:3000/login with user/pass pairs defined in source code
02:50ddellacostamyguidingstar: and then, what url is not working for you?
02:51myguidingstarafter press 'login' button, I get redirected to "/" with a non-logged-in welcome
02:52ddellacostamyguidingstar: and if you try going to /authorized for example, does that redirect you back to /login ?
02:52myguidingstarand /authorized says that I've not logged in
02:52ddellacostamyguidingstar: does /authorized say "This page can only be seen by authenticated users." ?
02:53myguidingstarhey wait, does that mean I'm authenticad?
02:53myguidingstarthen I think it works
02:53ddellacostamyguidingstar: yeah. I suppose that's a bit confusing--probably should say something like "if you see this you have authenticated successfully"
02:53myguidingstar=)))
02:53ddellacostahaha, yep. :-)
02:53ddellacostasounds like
02:54myguidingstarsorry for the wrong report
02:54ddellacostamyguidingstar: not at all--you've pointed out something confusing in the tutorial.
02:54ddellacostamyguidingstar: would you do me a big favor and create an issue for that? Something like "the message on the authenticated page is not clear" or something
02:55myguidingstarI'll make a PR for that
02:55ddellacostamyguidingstar: cool, thanks!
02:58myguidingstarddellacosta, I think after logging in, username should be shown in messages
02:59myguidingstarhow do I do that?
03:00ddellacostamyguidingstar: you will have to dig into the session to get that information out
03:01myguidingstaroh, I thought that's friend's stuff
03:01ddellacostamyguidingstar: well, it is, but friend stores that in the session
03:02myguidingstarin users: {"admin" {:username "admin"
03:02myguidingstar :password (creds/hash-bcrypt "password")
03:02myguidingstar :roles #{::admin}}}
03:03myguidingstaris the first 'admin' friend's so-called identity?
03:03ddellacostamyguidingstar: I'm not sure I know what you are asking--what are you referring to when you say "friend's so-called identity?"
03:04ddellacostamyguidingstar: friend does story a value in the session it calls "identity:" https://github.com/cemerick/friend/blob/7d286dffcb865c20e9a9c1465dba4f2c5ced7cab/src/cemerick/friend.clj#L64-L68
03:05ddellacostamyguidingstar: you probably want to use this: https://github.com/cemerick/friend/blob/7d286dffcb865c20e9a9c1465dba4f2c5ced7cab/src/cemerick/friend.clj#L92-L102
03:05myguidingstarcool, thanks
04:05neoncontrails,(#(sort > %) '(79 8 92 1 30))
04:05clojurebot(92 79 30 8 1)
04:06neoncontrails,((fn [x] (first #(sort > x))) '(79 8 92 1 30))
04:06clojurebot#error {\n :cause "Don't know how to create ISeq from: sandbox$eval52$fn__53$fn__54"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Don't know how to create ISeq from: sandbox$eval52$fn__53$fn__54"\n :at [clojure.lang.RT seqFrom "RT.java" 535]}]\n :trace\n [[clojure.lang.RT seqFrom "RT.java" 535]\n [clojure.lang.RT seq "RT.java" 516]\n [clojure.lang.RT first "RT.java" 661]\n...
04:07neoncontrailsHow do you take the first of this? Assuming the call must be tucked inside the S-expr
04:07justin_smithneoncontrails: for starters that doesn't need to be an anonymous function
04:07amalloyuh, don't you just mean (first (sort > x))?
04:08justin_smith,((fn [x] (first (sort > x))) '(79 8 92 1 30))
04:08clojurebot92
04:08justin_smith,((fn [x] (apply max x)) '(79 8 92 1 30))
04:08clojurebot92
04:09neoncontrailsAh, I see now. I was overthinking it
04:46ashwink005what does the :refer and :all keyword mean?
04:50oddcullyashwink005: http://conj.io/store/v1/org.clojure/clojure/1.7.0/clj/clojure.core/require/
04:50oddcully``:refer takes a list of symbols to refer from the namespace or the :all keyword to bring in all public vars.
04:50ashwink005thanks :)
06:30darth10anyone got an idea on the #= reader macro?
06:31darth10i cant seem to find much in the docs
06:42Rurik(defn my-first [[first-thing]] first-thing) will give the first thing in the vector
06:43Rurikbut what if I want to get the second thing
06:49Rurikgot it
06:50Rurik(defn my-second [[_ second]] second)
06:51expezdarth10: it's used to eval code at read time
06:54expez,(read-string "(+ 1 1)"
06:54clojurebot#<RuntimeException java.lang.RuntimeException: EOF while reading>
06:54expez,(read-string "(+ 1 1)")
06:54clojurebot(+ 1 1)
06:55expez,(read-string "#= (+ 1 1)")
06:55clojurebot#error {\n :cause "EvalReader not allowed when *read-eval* is false."\n :via\n [{:type java.lang.RuntimeException\n :message "EvalReader not allowed when *read-eval* is false."\n :at [clojure.lang.Util runtimeException "Util.java" 221]}]\n :trace\n [[clojure.lang.Util runtimeException "Util.java" 221]\n [clojure.lang.LispReader$EvalReader invoke "LispReader.java" 1100]\n [clojure.lang.LispRe...
06:55expez,(binding [*read-eval* :just-do-it] (read-string "#= (+ 1 1)"))
06:55clojurebot2
07:04Novel2I hear you guys are very helpful
07:04Novel2I hope you know about autohotkey
07:06oddcullyif you think the question is relevant to clojure, please ask the question
07:06oddcully~ask
07:06clojurebotThe Ask To Ask protocol wastes more bandwidth than any version of the Ask protocol, so just ask your question.
07:07Novel2it's not clojure, I'm just desperate for help
07:07Rurik(let [bindings* ] exprs*)
07:07Rurikwhat does the * means here
07:07Rurikmean
07:07expezRurik: 0 or more
07:07oddcullyRurik: many bindings
07:07Novel2I want to trigger a autohotkey script when gpodder downloads something
07:07Rurikah, thanks
07:08oddcullyNovel2: well you might have luck here, but it's OT after all
07:08Novel2fingers crossed :)
07:11Rurikcan anyone explain how I am supposed to use let
07:12oddcully,(let [n 5 square (* n n)] (print square))
07:12clojurebot25
07:15Rurikgot it
07:15Rurikso the part after the bindings gets evaluated
07:15wasamasawell, not really
07:15Rurikno?
07:15clojurebotno is tufflax: there was a question somewhere in there, the answer
07:15wasamasadepends on what you mean with "after the bindings"
07:17wasamasalet is a macro which means its evaluation rules are... different
07:17wasamasaNovel2: isn't autohotkey windows software?
07:19Novel2yup
07:20wasamasahead over to ##windows
07:21Rurikhttp://www.braveclojure.com/do-things/#4_2__let
07:21RurikI don't understand what he is trying to do here
07:21TEttingerRurik: have you used def yet?
07:21Rurikyes
07:21TEttingernot sure how far in you are
07:22TEttingerok
07:22TEttingerdef creates a "global-like" name that you can use for some value. like (def pi-kinda 3.14)
07:23Novel2ty
07:23TEttingerbut let creates "local" names that you can use for its values, in the section after the square brackets
07:25TEttingerand the names created with let, which are technically called bindings... (because "naming" things means it seems permanent, but let bindings are only bound to a value for a short part of the program)
07:25TEttingerthe bindings no longer exist after the let's last ) ends
07:26TEttingerthis is useful when you have let inside a function, and you do not, really, you never want to def inside a function just to give a name
07:27TEttingerbecause def inside a function would still be global, and could cause problems if you have two defs with the same name... or call a function that has (def foo "bar") in it twice.
09:31gfredericksdoes anybody know how *assert* is intended to be used in libraries?
09:33gfredericksin particular so each namespace can default to on or off, but still provide customizability
09:51quique_does anyone have a hint how to change the default print behaviour of cider? i'd like to avoid printing out infinite and very large data structures - which happens quite often out of purpose
09:52Bronsa,*print-length*
09:52clojurebot5
09:52Bronsa,(doc *print-length*)
09:52clojurebot"; *print-length* controls how many items of each collection the printer will print. If it is bound to logical false, there is no limit. Otherwise, it must be bound to an integer indicating the maximum number of items of each collection to print. If a collection contains more items, the printer will print items up to the limit followed by '...' to represent the remaining items. The root binding is...
09:52Bronsa,(doc *print-depth*)
09:52clojurebotGabh mo leithscéal?
09:52Bronsa,(doc *print-level*)
09:52clojurebot"; *print-level* controls how many levels deep the printer will print nested objects. If it is bound to logical false, there is no limit. Otherwise, it must be bound to an integer indicating the maximum level to print. Each argument to print is at level 0; if an argument is a collection, its items are at level 1; and so on. If an object is a collection and is at a level greater than or equal to th...
09:55quique_perfect thanks, that's what i was looking for
10:15namracan someone recommend some introductory books into game development?
10:16genzlerso I have a list like [[1] [[1 1 1] [3] [1 2]] – basically, [[[a] [b]] [[x] [y]]– what's the easiest way to make combinations like [[a x] [a y] [b x] [b y]] – like a cartesian product basically
10:17quique_@namra check the play-clj library, if you are interesetd in clj game development
10:18namraquique_: thanks i know about that and saw oakes talk, great take.
10:18namratalk
10:18quique_i agree on that :-)
10:19namrabut i'm looking for a general intro, about some techniques and to get some ideas on how to structure it
10:22gfredericksgenzler: your first list is rather confusing
10:22gfredericksit has numbers at different levels
10:23gfredericksmy guess is that wasn't intentional?
10:24genzlergfredericks: yeah, I think it should be [ [[1]] [[1 1 1] [3] [1 2]] ]
10:24genzlerdoes that sound better?
10:25genzlercombo/cartesian-product kinda works, it gives me: (([1 1 1] [1]) ([3] [1]) ([1 2] [1]))
10:26lambda-smithHm... so you can't use Java static function like this? (map Integer/parseInt '("1" "2"))
10:26Bronsalambda-smith: correct
10:26genzlerbut what I want is [[1 1 1 1] [3 1] [1 2 1]]
10:26gfredericksgenzler: normally a cartesian product doesn't require so many levels, you just need two collections
10:27lambda-smithI had to do it like this instead: (map #(Integer/parseInt %) '("1" "2")) is this a correct way of doing this?
10:27genzlergfredericks: I sorta want a cartesian product over vectors that would eventually join internal elements
10:27gfredericksgenzler: if you took the result from combo/cartesian-product and passed it to (map (fn [[a b]] (into a b)) ____) would that do what you want?
10:27genzlerit would be yes
10:27genzlerI was wondering if there was a shortcut
10:27gfredericksprobably not
10:28gfredericksseems pretty specialized
10:28genzleryeah
10:33gfredericksBronsa: ping
10:34Bronsagfredericks: pong
10:34gfredericksBronsa: I'm writing an email to clojure-dev about *assert* and wanted to clarify how compile-flag-style-dynamic-vars get used
10:35gfredericksthe fact that you call set! on them implies they have a thread-local binding, but I don't know where the thread-local binding gets set
10:35gfrederickswhich I only care about because I'm trying to verify my assumption that set! at the top level of a file only changes the var for that file
10:36Bronsagfredericks: look at clojure.main/with-bindings
10:37gfredericksah hah, I knew there must be a whitelist somewhere; I grepped for *assert* and that line came up but I accidentally overlooked it
10:37gfredericksBronsa: thanks!
10:38gfrederickshaha I like the stale docstring
10:38Bronsagfredericks: AFAIK set! ing *assert* is not a per-file/per-namespace local change
10:39gfredericksBronsa: well presumably if it's not then neither is set!ing anything else in this whitelist?
10:40gfrederickser...
10:40Bronsagfredericks: not necessarily, I don't recall if RT.load/Compiler.load bind any dyn var
10:40gfredericksI was assuming that this would have to be involved in calling require but I doubt anything in clojure.main could play that role
10:40gfredericksalright well I'm gonna run a test project to find out at least
10:41Bronsagfredericks: looking at RT.load I see that at least warn-on-reflection and unchecked-math get bound
10:41Bronsameaning set!ing them is not per-file/per-namespace local but at least load-local
10:42gfredericksoh okay, so there's a different whitelist
10:42Bronsalike, if you have (require 'foo) and you have (set! warn-on-reflection true) (ns foo (:require [bar])) ..
10:42Bronsaboth foo and bar will have w-o-r true
10:42Bronsabut the top-ns won't
10:42gfredericksright
10:43Bronsaotoh set!ing assert to true in foo should make assert true in the top ns too since there's no dynamic boundary in place
10:43gfredericksyep, just confirmed that set! with *assert* is leaky
10:44gfredericksso why did *assert* have a thread-local binding in the first place?
10:45gfredericksthe thing in clojure.main I guess?
10:45gfredericksyeah
10:45gfredericksBronsa: okay I think that sets me straight, thanks again
10:46Bronsayes
10:46Bronsanp
10:46gfredericks(inc Bronsa)
10:46lazybot⇒ 121
11:06sdegutisBronsa: Isn't (set! *warn-on-reflection* true) only good for the thread you're calling it on?
11:06sdegutisDon't you have to use alter-var-root instead?
11:08gfrederickssdegutis: it's normally used when compiling, which is single-threaded
11:08sdegutisOooh good point.
11:09sdegutisWhere should it be set, maybe in :injections?
11:09gfredericksor rather, you *do* only want it to change for the thread you're calling it on
11:09sdegutisBtw I'm using clojure.test along with clojure-tests-mode + Cider (in Emacs) and it's AWESOME.
11:09gfrederickssdegutis: normally you see (set! *warn-on-reflection* true) at the top level of the top of a file, and the intention is to only change it while compiling that file, and it works perfectly for that
11:10gfredericksif you want to enable it for your whole project & libraries that's a different use case
11:11sdegutisgfredericks: ahhh
11:14gfredericksleiningen has a feature specifically for that I think, and it might just boil down to :injections
11:15sdegutisWow clojure-mode has improved a lot over the past 2 years.
11:38sdegutisgfredericks: ah, found it -- leiningen has a :global-vars key that can be used in the :test profile etc
11:38gfredericksright
11:43sdegutisI don't understand this reflection warning:
11:43sdegutis"call to static method abs on java.lang.Math can't be resolved (argument types: java.lang.Number)."
11:43gfrederickssdegutis: what does the call look like?
11:43gfredericksMath/abs can take double/float/int/long so it has to be able to figure out which of those you want
11:43sdegutis,(-> 50 (- 33) (Math/abs))
11:43sdegutisThat.
11:43clojurebot17
11:44sdegutisI thought java.lang.Number is already statically resolved?
11:44gfrederickssdegutis: your code has literals in it exactly like that?
11:44sdegutisNope,
11:44gfredericksokay that's an important difference for reflection purposes
11:44sdegutis50 is gotten from clojure.core/frequences
11:45gfredericksyou could e.g. pass through (long) before Math/abs and that should make it go away
11:45sdegutisAh nice, thanks.
11:46gfredericks(defn long-abs [^long x] (Math/abs x)) ;; ← should also not reflect
11:46sdegutisAh nice.
11:47gfredericksI think the error msg was trying to tell you that the only thing it could tell about the arg to Math/abs was that it was a java.lang.Number and that wasn't enough to pick a particular impl
11:47Rurikwhat does ^long do?
11:48gfredericksit's a type hint, which the compiler uses for compiling interop and occasionally for compiling the code to use primitives
11:48gfredericksvirtually never necessary except for performance
11:49Rurikah, the java long type?
11:49gfredericksyeah, the primitive type in this case
11:49gfredericks(i.e., not java.lang.Long)
11:52sdegutisgfredericks: thanks a ton
11:53gfredericksnp
11:58sdegutisHow can you type-hint a binding inside (let)?
11:58sdegutisCan you just do this?
12:00sdegutis,(let [a [1 2 3], z (map long a), [_ ^:long b] z] (= b 2))
12:00clojurebottrue
12:01sdegutisNeat.
12:01gfredericksit'b be ^long instead of ^:long
12:01sdegutisOops.
12:01gfredericksbut that test doesn't tell you if it works or not
12:01sdegutis,(let [a [1 2 3], z (map long a), [_ ^long b] z] (= b 2))
12:01clojurebottrue
12:01sdegutisOh right.
12:01sdegutis,(binding [*warn-on-reflection* true] (let [a [1 2 3], z (map long a), [_ ^long b] z] (= b 2)))
12:01clojurebottrue
12:01sdegutis,(binding [*warn-on-reflection* true] (let [a [1 2 3], z (map long a), [_ b] z] (= b 2)))
12:01clojurebottrue
12:01gfredericksI think the best way to experiment is to set *warn-on-reflection* to true at your repl and play with things
12:01sdegutis:'(
12:01gfrederickssdegutis: that binding doesn't work either
12:01gfredericks(set! ...) at the repl should help
12:02sdegutis,(set! *warn-on-reflection* true)
12:02clojurebot#error {\n :cause "Can't change/establish root binding of: *warn-on-reflection* with set"\n :via\n [{:type java.lang.IllegalStateException\n :message "Can't change/establish root binding of: *warn-on-reflection* with set"\n :at [clojure.lang.Var set "Var.java" 221]}]\n :trace\n [[clojure.lang.Var set "Var.java" 221]\n [sandbox$eval125 invokeStatic "NO_SOURCE_FILE" -1]\n [sandbox$eval125 invo...
12:02sdegutisWelp, clojurebot isn't useful here.
12:02sdegutisThanks again gfredericks
12:03gfredericksnp
12:04sdegutisHmm this doesn't warn, gfredericks.
12:04sdegutis(let [a [1 2 3], [_ b] a] (= b 2))
12:04sdegutisI just set warning to true.
12:05gfredericksthere's no interop involved
12:05gfredericksso no reflection needed
12:05sdegutisHmmmmm....
12:05gfrederickstry calling (Math/abs b) or something
12:06sdegutis,(binding [*warn-on-reflection* true] (let [a (map #(Math/abs %) [1 2 3]), [_ b] a] (= b 2)))
12:06clojurebottrue
12:06sdegutisWell it works in my repl :D
12:06sdegutisThanks!
12:07gfrederickssdegutis: the binding call is a runtime thing so it's not having any effect
12:07sdegutisAnd yeah, this style of type-hinting works: (let [a [1 2 3], [_ ^long b] a] (Math/abs b))
12:07sdegutisIt stops the warning.
12:07gfredericksright
12:08sdegutisgfredericks: very true, my example was wrong
12:08sdegutis(the first one)
12:08sdegutisI'm surprised Clojure lets it work inside destructuring.
12:08sdegutisWoo! Time to fix a million reflection errors.
12:09sdegutisgfredericks: An incorrect type-hint has absolutely no effect on the running code, right?
12:09gfredericksyeah, the let macro preserves the metadata when it expands
12:09gfrederickssdegutis: 99% of the time yes
12:09gfrederickswell depends on if by "effect" you meant just correctness or also performance
12:10gfredericksobviously you can have worse performance if you screw up the type hinting and thereby get reflection
12:10gfredericksyou can also get incorrect code if the type-hint successfully causes the compiler to compile to the wrong interop method
12:10sdegutisI meant like introducing bugs.
12:10gfrederickstrying to think of way to demonstrate that
12:10sdegutisYeah that's what I had in mind.
12:11Bronsagfredericks: invalid type hints are also not always ignored
12:11sdegutisLike if I type-hinted .replace on some obscure PDF type rather than String or whatever.
12:11gfredericks,(defn make-bigint [s] (BigInteger. s))
12:11clojurebot#'sandbox/make-bigint
12:11gfredericks,(make-bigint "42")
12:11clojurebot42
12:11gfredericks,(defn make-bigint [^bytes s] (BigInteger. s))
12:11clojurebot#'sandbox/make-bigint
12:11gfredericks,(make-bigint "42")
12:11clojurebot#error {\n :cause "java.lang.String cannot be cast to [B"\n :via\n [{:type java.lang.ClassCastException\n :message "java.lang.String cannot be cast to [B"\n :at [sandbox$make_bigint invokeStatic "NO_SOURCE_FILE" -1]}]\n :trace\n [[sandbox$make_bigint invokeStatic "NO_SOURCE_FILE" -1]\n [sandbox$make_bigint invoke "NO_SOURCE_FILE" -1]\n [sandbox$eval95 invokeStatic "NO_SOURCE_FILE" 0]\n [san...
12:12gfredericks^ like that
12:12Bronsahttp://dev.clojure.org/jira/browse/CLJ-1674
12:12gfredericksthe first one reflected, the second one crashed
12:30Stalkr_I'm considering playing around with Clojure(Script) and emacs seems to be the superior editor between emacs and Vim. I have been using Vim for a few years though. Anyone recommend switching to emacs for Clojure with Evil mode?
12:33sdegutisI wonder if it also works in doto
12:36wasamasaStalkr_: feel free to give it a try
12:36DeraenStalkr_: I hear Spacemacs is quite good: https://github.com/syl20bnr/spacemacs But I use Vim myself, works fine in my opinion.
12:36wasamasaStalkr_: be aware though that even with vim keybindings, emacs is a much more complex beast than vim
12:37wasamasaStalkr_: so, while the IDE-style extensions are quite impressive, you will run into problems you'd have never encountered with vim :P
12:38DeraenVim also has access to (some of) the same IDE-style extensions that Emacs has
12:39Stalkr_Never heard about Spacemacs. I will have to give emacs/Spacemacs a shot, just wanted to hear others opinion :-)
12:39BronsaStalkr_: if you're not set to use either vim or emacs I'd suggest trying cursive
12:39Stalkr_That's a JetBrains IDE right?
12:39Bronsahttps://cursiveclojure.com/
12:40Bronsait's built in top of intellij, yes
12:42Stalkr_Ahh, thought it was from JetBrains too. I like to stay away from IDEs unless it is Java, C# or related but can't hurt to give it a try (y)
13:51red_revHey all. I want to learn clojure. Can anyone point me to an IDE for GNU/Linux?
13:52justin_smithred_rev: for a full IDE experience I'd go with cursive
13:52justin_smithred_rev: there are good bindings for emacs and vim too though
13:52red_revAwesome1 Thanks.
13:53red_revany tips for Switching over from OO based languages?
13:53justin_smithred_rev: what lang are you coming from?
13:54justin_smithRE: IDE I'd also suggest learning how to look up docs and reload namespaces in the repl - if nothing else just to realize none of it is magic and most of it is done with regular clojure features
13:56justin_smithred_rev: one of the most interesting differences between OO and FP is that good OO hides ugly stuff deep under class interfaces, and good FP pushes the ugly stuff outward to the interface -- this is even a clue about how to use them together nicely
13:57sdegutisCan you type hint a Java list?
13:58sdegutis^java.util.List<some.Thing> like that?
13:58justin_smithsdegutis: generics don't exist
13:58justin_smith^List is all you need
13:58sdegutisOh.
13:58sdegutisSo then I have to type-hint ^some.Thing when I take an item out?
13:58justin_smithsdegutis: well, generics kind of exist, but only inside the java compiler, which we don't use
13:58justin_smithsdegutis: yes, because the vm does not enforce anything about generics
13:59sdegutiswompwomp
13:59gratimaxsdegutis: are you doing this for java interop?
13:59red_revJustin_smith I've programmed mostly in python and Java
13:59sdegutisgratimax: yeah, using Stripe's Java SDK.
13:59sdegutisJust adding type hinting for it.
13:59sdegutisThe new magit rocks btw.
14:00gratimaxyou might want to wrap it lightly in java classes that take clojure collections instead of lists
14:01gratimaxI personally do that for java interop just so that it stays mostly clojure datastructures, even if under the hood it's not
14:02sdegutisAhh nice idea.
14:04Bronsagratimax: clojure collections already implement many java collection interfaces
14:04gratimaxthat's true
14:07gratimaxI guess I should have elaborated, I meant more that it takes clojure collections with maps, etc. that get converted to the equivalent java objects
15:25justin_smith,(defn youngest-datable [age] (+ 7.0 (/ age 2)))
15:25clojurebot#'sandbox/youngest-datable
15:25justin_smith,(clojure.string/join "," (map (juxt identity, youngest-datable) (range 50)))
15:25clojurebot"[0 7.0],[1 7.5],[2 8.0],[3 8.5],[4 9.0],[5 9.5],[6 10.0],[7 10.5],[8 11.0],[9 11.5],[10 12.0],[11 12.5],[12 13.0],[13 13.5],[14 14.0],[15 14.5],[16 15.0],[17 15.5],[18 16.0],[19 16.5],[20 17.0],[21 17.5],[22 18.0],[23 18.5],[24 19.0],[25 19.5],[26 20.0],[27 20.5],[28 21.0],[29 21.5],[30 22.0],[31 22.5],[32 23.0],[33 23.5],[34 24.0],[35 24.5],[36 25.0],[37 25.5],[38 26.0],[39 26.5],[40 27.0],[41 2...
15:37TimMcjustin_smith: "Asking for a friend."
15:37justin_smithTimMc: it's a classic formula, I find the results for lower inputs hilarious
15:37TimMcup :-)
15:37TimMc*yup
15:37justin_smith"if you are an infant, the youngest person you can date is 7"
15:51TimMcI wonder if there is an age that most people agree on as a lower bound for inputs to that formula.
15:52justin_smithTimMc: very likely 14
15:52TimMcor if it just gets progressively more absurd
15:52justin_smith,(youngest-datable 100)
15:52clojurebot#error {\n :cause "Unable to resolve symbol: youngest-datable in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: youngest-datable in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6704]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve...
15:53justin_smith,(defn youngest-datable [age] (+ 7.0 (/ age 2)))
15:53clojurebot#'sandbox/youngest-datable
15:53justin_smith,(youngest-datable 100)
15:53clojurebot57.0
15:53justin_smithyeah, I think that aproximation could be improved
15:56justin_smithlike any two people over 80 should be able to date, I see no reason a 500 year old and a 100 year old wouldn't get along just fine
16:00diyfupeco.(youngest-datable 42)
16:00diyfupeco,(youngest-datable 42)
16:00clojurebot28.0
16:00diyfupeco^ That is wrong, sorry guys. :D
16:00justin_smithyeah, I didn't make the formula up - now I wonder where it comes from...
16:01gfredericksjustin_smith: you say that just because you can't relate to either of them
16:01gfrederickswait till you're 100 and I think you'll change your mind about the 500yo's
16:01justin_smithhaha
16:02justin_smith"Elijah Muhammad (1897-1975) said that the ideal age of a man's wife was half his age, plus seven."
16:03diyfupecoVery subjective view.
16:03gfredericksideal != youngest-allowable
16:03diyfupeco:D
16:03justin_smithgfredericks: yeah, he was brought up as an outlier
16:03diyfupecoWell, that would be 14 in Germany I think, no matter what age.
16:03justin_smithhttp://www.onehalfplusseven.com/home/about-the-half-your-age-plus-seven-rule
16:03TimMcwait wait wait, this is the Nation of Islam guy?
16:03justin_smithyeah
16:03TimMcfascinating
16:05justin_smith"Although the origin of the rule is unclear, it is sometimes considered to have French origin.[20] There is no scientific evidence to support the rule."\
16:05justin_smithhttps://en.wikipedia.org/wiki/Age_disparity_in_sexual_relationships#The_.22half-your-age-plus-seven.22_rule
16:05TimMcI can't believe someone registered a domain for that.
16:05diyfupeco:D
16:05justin_smitholdest citation is 1901
16:06justin_smithand yeah, the version from 1901 was "ideal age" - not lower limit
16:06justin_smithideal age for bride of course
16:06TimMcInteresting that as the two people age, they can only transition from "unacceptable" to "acceptable".
16:07diyfupecoYou know what the problem is? That we are measuring age in years and not experience.
16:07justin_smithif only our popular understanding of aging was more nuanced, the range could narrow or expand following some polynomial
16:08justin_smithhusband who is her age minus 7 * 2, not that anybody cares what is ideal for her in 1901 anyway :)
16:08diyfupecoTimMc: income = age * 1.500+
16:09diyfupeco(Was that to sexist?)
16:09TimMcprobably
16:09TimMcalso you didn't specify units
16:09diyfupeco:(
16:10diyfupecoI am terrible at this.
16:10justin_smithwait, "income = age * 1.5" could approximate us hourly wages in dollars ...
16:10justin_smithno, starts too high
16:10TimMcway too high if you're doing years and dollars
16:11justin_smithyeah
16:11diyfupecoI was thinking in €
16:11diyfupecoand over a year
16:11justin_smithoh, where . is american ,
16:12diyfupecoYes. :D
16:14justin_smithOK how about simplest formula that would approximate height by age
16:15diyfupecoI can't follow.
16:15justin_smitheg f(age) ~= average height
16:16justin_smithwith bonus for exceeding accuracy or simplicity (ideally both)
16:17TimMcNext you need a metric for "simplicity".
16:17justin_smithwe'll know it when we see it
16:26diyfupecoHm, I could provide data about age samples but not about height :D
16:28diyfupecoHm, what I do wonder though if sexuality matters.
16:29justin_smith,(defn age->inches [age] (+ 30.0 (* (min age 17) 2.41))) ; matches this chart for white boys pretty well http://halls.md/chart/BoysHeightWhite.gif
16:30clojurebot#'sandbox/age->inches
16:31diyfupecojustin_smith: What about conditions which lead to dwarfism (I hope this is a politically correct term in english)?
16:32justin_smithhaha, the term is fine and yeah of course a formula accounting for dwarfism would be much different
16:34diyfupecoWell, in german the same term translated is not ok. :D
16:34justin_smithlike you would need an input for chromosomes or something
16:34diyfupecoHm.
16:35diyfupecoIf we had chromosome input we could just find the perfect match, since some studies found that we search for the genetical opposite.
16:36justin_smithI'm sure we'd have mapping from various chromosome sets to charts like the above but with much narrower distribution ranges, and then a near-linear function (through the range of growth ages) for each chromosome set
16:36justin_smithsorry, I'm not sure, I just suspect
17:14arkhanyone used raynes/conch before? I've going over the code for a while now and I just can get e.g. the following last function to work: https://www.refheap.com/6617/raw
17:14arkh*I've been
17:14arkh*can't
17:14arkhalso, can't type
17:15gfredericksarkh: I've used it a few times
17:15justin_smithI've used it, but ended up just using ProcessBuilder directly
17:16arkhdoes the last function in the above refheap look like it should still run?
17:16arkhsorry, probably tough to say just be eyeballing it
17:16justin_smitharkh: you have an "unbuffer" program on your path?
17:17arkhI don't - I ended up doing a (let-programs ..) instead with the path to ssh specified
17:17arkhI should have mentioned that
17:17arkhit was the one change I amde
17:17arkh*made
17:19arkh(let-programs [p "/bin/cat"] (let [proc (p "stuff")] ... ) returns with a non-zero error code, too
17:20arkhwith matching parens of course
17:20fierycatnetIs there a way to read from stdio and return these values in a vector/list form? ex: 1 2 3 is entered and it returns [1 2 3]. So far I can only get it to return "1 2 3" as a string or "1 2 3" as a persistent vector.
17:20justin_smitharkh: and you have a file called "stuff" in the current directory?
17:21arkhoh
17:21arkhI don't!
17:21arkhok - echo works
17:21justin_smithfierycatnet: ##(mapv read-string (clojure.string/split #" " "1 2 3")) maybe?
17:21lazybotjava.lang.ClassCastException: java.lang.String cannot be cast to java.util.regex.Pattern
17:21justin_smitherp
17:22justin_smithfierycatnet: ##(mapv read-string (clojure.string/split "1 2 3" #" ")) maybe?
17:22lazybot⇒ [1 2 3]
17:22justin_smithit really depends on how much you trust the input source and what you really want to do with the data coming in I guess
17:23fierycatnetjustin_smith: that might just work, i'll play with it, thanks. It's just for an exercise, nothing critical.
17:23justin_smithfierycatnet: perhaps you could string/split each line of input and work with the strings - that's less error-prone
17:27fierycatnetI think I've tried similar code before but I only used map instead of mapv, I guess there is a significant difference between the two? I was getting errors when I tried regular map function.
17:28justin_smithfierycatnet: I only used mapv because you specified the result being in a vector
17:28justin_smithother than that (and mapv not being lazy, because vectors are not lazy) they are the same
17:28arkhany thoughts on the following use of conch? https://www.refheap.com/108955
17:28fierycatnetI was doing something wrong then
17:29justin_smitharkh: are you getting the output from stderr?
17:30justin_smitharkh: because iirc the prompts from ssh before connecting will be on stderr
17:30justin_smitharkh: may be easier to interact with a less tricky interactive program first (eg. cat or ed)
17:31arkhI'm able to get non-persistent programs to run, like cat
17:31justin_smithso next step would be interactive but less tricky (ed is a good one, as is bc)
17:31arkhwhen I run the above (from refheap) I get this to my console: rwaters@localhost's password:
17:31arkhhmm
17:31justin_smiththat sounds like an expected output...
17:31arkhyeah, I could try bc
17:32arkhit is expected, but I can't seem to hook into it at all
17:32arkhI can't grab (:stderr proc), etc.
17:32justin_smithwell, you need to get a handle to proc stdin from conch right
17:32arkheventually
17:32justin_smithI think :seq true is incompatible with the kind of interaction you want
17:33arkhoh
17:33justin_smith:seq is for nice packaged output of non-interactive stuff iirc
17:33justin_smitharkh: what I found is that I could make a ProcessBuilder, launch that, get stdin, stdout, stderr from the resulting process, and interact with those via .read and .write and .flush
17:34justin_smithand it was simpler for me than using conch was
17:34justin_smithymmv of course, I often find clojure libs that wrap some java libs are just a pain in the ass
17:34arkhsure - I might do that too
17:35justin_smithbut maybe you just need to find some alternative for the :seq option
17:35justin_smithsomething that lets you be more interactive, though I suspect that will involve .read and .write and .flush calls
17:35arkhI've been looking into https://github.com/ronniedong/Expect-for-Java which uses jsch (same as clj-ssh) and some nice java.nio non-blocking, selectable channels but thought conch would be a faster way to get to the end goal (if I could just get it to work)
17:36arkhI was a little concerned with how futures are used in conch but I guess the threads would be returned to clojure's thread pool with the process exits
17:37justin_smiththat's how futures work, yeah. And they use an expandable pool.
17:37arkhoh - I thought it was fixed; good to know
17:37justin_smithagents have two pools, a fixed send pool and expandable send-off pool, futures share the latter
17:38arkhok. And core.async has its own fixed thread pool?
17:38justin_smithyup
17:38arkhcool
17:38justin_smith2*nprocs+42
17:40arkhthanks for your help
17:46justin_smithno problem, best of luck!
18:42TimMcjustin_smith: nprocs/2+7 ;-)
19:58python476hi
20:00python476noob question: (.. (new JFrame) getContentPane add (new JLabel "wat")) fails saying `add` can't be found
20:01justin_smithpython476: I'm thinking add needs some arg
20:02python476justin_smith: aight, I'll look into it
20:03justin_smithpython476: my suspicion is (.. (new JFrame) getContentPane (add (new JLabel "wat)))
20:03python476justin_smith: right, I just tried that, so ..nooby
20:03python476thanks
20:03justin_smiththe better version of that is (.. (Jframe.) getContentPane (add (JLabel. "wat")))
20:07amalloyi suspect (doto (JFrame.) (-> (.getContentPane) (.add (JLabel. "wait")))) is better still, because you surely need to return the jframe
20:08amalloyyou can use .. if you want, but i think -> reads better basically all the time even if it's more characters
20:08python476amalloy: also more readable
20:08python476hehe
20:08python476but I'm not comfy with the subtle difference between . .. -> and such
20:08python476I was experimenting
20:09amalloydoto and -> go together like peanut butter and jelly, for java interop
20:35mdeboardHi, how might I simplify this sexpr: (json/read-str (:message (json/read-str js :key-fn key->keyword)) :key-fn key->keyword)
20:35mdeboardThat is, is there some kind of "reduce" call I can use? I know I can write a function to do so
20:36mdeboardsome specialized function, just asking out of curiosity
20:36amalloyyou have a string representing json object that contains a field whose value is a string representing another json object?
20:36amalloy(i heard you like json)
20:37mdeboardYeah, it's like {"Message" "{\"foo\" : \"bar\"}"}
20:37mdeboardYeah I'm processing AWS events
20:37mdeboardthis is what they do :(
20:37justin_smith(let [rd #(json/read-str % :key-fn key->keyword)] (-> js rd :message rd))
20:37TEttinger(inc justin_smith)
20:37lazybot⇒ 292
20:37TEttinger(inc amalloy)
20:37lazybot⇒ 296
20:37mdeboardOk that's basically what I was thinking justin_smith , thanks
20:37TEttinger(inc yo dawg)
20:37lazybot⇒ 1
20:37mdeboardIt just vaguely looks like a reduce
20:38mdeboardDidn't know if there was some higher order deal
20:38amalloymdeboard: if you had more layers, it would be worth making a reduce out of it
20:38mdeboardYeah, just curious
20:38Bronsalooks more like a prewalk than a reduce to me
20:39amalloy(reduce (fn [m f] (f (json/read-str m :key-fn key->keyword))) s [:message identity])
20:41amalloyBronsa: that wastes a lot of effort on a json object with high branching factor where you only care about one deep path
20:41Bronsaah, risght
20:46arrdemgfredericks: just saw your ML post... I think the "real" anwer is that `ns` should automate that for you, but it'll never happen
20:47agumonkeyany emacs user ? emacsconf 2015 is on
20:47agumonkeyhttp://www.twitch.tv/emacsconf , also #emacsconf
20:55justin_smithgfredericks: perhaps your own macro, which uses the value of *gfredericks-assert*
20:57arrdemI mean... what we really need is compiler support for the JVM assert stuff
20:58justin_smithalso, related, I have a pet peeve about code that changes behavior if *assert* is turned off (beyond just halting and catching fire of course)
20:58justin_smitharrdem: would that solve gfredericks issue though?
20:58Bronsaarrdem: there's no assert support in the jvm
20:59arrdemBronsa: I thought there was a JVM flag to disable Java asserts
20:59arrdemobviously no assert instr
20:59Bronsaarrdem: it just uses an internal field
21:00justin_smitharrdem: there is definitely a flag for the jvm yeah see this convo https://groups.google.com/forum/#!topic/clojure/B9ba-ExZGzI
21:01arrdemjustin_smith: Bronsa is as usual correct, just uses the AssertTest.$assertionsDisabled field
21:01arrdemso there's a java.lang.AssertTest class or something that holds the on/off bit
21:01rhg135Is there any data structure that supports near constant time retrieval of a random element and no duplicates. A set would fulfill the latter but not the former
21:09gfredericksjustin_smith: yeah having to rewrite the whole assert/*assert* thing does kind of suggest that it's not covering all the use cases :P
21:15amalloyrhg135: i think you would do it by taking the data structure that is currently used for sets, and adding to each node a count of how many items are in each of its subtrees, and use that to weighted-choose which branch to go down
21:17rhg135Sounds like it'd require a lot of code, amalloy, guess it'll have to be O(n) for now
21:17justin_smithamalloy: would that interact weirdly with structural sharing?
21:17amalloyjustin_smith: i don't think so. you should still only have to rebuild the path back to the root, right?
21:17justin_smithrhg135: what about a tuple with set and vector, and only inserting in the vector if the item isn't in the set yet
21:17justin_smithamalloy: fair point, yeah
21:18amalloyjustin_smith: the problem with a set/vector pair is that you can't remove stuff from the middle of the vector
21:18justin_smithyeah, not cheaply at least, but he didn't mention removal :P
21:18amalloyoh. i misread retrieval
21:19amalloyyeah if you never take anything out, a set/vector pair is fine
21:20justin_smithand even if he does occasional removals, it's still better than O(n) insertion which was the other interem plan
21:20justin_smith*interim
21:20rhg135Yeah, I don't plan on removal, justin_smith
21:20rhg135even than it'd be uncommon
21:21justin_smithso yeah, I think that pair of set/vector is the easiest thing, and will perform decent enough
21:21rhg135my other plan was keep a set and do an O(n) conversion to a vector
21:21rhg135on demand for retrievals
21:22rhg135how would a set/vector pair work though?
21:22arrdemso if you want "only once" insertions, what name are you trying to retrieve these things by?
21:23rhg135name?
21:23justin_smithrhg135: for conj you check set membership, if absent conj to both, for presence / lookup you just use the set, for random selection use the vector
21:23arrdemwhich is not unique? I'm just wondering if you're overthinking a {name -> T{:name = name}} structure of some sort
21:26rhg135I'm sorry, arrdem, my brain is not cooperating.
21:27arrdemAll good I have no idea what you're actually trying to do and may have proposed something nonsensical
21:28rhg135I'm basically hava a structure of {vector x} where x is a structure where I can get items out randomly quickly and has no duplicates
21:32rhg135what interfaces do I have to implement then?
21:32Bronsaall of them!
21:32arrdemlol
21:33arrdemwait but which are interfaces and which are implementation details...
21:33rhg135brb
21:34Bronsarhg135: IPersistentMap, IPersistentSet, IObj probably
21:34justin_smithBronsa: what about the one for nth?
21:34justin_smithI forget which one that is even
21:34BronsaIEditableCollection if you want to be fancy
21:34justin_smithfor rand-nth he needs to support nth
21:35Bronsawait, he wants set+vector semantics
21:35justin_smithyeah
21:35Bronsathen IPersistentVector, IPersistentSet, IObj
21:35Bronsajustin_smith: nth is Indexed
21:35justin_smithaha
21:35Bronsawhich is a super interface of IPersistentVector
21:37Bronsa,(let [ifs #{clojure.lang.IPersistentVector clojure.lang.IPersistentSet clojure.lang.IObj}] (merge ifs (map supers ifs)))
21:37clojurebot#{clojure.lang.IPersistentSet clojure.lang.IPersistentVector clojure.lang.IObj (#{clojure.lang.IPersistentCollection clojure.lang.Counted clojure.lang.Seqable} #{clojure.lang.IPersistentStack clojure.lang.Sequential clojure.lang.Associative clojure.lang.Indexed clojure.lang.Reversible ...} #{clojure.lang.IMeta})}
21:37Bronsa,(let [ifs #{clojure.lang.IPersistentVector clojure.lang.IPersistentSet clojure.lang.IObj}] (apply merge ifs (map supers ifs)))
21:37clojurebot#{#{clojure.lang.IPersistentStack clojure.lang.Sequential clojure.lang.Associative clojure.lang.Indexed clojure.lang.Reversible ...} clojure.lang.IPersistentSet clojure.lang.IPersistentVector #{clojure.lang.IMeta} #{clojure.lang.IPersistentCollection clojure.lang.Counted clojure.lang.Seqable} ...}
21:37Bronsa,(let [ifs #{clojure.lang.IPersistentVector clojure.lang.IPersistentSet clojure.lang.IObj}] (apply merge ifs (mapcat supers ifs)))
21:37clojurebot#{clojure.lang.IPersistentStack clojure.lang.Sequential clojure.lang.IPersistentSet clojure.lang.Associative clojure.lang.IPersistentVector ...}
21:37justin_smithnice
22:05rhg135Seems like a lot of work for little gain
22:08amalloyrhg135: yes, i would suggest not actually deftyping this up, but just writing a couple functions that manipulate a tuple in the ways you actually need
22:09amalloyyou can look at the source for amalloy/ordered if you want to see all the nonsense you have to implement to be a good citizen; it's another deftype around a set and a vector
22:09rhg135Good to know I'm not just being lazy, amalloy
22:10amalloyyou only really need to make a deftype if you want to be able to pass these things to oblivious other functions that will operate on them like ordinary collections
22:10justin_smithgreat point, you can just get away with a pair of items and a few functions otherwise
22:13rhg135Hmm