#clojure logs

2016-03-10

06:43amoe_it seems strange to me that (def blah nil) (blah) => NullPointerException. I mean, it totally makes sense, but I wonder why there is not a more specific error message.
06:55tdammersamoe_: because clojure doesn't abstract away all the JVM peculiarities
06:55tdammersfor the same reason, you'll also see the underlying Java class names and such in stack traces instead of their clojure appearances
08:08faxmodemI've been successfully using lein try a lot and it's awesome
08:08faxmodemhow can I use it for a local project?
08:08faxmodeme.g. 'lein try .'
08:15ridcully_faxmodem: isnt that just lein repl then?
08:17faxmodemridcully_: I guessed the same
08:17faxmodembut then the deps arent' being fetched
08:17faxmodemso I guess I'm just looking at the lein command to do that :)
08:19ridcully_oh you mean you want to temporarily try it out with an existing project
08:19ridcully_i either add it then or use lein plz. i only ever used try without projects
08:37faxmodemyes
08:38faxmodemlein plz is that shipped with leiningen?
08:40tdammerslein *is* leiningen
08:40ridcully_plz is another plugin
08:40tdammersoh nm
09:08faxmodemtdammers: then 'lein deps && lein repl' should be enough to get started?
09:08faxmodems/tdammers/ridcully_/
09:15ridcully_faxmodem: yep (even without the deps first)
09:15ridcully_your project.clj should contain the deps beforehand
09:22faxmodemridcully_: I thought it did :)
09:22faxmodemridcully_: so lein repl should run deps
09:40faxmodemso when I run lein deps, where do the deps get stored?
09:42schmirfaxmodem: ~/.m2/
09:42faxmodemthanks!
09:59sdegutisI'm about to use reduce-kv for the first time ever!
10:10fodhttps://www.youtube.com/watch?v=-W6as8oVcuM
13:20backnforthHello, can someone explain to me how to short snipper of code works: http://pastebin.com/y8tHJ47Z . Really I'm trying to understand how "i" and "y" obtain their values, how does the "?" work, and how does filter, identiy, and map-indexed work? And whether it was right for me to add a println to the main when calling the questioned function.
13:21hiredman? isn't anything special
13:21hiredman,(let [x?y?z 1] x?y?z)
13:21clojurebot1
13:22hiredmanfilter, identity, and map-indexed all have docs you can read on clojure.org
13:23backnforth,(let [x?y?z? 1] x?y?z?)
13:23clojurebot1
13:23hiredmanwhen you added the println, you replaced the call to listread with the call to println
13:24backnforthHow should the return of the function be printed?
13:42backnforthI'm having a hard time understanding how "filters" how.
13:44backnforthOh, so it returns a lazy sequence for which the "pred" holds true,
13:51backnforthAnyone know where I may find a Clojure tutor?
13:52justin_smithbacknforth: have you checked for nearby clojure meetups?
13:52backnforthNone unfortunely.. I would even be willing to pay for a tutor.
13:53justin_smithif remote tutoring is an option, maybe you can find someone here, or on the clojurians slack channel
13:54backnforthI would prefer remote tutoring
13:54backnforthI'll also check the slack channel
13:55rhg135We don't talk about that place
13:55justin_smithI'd offer but I'm very busy with the day job at the moment (though I do make time to check in and answer questions here)
13:55justin_smithhaha
13:56backnforthI have all day, justin_smith. If you'd like to help me later I could try to have a session prepared for then.
13:56backnforthOr possibly another day.
14:04justin_smithbacknforth: what I meant was I can probably answer one-off questions on this channel on a case by case baisis but can't promise to do one on one tutoring right now
14:04justin_smithbut maybe someone else here is available
14:05justin_smithbacknforth: in my experience if you share a link to some code and say "what's wrong with this code" you'll probably get a lot of good advice
14:06backnforthok
14:30backnforthWhy do variables often have ":" added in front of them?
14:31justin_smithbacknforth: :foo is not a variable, it is a keyword
14:31justin_smithbacknforth: keywords are a special type that is self evaluating
14:31backnforthA keyword to the function? And the functions should know how this keyword matches?
14:31justin_smithbacknforth: wat
14:32backnforthHow might they be self evaluating?
14:32justin_smith,:foo
14:32clojurebot:foo
14:32justin_smiththat's what I mean - they always stand for themselves
14:32amalloybacknforth: :charles is a constant value, just like 5 is a constant value
14:32justin_smithright, that might be a clearer way to say it
14:33amalloywhereas there are other structures that don't evaluate to themselves. lists, for example: the list (+ 1 2) doesn't evaluate to the list (+ 1 2), it evaluates to 3
14:34backnforth ,(= :charles :charles)
14:34clojurebottrue
14:34backnforth,(= :charles charley)
14:34clojurebot#error {\n :cause "Unable to resolve symbol: charley in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: charley in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6688]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: charley i...
14:35backnforth,(let :charles 3)
14:35clojurebot#error {\n :cause "let requires a vector for its binding in sandbox:"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "let requires a vector for its binding in sandbox:"\n :at [clojure.core$let invokeStatic "core.clj" 4333]}]\n :trace\n [[clojure.core$let invokeStatic "core.clj" 4333]\n [clojure.core$let doInvoke "core.clj" 4325]\n [clojure.lang.RestFn invoke "RestFn.java" 467...
14:35justin_smithand charley is not self-evaluating - clojure looks for a binding (and throws an error if it does not find one)
14:35justin_smithbacknforth: for the top level you need def, and keywords are not valid bindings
14:35backnforthSo i assume I can't assume values to :charles considering :charles is its value.
14:35justin_smithbacknforth: what does that mean?
14:36justin_smithyou can't bind a value to :charles because it always is just :charles if that's what you mean
14:36backnforthYes, thank you.
14:36justin_smithunlike charley which can be bound
14:36justin_smith,(def charley "just some guy")
14:36clojurebot#'sandbox/charley
14:36backnforthIt's so simple.
14:37justin_smithI like to think so, heh
14:42backnforth,(= poopy poopy)
14:42clojurebot#error {\n :cause "Unable to resolve symbol: poopy in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: poopy in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6688]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: poopy in this...
14:42backnforth,(= :poopy :poopy)
14:42clojurebottrue
14:55TMA,(= 'karlos 'karlos) ; backnforth
14:55clojurebottrue
14:57justin_smith,(apply = (map (comp symbol name) ["foo" :foo 'foo]))
14:57clojurebottrue
14:57backnforth,(= 'karlos 'karlos)
14:57clojurebottrue
14:59TMAbacknforth: 'thing prevents the evaluation of the thing; in other words, the result of 'thing is thing for whatever the thing might be. see:
14:59TMA,(+ 1 2)
14:59clojurebot3
14:59TMA,'(+ 1 2)
14:59clojurebot(+ 1 2)
15:01backnforth,:(+ 1 2)
15:01clojurebot#<RuntimeException java.lang.RuntimeException: Invalid token: :>
15:01backnforth,(= 'a 'a)
15:01clojurebottrue
15:01backnforthThen why used :thing?
15:08TMA,(:foo {:foo 1})
15:08clojurebot1
15:08TMA,('foo {'foo 1})
15:08clojurebot1
15:10TMAbacknforth: no idea, :foo is a keyword, 'foo is a symbol; there might be some reason I do not know why they are separate
15:10TMAbacknforth: maybe there is something with namespaces that make :foo better in some contexts than 'foo
15:41justin_smithTMA: 'foo is usually used in those cases where you eventually want to look up foo (eg. it's a var to resolve / eval later), while :foo doesn't have that implication
15:42justin_smithTMA: of course we could just use 'foo instead of :foo, but that adds a little bit of ambiguity about what kind of lookup / meaning we expect with that symbol
15:42TimMcThat's a good way of putting it.
15:42justin_smithI mean, really, we could use strings for all of these things anyway, the rest is nuance
15:42justin_smithTimMc: thanks
15:50TimMcI usually put it as "symbols usually refer to code, keywords are usually used in data structures" but of course code is data so... :-P
16:16matt______a little bit confused about an error i'm getting using deftype and implementing an interface. stripped-down example is here: http://pastebin.com/AVupasmR
16:16amalloykeywords are faster too
16:17amalloyinterface methods are interop calls. they're not functions
16:18matt______nailed it, amalloy. thanks.
16:25sdegutisCan (for [x xs, y ys] (get-in y [...])) be simplified/combined somehow?
16:27amalloyi don't think so
16:34sdegutisThanks.
16:45justin_smithamalloy ♥'s for
17:16randomcharherewhy does this not work (apply inc '(1 2 3 4)) but this does (apply + '(1 2 3 4)) ?
17:18yellow13inc is a function of only one argument
17:18yellow13+ receives 1..n argr
17:19TEttinger0..n
17:19TEttinger,(+)
17:19randomcharheremy assumption was that apply would iterate of the arg?
17:19clojurebot0
17:23yellow13actually apply take the args from [1 2 3 ...] and then call (fn arg1 arg2 arg3 ...)
17:23macroliciousI'm loving testing db calls from within my code via nREPL but I'm still unclear what it is in functional languages that make this possible and why it's not in other types of languages... can someone explain?
17:26randomcharhereevidently map was design to iterate over args
17:28randomcharhereDb calls can be made from within other languages nothing to do with funtioanl languages its just more imediate with repl *shrug*
18:26rhg135there's an assembly repl out there. not functional at all
18:26rhg135it's mostly the power of repls and recognizing their utility
18:44TimMcmacrolicious: Being able to define functions outside of classes makes it easier to define functions. :-)
18:45TimMcYou could imagine a Java REPL that allows you to add static methods to a ReplFunctions class.
18:45TimMcand then fix up references to make it work
18:46tjdI'm calling a function with keyword args, (foo :a 1 :b 2), if I have a map {:a 1 :b 2}, how can I effectively execute (foo {:a 1 :b 2})?
18:48TEttingerapply, I'd say, but I am not sure I understand tjd
18:48TEttingerohhh
18:48TEttingernvm
18:49tjdThe keyword-args map is passed in to me, and I'm just sending it along the way. Really don't want to break it apart, because what
18:49tjdBecause the content is implementation detais that my function doesn't care about
18:49TEttinger,(defn foo [{a :a b :b}] (+ a b))
18:49clojurebot#'sandbox/foo
18:49TEttinger,(foo :a 1 :b 2)
18:49clojurebot#error {\n :cause "Wrong number of args (4) passed to: sandbox/foo"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (4) passed to: sandbox/foo"\n :at [clojure.lang.AFn throwArity "AFn.java" 429]}]\n :trace\n [[clojure.lang.AFn throwArity "AFn.java" 429]\n [clojure.lang.AFn invoke "AFn.java" 44]\n [sandbox$eval50 invokeStatic "NO_SOURCE_FILE" 0]\n [sandbox$eval5...
18:50TEttingercan't remember how this is done
18:51TEttingersomething like the first example here, https://stuartsierra.com/2010/01/15/keyword-arguments-in-clojure ?
18:51tjdThis works: (apply foo (flatten (into [] {:a 1 :b 2})))
18:51tjdNot proud of that, though.
18:51TEttingerohhh, :keys
18:52TEttinger,(defn foo [& {:keys [a b]}] (+ a b))
18:52clojurebot#'sandbox/foo
18:52TEttinger,(foo :a 1 :b 2)
18:52clojurebot3
18:53matt______TEttinger: i think you're solving a different problem than tjd. :)
18:53TEttinger,(foo (apply into [] {:a 1 :b 2}))
18:53clojurebot#error {\n :cause "Key must be integer"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Key must be integer"\n :at [clojure.lang.APersistentVector invoke "APersistentVector.java" 292]}]\n :trace\n [[clojure.lang.APersistentVector invoke "APersistentVector.java" 292]\n [clojure.core$transduce invokeStatic "core.clj" 6598]\n [clojure.core$into invokeStatic "core.clj" 6614]\n [...
18:53TEttinger,(apply foo (apply into [] {:a 1 :b 2}))
18:53clojurebot#error {\n :cause "Key must be integer"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Key must be integer"\n :at [clojure.lang.APersistentVector invoke "APersistentVector.java" 292]}]\n :trace\n [[clojure.lang.APersistentVector invoke "APersistentVector.java" 292]\n [clojure.core$transduce invokeStatic "core.clj" 6598]\n [clojure.core$into invokeStatic "core.clj" 6614]\n [...
18:53TEttingeryeah, I'm still figuring out kwargs, matt______
18:54tjd,(defn x [& {:keys [a b]}] (println a b))
18:54clojurebot#'sandbox/x
18:54matt______well, he wants all the keys and all the values passed to a function in order, it seems.
18:54tjd,(apply x (flatten (into [] {:a 1 :b 2})))
18:54clojurebot1 2\n
18:55tjdAlthough I can't help but think I should insist that my caller pass in a function instead of arguments to a sub-function.
18:55TEttinger,(apply foo (apply concat {:a 1 :b 2}))
18:55clojurebot3
18:55TEttinger,(apply x (apply concat {:a 1 :b 2}))
18:55clojurebot1 2\n
18:55tjdoh my
18:55TEttingerit doesn't order them though
18:56TEttinger,(apply x (apply concat {:a 1 :b [1 2 3]}))
18:56clojurebot1 [1 2 3]\n
18:56TEttingerwhich flatten would break
18:56tjdboo
18:56TEttingerapply concat only does one level of "flattening"
18:57TEttingerhash-maps are never ordered
18:57TEttingerso if you pass a hash-map there's no guarantee of order
18:57matt______i meant as k1 v1 k2 v2, etc.
18:58TEttingerthat's a kwarg thing
18:58TEttinger,(defn foo [& {:keys [b a]}] (+ a b))
18:58clojurebot#'sandbox/foo
18:58TEttinger,(apply foo (apply concat {:a 1 :b 2}))
18:58clojurebot3
18:59matt______i don't think so. he said he doesn't care about the keys or values and is just acting as proxy.
18:59amalloy~mapply
18:59clojurebotYou have to do something like (defn mapply [f & args] (apply f (apply concat (butlast args) (last args)))), which just goes to show why unrolled keyword args are a bad idea
18:59matt______i mean, he also said he has a solution. in (apply foo (flatten (into [] {:a 1 :b 2})))
19:00TEttingerdothat isn't a solution, matt______
19:00TEttingerflatten kills any nesting
19:00amalloy~flatten
19:00clojurebotflatten is rarely the right answer. Suppose you need to use a list as your "base type", for example. Usually you only want to flatten a single level, and in that case you're better off with concat. Or, better still, use mapcat to produce a sequence that's shaped right to begin with.
19:00matt______well, maybe that matters.
19:00matt______tjd: does nesting matter for your use case?
19:01tjdnesting does not matter
19:01TEttingerflatten's fine but still terrible then
19:01tjd:-)
19:01amalloypeople who think nesting doesn't matter are (a) usually wrong, and (b) working with data simple enough that mapcat or concat is easy
19:01clojurebotIk begrijp
19:01amalloynice
19:02TEttinger~people who think nesting doesn't matter
19:02clojurebotTitim gan éirí ort.
19:02TEttinger~people
19:02clojurebotyou mean BugFactorySingletons
19:02TEttingerhaha
19:02amalloy~people who think nesting doesn't matter are (a) usually wrong, and (b) working with data simple enough that mapcat or concat
19:02clojurebotpeople who think nesting doesn't matter are (a) usually wrong, and (b) working with data simple enough that mapcat or concat is easy
19:02TEttingermm
19:09matt______fair enough
19:09matt______tjd: unflattened: (apply foo (apply concat (into [] {:a 1 :b 2})))
19:10TEttingerdon't need the into []
19:10matt______good call.
19:11TEttingerbut yeah, this does seem a bit odd to have the unrolled kwargs mixed up with maps of those args
19:11TEttingeramalloy's mapply example is a good point
19:31X-warriorhey guys I'm new to clojure and I'm doing a project to learn it, I'm thinking if my code is on the right way of doing things on clojure and if it is readable. Could anyone take a look at it? https://bitbucket.org/matheusbrat/clojure
19:40maya__Hi, I have some bug with clojure interop with java, when I write the same (I think) code in the two languages, I got two diferent results. I don't have any idea why
19:40maya__(println (.contains (.getAllowedValues (PropertyInteger/create "propertyBottomPosition" 0 4)) 0)) // false System.out.println(PropertyInteger.create("propertyBottomPosition", 0, 4).getAllowedValues().contains(0)); // true
19:41maya__Do you have any idea about what can be wrong here ?
19:43amalloyunrelatedly to your problem, it will certainly be easier to read if you write it like (println (-> "propertyBottomPosition") (PropertyInteger/create 0 4) (.getAllowedValues) (.contains 0)))
19:45maya__amalloy: you'r right, juste didn't have the reflex yet
19:46amalloythose two snippets look equivalent to me, though. i'd say confirm that that's the exact code you're running, and if you still get different results then start seeing if there's something about the context you run them in in the respective languages
19:47hiredmanwell
19:48hiredmanthe difference would be, in java that 0 is an int, in clojure it is a long
19:48amalloyoh dang
19:48hiredmanso it depends on what the behavior of .contains is given that
19:48amalloyyeah that is almost certainly the answer. nice spot
19:50maya__getAllowedValue return a com.google.common.collect.RegularImmutableSet
19:51hiredmanyeah, you want something like (Integer/valueOf 0) for contains
19:51amalloyhiredman: just (int 0) should do it, right? i think it doesn't re-box for interop calls
19:51amalloyright, hiredman's point is that your clojure code translates to (...).contains(0L)
19:52maya__amalloy, hiredman : ok thx, I will try to fix that
19:52amalloyor well, obviously it does re-box, but it knows that it has an int so it boxes to an int rather than a long. unless you're on specifically clojure 1.3 or whatever version that was
19:53hiredmanI dunno, it seems like the most explicit code is best here. it really needs to be an Integer
19:54hiredmanthe fact that there can be some uncertainty and some wiggle room around 'int', well maybe it isn't the best choice
19:54amalloyfair
20:09maya__Ok, that was the probleme, thx. Is that a way to specify to the reader the type (to Integer) of my literal ? other than (int 0)
20:12justin_smithno
20:25Guest58040What is the best way to determine if something is a collection or a single symbol? (complement coll?) ?
20:33TimMcGuest58040: Do you know it's always a symbol if it's not a collection?
20:33TimMcIf so, you can use symbol? to check instead.
20:40Guest58040Heh, my terminology might be bad. I did end up using coll? for my problem.
20:40Guest58040So, what would you call the first element of this list? (1 2 3)
20:41Guest58040vs the first element of this list ([1] 2 3)
20:41Guest58040Is 1 a symbol?
20:41Guest58040Okay, it's not... what can I call it?
20:42amalloyit's a number
20:42Guest58040I guess I'm looking for an equivalent term to "atom" from Scheme lingo...
20:43amalloywe don't have that, because clojure code is built of more than two primitive types
20:43Guest58040A primitive, then?
20:43amalloythere's no atom/pair dichotomy
20:44amalloyno, primitive means something else. are you sure you *want* to make this distinction, even?
20:45justin_smithI guess we have "self evaluating objects that are not data structures" and "everything else", but given that java.lang.Long is an object I don't know how many things *really* belong in the former category if any...
20:45Guest58040Hmm. Perhaps I will stick with number for now - I don't seem to have the vocabulary to express myself well.
20:45Guest58040I see that the JVM complicates what I should call things.
20:45turbofaili mean... collection vs. non-collection seems to be pretty much what you're looking for
20:45justin_smithGuest58040: clojure chooses not to mask or manipulate the representations of its vm
20:46justin_smithturbofail: but Long is a class, its instances have fields, it has methods
20:46amalloynot data structures? that's not really a good description imo
20:46amalloysince eg Symbol is a pair of strings
20:46justin_smithindeed
20:46turbofailjustin_smith: yeah but you can't reduce over a Long
20:47Guest58040Have you ever gotten excellent instruction by doing something incorrectly in front of a room full of skilled folks?
20:49justin_smithGuest58040: oh man I was arrogant enough to audit a graduate seminar, before I had even enrolled in college, when I was 19. I feel sorry for the other people in that room, but I learned a lot.
20:50amalloyGuest58040: https://meta.wikimedia.org/wiki/Cunningham%27s_Law
20:51Guest58040And now I even have a term for it. Thanks!
21:23csd_why is ring telling me that i have an invalid csrf token when i havent enabled the anti-csrf middleware (at least, to the best of my knowledge)
21:24csd_i'm using ring-defaults but didn't enable the feature
21:25csd_oh wait, ugh i take that back :-/
21:40amalloy(filter (comp seq identity) xs)
22:34renlhi may i ask why drop would check a vector into a list?
22:34renlack * check = change
22:34justin_smithrenl: I think you want seq
22:34justin_smith,(seq [1 2 3])
22:34clojurebot(1 2 3)
22:34justin_smithrenl: why do you need a list though?
22:35justin_smithmost things that work with lists work with vectors without needing any explicit conversion
22:35renli didnt want a list, but i did a drop on a vector, then i did a conj on that but it added the new stuff at the front which i didnt want
22:35justin_smiththen you didn't have a vector
22:35justin_smithdrop returns a list, not a vector
22:35justin_smith,(drop 3 [1 2 3 4])
22:35clojurebot(4)
22:36justin_smith(doc subseq)
22:36clojurebot"([sc test key] [sc start-test start-key end-test end-key]); sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a seq of those entries with keys ek for which (test (.. sc comparator (compare ek key)) 0) is true"
22:36justin_smitherr
22:36justin_smith(doc subvec)
22:36clojurebot"([v start] [v start end]); Returns a persistent vector of the items in vector from start (inclusive) to end (exclusive). If end is not supplied, defaults to (count vector). This operation is O(1) and very fast, as the resulting vector shares structure with the original and no trimming is done."
22:37justin_smith,(subvec [1 2 3 4] 3) ; you can use subvec instead of drop if you need the return value to be a vector
22:37clojurebot[4]
22:37renlk thanks just felt that it would cause bugs for newbies when i put a vector into a function and the outcome gave me a list :(
22:37renlok thanks :D
22:37justin_smithrenl: nope, pretty much every list function silently turns vectors into lists, by design
22:38renlnod
22:38justin_smithwell that's wrong, sorry, they don't turn anything into anything - for a vector arg they return things that are seq not vector
22:39renlk