#clojure logs

2011-09-03

00:00livingstonjblomo: that's a little wired but not that odd.. why not just switch on type or use dispatch
00:00livingstonor just make your caller call list
00:01jblomoi usually like functions that are flexible and just do what i want
00:01livingston(it's not that odd because a recursive function might work like that)
00:01jblomoi'll do a sanity check to make sure i haven't written something wrong, thoguh :)
00:02amalloythat's a good point, livingston
00:02amalloyclojurebot: please cancel my previous accusations of wrong-ness
00:02clojurebotTitim gan éirí ort.
00:02livingstonbut then you'd have a switch right at the top is this one things or many?...
00:03amalloylivingston: depending on the sort of recursive function, i'd make it a protocol
00:03livingstonwhy does everyone want to shove everything in an object...
00:04amalloylivingston: who said? see https://github.com/clojure/data.xml/blob/master/modules/xml/src/main/clojure/clojure/data/xml.clj#L196
00:05amalloyit's just polymorphism based on the type of the argument, without the gross/slow `switch` at the top
00:05livingstonthat's to make existing objects seq-able, that's fine. but if you just have lists of stuff that's perfectly fine
00:06amalloyoften you're right, which is why i said "depending on the type of recursive function"
00:06livingstonamalloy: some kind of recursing on item/list is still going through dispatch ... you're not saving anything (there's no way the compiler knows ahead of time how many are in your list etc.)
00:07livingstonI'm just near to much java - the kingdom of nouns and all ;)
00:07amalloylivingston: that's not exactly true. the jvm can dispatch on type faster than you can do an if/else and dispatch yourself
00:08amalloymaybe if there are only two types involved, seq/string, then that's not true
00:08amalloybut in general if you're dispatching on type and you care about speed, you should let the jvm get involved
00:08livingstonI'm inclined to say that's crazy how could that be, but everytime I've done that with clojure I'm likely to be wrong, so .. ok
00:09amalloymost of the time at least one of those statements is false, so i don't bother with protocols
00:09livingstonoh sure if it can turn it into a jump-table maybe
00:09amalloyright
00:09amalloylivingston: it can in fact do even better
00:10livingstonthen you pay for hashing. in some good CL implementations you could scan 30 items in a list before a hash got faster
00:10amalloyget the JIT involved and say "hm, this function has been called a thousand times, and EVERY TIME x was an instance of List. i'll just inline a jump to List.foo, and leave a note that if someone ever passes in a non-List i need to recompile"
00:11amalloyit's all magic to me, of course, but i understand it does things like that regularly
00:12livingstoncompilers are smart
00:13amalloyyeah, and JIT compilation can optimized based on runtime information
00:33solussdIf I want to extend array-map and hash-map, do I extend the java.util.map interface?
00:34amalloyi think the first thing you do is ask yourself what you mean by "extend"
00:34livingston,(doc hash-map)
00:34clojurebot"([] [& keyvals]); keyval => key val Returns a new hash map with supplied mappings."
00:34solussdamalloy: with a protocol ?
00:35amalloythen no, extend it to clojure.lang.IPersistentMap
00:35solussdexcellent. thanks!
00:35amalloysolussd: see ##(supers (class {}))
00:35lazybot⇒ #{clojure.lang.APersistentMap clojure.lang.Associative clojure.lang.IObj clojure.lang.AFn java.lang.Iterable java.io.Serializable clojure.lang.IPersistentMap clojure.lang.MapEquivalence clojure.lang.Counted clojure.lang.IMeta java.util.concurrent.Callable java.lang... https://gist.github.com/1190567
00:35amalloypick the one that most closely resembles what you want to extend, and go from there
00:36solussdmakes sense
00:36solussdand wow, that's a lot of interfaces, etc
00:36amalloyclojure loves interfaces, yeah
00:39gaze__Hey, what would be the best way to do a sort of message queue thing in clojure?
00:40gaze__a la erlang message passing
00:40livingstoncould you be more specific "a sort of message queue thing"
00:40gaze__yeah sorry that was pretty nonspecific, haha.
00:40livingstonyou could probably use an atom
00:42solussdwhat's the 'isa?' equivalent to check if an object implements an interface or protocol?
00:43amalloysolussd: turn that into two separate questions: interface, or protocol?
00:44solussdinterface
00:44amalloyisa?
00:44solussdmore generally, I want to know if something is a map or a list/vector/seq
00:44amalloy&(doc map?)
00:44lazybot⇒ "([x]); Return true if x implements IPersistentMap"
00:44solussd,(isa? [] clojure.lang.IPersistentCollection)
00:44clojurebotfalse
00:45amalloy&(isa? clojure.lang.IPersistentCollection [])
00:45lazybot⇒ false
00:45amalloyoh right
00:45amalloyinstance?
00:46solussdisn't that just for classes?
00:46solussd,(instance? clojure.lang.IPersistentCollection [])
00:46clojurebottrue
00:46amalloyinterfaces are classes
00:46solussd;)
00:46amalloy&(class clojure.lang.IPersistentCollection)
00:46lazybot⇒ java.lang.Class
00:51amalloylivingston: btw, your remark that people want to put everything in an object reminded me of http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.html
00:53livingstonamalloy: I don't know what that is but just reading the name of that thing makes me agitated if not angry
00:53amalloyi don't think anyone knows what it is, or they would never have written it
00:53amalloyhttp://www.classnamer.com/ is a less-painful, more-fun take on the same thing
00:54livingstonI like how the doc starts with "convenient..."
00:54livingstonok that thing is awesome...
00:59livingstonthanks everyone, I'm out of here.
01:00jblomois there a way to stick a primitive long into a map? I keep find it converted
01:00jblomoboxed
01:00amalloyno
01:18gaze__is there any way to turn a quoted sexp into a string an vis-versa?
01:19amalloy&(doc pr-str)
01:19lazybot⇒ "([& xs]); pr to a string, returning it"
01:19amalloy&(doc read-string)
01:19lazybot⇒ "([s]); Reads one object from the string s"
01:20gaze__ahh, thanks a bunch :D
01:20gaze__I'd like to try and come up with a way to have a really natural interface for storing that I want to call a function in a database, and then having it read that record out with all the arguments and actually call it
01:21gaze__should be pretty simple, right?
01:38gaze__actually wait... pr-str gives me some funky #<blah$something blah$blah@0xblah> which would seem to imply it cares about where that bit is loaded
01:38gaze__so if I kill the vm, restart it, reload that function, that string won't actually get me back to the same function, will it?
01:38amalloyfunctions are not readably-printable
01:39amalloyespecially not closures
01:40gaze__I don't care so much that it's readable... I just want to store a blob somewhere that allows me to call that function again with say... no environment.
01:40gaze__do I wanna write a macro like (defresumable name [args] contents) that defs the function as well as adds an entry to a table somewhere?
01:41amalloyclosures already are what you want, except that they're not readable
01:43gaze__readable?
01:43amalloyfrom a string
01:44amalloyclosures are already "resumable" from within a single VM, and just writing some crap to a table somewhere isn't going to make your function "resumable" from a different VM
01:45gaze__sorry, I don't mean resumable... that was a really bad choice of words. Basically this is just a mechanism to ensure that if the VM dies in the middle of a function, when I start the program back up, that function will get started from the beginning again.
01:45gaze__with the same set of arguments
01:46gaze__that's what I meant to set out to do from the beginning
01:47gaze__say I have a system designed to transcode videos or something. If a web user comes in, uploads a file, the raw file is sitting somewhere... and then the app calls (transcode "/path/to/video.avi"), that should start and complete. If there's a power outage, I want that transcoding to still happen.
01:49gaze__so if there's a table somewhere with "transcode", "/path/to/video.avi" somewhere that gets scrubbed on startup, etc. etc.
01:52amalloythen don't store functions. just create a simple schema for "pending tasks"
01:53amalloypending.clj => {:tasks {1341 {:type :transcode :args "/path.avi"}}}
01:55gaze__it'd just be nice to have an interface where I can sorta (deftask transcode [args] (do stuff)), and then (invoketask transcode "/path.avi"), and all the bookkeeping is handled for me
01:56gaze__I mean, isn't the lispy way to do it to create a ton of macros and make it all nice and transparent? :D
01:57amalloyso do that. but you still need a storage schema, and just storing functions or code isn't going to be a good one
01:58gaze__oh no no, the idea was never to store the function or code, just a way to get back to it.
01:58gaze__what I wanted was to be able to do ((read-string "println") "hello")
01:59gaze__only, instead of println, it'd be some stuff from that table, and instead of "hello", it'd be the stored args.
02:57gaze__"java.lang.ArrayIndexOutOfBoundsException: 1 [Thrown class clojure.lang.LispReader$ReaderException]"
02:57gaze__from the interpreter
02:57gaze__would be a bug, yes?
03:02hiredmandoubt it
03:02hiredman(well, yes a bug in your code, sure)
03:14amalloy&(read-string "{x}")
03:14lazybotjava.lang.ArrayIndexOutOfBoundsException: 1
03:16amalloygaze__: ^
08:00nizzeHi!
08:00nizzeWhy clojure does not have [1..100] syntax for creating vectors?
08:03Netpilgrimnizze: Hi. I guess (range 1 101) does what you want. Not short enough?
08:03nizzeNetpilgrim: thanks I know about (range 1 100)
08:03nizzeI'm just curious
08:03Netpilgrimnizze: And if it has to be a vector: (vec (range 1 101))
08:03nizze:)
08:05nizzeCould I write a macro to impelment [1..100]?
08:05nizzeOr actually 1..100
08:06Netpilgrimnizze: The language designers probably wanted to keep the syntactic sugar to a minimum. And in this case it wouldn't really be a big improvement.
08:06nizzeNetpilgrim: Okay, thanks :)
08:06nizzeWhat I like about clojure compared to scheme is that it has sugar
08:06Netpilgrimnizze: I have no experience with macros but I think they have to be of the form (macro-name …) like function calls.
08:06nizzeEasier to read.
08:07nizzeOkay
08:07Netpilgrimnizze: I'm still very new to the language, and I've just fallen in love with -> and ->>. :)
08:07nizzeYeah, those are cool, you should check .. as well :D
08:09NetpilgrimIsn't it (.. o (m1) (m2)) the same as (-> o (.m1) (.m2))?
08:10Netpilgrim s/it //
08:13NetpilgrimApparently you can call static methods with .. but not with ->.
08:21NetpilgrimIs there a limit on how many function calls I can chain together with ->? I suddenly get a ClassCastException after a few almost identical calls in this code: https://gist.github.com/1191098
08:28raekNetpilgrim: which function is the exception thrown from?
08:29Netpilgrimraek: Apparently set-edge on the marked line.
08:30Netpilgrimraek: It's curious because on the two lines above it I call the exact same function.
08:30raekbut no, there shouldn't be any limit on the number of forms
08:31raekif you get an exception at runtime, it's not ->'s fault, since it's gone then
08:31raek(because it is a macro)
08:32Netpilgrimraek: Ah, ok. It seems the exception is thrown the third time set-edge is called, no matter what order the calls are in.
08:33raekI would recomment to look the stacktrace to see which line of the set-edge function it is thrown from
08:34Netpilgrimraek: Do you know how I can get a full stacktrace in slime-repl?
08:34raekyou should get one
08:34raekmaybe you need to click on the cause lines
08:35khaliGNetpilgrim, try (.printStackTrace *e) (i've been reading Joy :P)
08:35raekbut the whole exception chain should be available in the buffer that pops up
08:36Netpilgrimraek: The compilation buffer only contains this one line I've quoted in the gist.
08:37NetpilgrimkhaliG: (.printStackTrace *e) returns nil.
08:38raekNetpilgrim: do you get the exception when you compile or when you run it?
08:38Netpilgrimraek: When I compile it.
08:39raektry calling (require 'yout-ns :reload) in the repl
08:42raekseems like you don't get good stack traces when you don't use the repl
08:42raekanyway, I think this line is the problem: (conj (em from) to)
08:42raekand that em is a list thre
08:43Netpilgrimraek: "Could not locate yout_ns__init.class or yout_ns.clj on classpath"
08:43raekyou coult also try to comment out the test-graph form from the file, copmile it, and the run that code in the repl
08:44Netpilgrimraek: Ah, you probably meant 'your-ns. :)
08:44raekor replace (def test-graph ...) with (defn test-graph [] ...) and call (test-graph) in the repl
08:44raekNetpilgrim: I meant whatever your namespace is called
08:44Netpilgrimraek: I got that now.
08:45Netpilgrimraek: require leads to the same ClassCastException. I'll try running the -> form in the repl.
08:46raekNetpilgrim: make the test thing a function. then you will have compile-time and run-time separate
08:51Netpilgrimraek: Wow, that's strange. I have made it a function (https://gist.github.com/1191098) and now it compiles and runs ok.
08:52Netpilgrimraek: It smells like a bug in the compiler.
08:54hugodshouldn't that be update-in rather than conj in set-edge?
08:55raekNetpilgrim: when I take your original code and turn test-graph into a function, I still get the exception when I run it
08:56raeksame thing with your second gist
08:57raekCaused by: java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.IFn
08:57raekat user.DirectedGraph.set_edge(NO_SOURCE_FILE:175)
08:58raekif you compile it in emacs, rather than typing it in in the repl as I did now, you should get a line number too
08:58Netpilgrimraek: Keeps getting stranger. I can't reproduce the problem, now that it's a function.
08:58raekNetpilgrim: which namespace is the repl in?
08:59raekNetpilgrim: and you run (test-graph) in the repl?
08:59Netpilgrimraek: You can see the line number here: https://gist.github.com/1191098/5191de8a71d2f1c579c6171d1b553da5ccf47306
08:59raekis this gist the whole file? if so, you're missing a namespace declaration
09:00Netpilgrimraek: Yes, I run the test-graph in the repl and it's in the same namespace as the function.
09:00Netpilgrimraek: I've left out the namespace declaration (and some other stuff) in the gist.
09:00raekwhat happens when you run (test-graph)?
09:00raekI get an sception there
09:00raek*exception
09:01raekanyway, I have to go. good luck!
09:01Netpilgrimraek: Damn, when I remove everything but what I've posted in the gist and call the function in the namespace "user" I get the exception again.
09:02raekhow do you compile the file?
09:04Netpilgrimraek: slime-compile-and-load-file
09:04raekanyway, it's easier for others to debug if you post the whole file as it is
09:05raekbut now I really have to go.
09:05hugod(update-in em [from] conj to)
09:06Netpilgrimhugod: Sorry, I wanted to get back to you on that. I'm not familiar with update-in. Is it just nicer or do you think my code is (semantically) wrong?
09:07Netpilgrimhugod: O, now I see the problem. Thanks for the hint.
09:08Netpilgrimhugod: Wow, this gets rid of the compilation problem. I just don't see how.
09:09Netpilgrimraek: Thanks for your help.
09:11hugodthe original call to conj was returning a list, which was used as the value of em in the next set-edge call, giving rise to the exception you were seeing
09:13Netpilgrimhugod: Now there's just the mystery why compilation and run did work with one specific namespace.
09:14Netpilgrimhugod: But as long as something like this doesn't come up again, I can live with that.
09:14khaliGis scheme a better choice for making android apps than clojure?
09:40bsteuberkhaliG: I'd stick to ClojureScript
09:40bsteuberbut to be fair, I don't know anything about scheme android dev
09:40ziltiWhy would you compile Clojure to JavaScript if it has to run on a JVM anyway on Android?
09:41bsteuberwhy should javascript run on a jvm?
09:41khaliGbsteuber, I dont know anything about it either - but reading about how kawa scheme has full support for android and it runs fast without the problems clojure seems to have on the same platform
09:42bsteuberthe thing is, if you use clojurescript, things run in any browser, so you even got iPhone in the boat
09:42bsteuberbut of course it might depend on the type of your app
11:58gaze__hey, what would be the nicest way to go about composing a list over the duration of a function... kinda like with the list monad in haskell, but without clojure's funky monad syntax
11:58gaze__is there anything better than a let-bound mutable vector?
12:51chousergaze__: yes, there is something better.
12:51chouserby definition. a let-bound mutable is to avoided if at all possible.
12:52chouserwhat about conjing onto a vector, passing it forward from one step in the function to the next.
12:59solussdI usually just don't, but what is the preferred way to enforce arg types to a function?
12:59solussde.g. I want a function to throw an exception if not called with a keyword
13:00solussdpre/post conditions?
13:06robermannif I'd want to double a number, which whould be better / more idiomatic: using a partial as (defn pdouble [x] ((partial * 2) x)) or using a closure as (def times-two (let [x 2] (fn [y] (* y x)))) ?
13:14gaze__chouser: I'm afraid I don't understand
13:16gaze__what would that look like?
13:19solussdrobermann: what's wrong with (defn [x] (* 2 x)) ?
13:19solussd*function-name
13:23robermannmmm I was tr
13:23robermannying to find when to use a partial and when to use a closure
13:24robermannthese are new concepts for me, and I'm going to study them
13:25robermannisn't a closure a partial function?
13:25gaze__a closure is a function tied with it's environment.
13:26solussda closure is a function that 'closes over' its environment
13:28robermannbut here the partial isn't closing over the two? (def two 2) (defn pdouble [x] ((partial * two) x))
13:28robermannor maybe this example is too simple to be interesting
13:29solussdthe function partial takes a function and any number of args and returns a function that calls the original function with the args it was created with plus any args passed to it
13:31gaze__I guess I don't understand how you'd write a DSL in closure... how do you go about threading state through a series of functions?
13:31solussddefine state as the application of functions? :D
13:34solussdmoving a data structure from one state to the next is modeled functionally as (def next-state (move-to-next-state original-state))
13:34gaze__let's put it this way... I wanna be able to do (foo [x] (add-to-list 3) (add-to-list 4) (if x > 8 (add-to-list 5))) (foo 3) => (3 4) ; (foo 9) => (3 4 5)
13:35solussdthere be side-effects
13:36gaze__sure! but haskell seems to handle this sorta thing fine
13:36gaze__I mean... there's a ton of desugaring
13:36gaze__I was just hoping there'd be something similar
13:37gaze__basically I want to build up a transaction over the lifetime of my function, and before the function returns I'd like to commit it atomically.
13:38michaelr525heyo
13:38michaelr525!
13:47solussdgaze__: (defn foo [x] (let [add-5? (fn [y] (if (> x 8) (conj y 5) y))] (-> [3] (conj 4) add-5?)))
13:48solussduse the threading macro to thread your list (in this case, a vector) through each step
13:50solussdmore concisely, (defn foo [x] (let [add-5? #(if (> x 8) (conj % 5) %))] (-> [3] (conj 4) add-5?)))
13:56ShereKahnHi, I am writing a tool to extract values from the output of commands of a system (in this case a router). The approach I have taken is to write a "parser" that is actually matching the output based on templates.
13:57ShereKahnbut the problem I have is that I have some sub-structure in the show, so I thought that I could use some recursive function to go through the templates and the actual tokens
13:58ShereKahnso the issue I have is that I would need to have something that would do (while tokens (parse ...)) where the parse would send back the result and the remaining tokens if any
13:58ShereKahnbut I am not sure how this is possible
13:59ShereKahne.g. passing a ref to change the state of the remaining tokens for the while ?
14:00ShereKahnor is there anything more idiomatic in clojure to do that ?
14:04ShereKahnotherwhise put, say I have a (let [token ...] (while token (do-something (token))), is there a way for the do something to change the bindings for 'token' from inside the 'while' or the 'do-something' ?
14:06ShereKahnsimilar to what CL '(setf token new-value) ' would do ?
14:07NetpilgrimCan someone explain to me why the pre conditions at https://gist.github.com/1191537 are ignored?
14:12ChousukeShereKahn: if you want something stateful you will need an atom or something
14:13ChousukeShereKahn: however it should be entirely possible to make a stateless parser
14:14Chousukeactually I might have a gist somewhere that implements a simple one
14:15ShereKahnChosuke : thanks I would be grateful to see it.
14:23ChousukeShereKahn: https://gist.github.com/141085 I did it as a monad exercise but maybe it will give you an idea or two :)
14:24ShereKahnChousuke: thanks a lot for that! I hope it'll give me enough ideas to get me unstuck
14:24ChousukeShereKahn: there's also a clojure parser combinator library that you might be able to use
14:25Chousukefparse or something? I don't remember exactly
14:49rindolfHi all. How do I run labrepl?
14:52rindolfhttps://github.com/relevance/labrepl/wiki/Maven - I see.
15:16scodeWould the with-private-fns macros as descibed at http://nakkaya.com/2009/11/18/unit-testing-in-clojure/ still be idiomatic for unit testing private functions in a namespace?
15:21amalloyChousuke, ShereKahn: fnparse
15:31arohnerscode: if you're not calling the fns too often , you can just ((var your-private-fn) foo)
15:32arohnersigh, anyone gotten a ring app to run on heroku? I'm getting Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch, and no other helpful information
15:34scodearohner: Interesting work-around, thanks!
15:34michaelr525what work-around?!
15:47iceyarohner: I have a ring app up there, but didn't run into any errors like that
15:48iceyarohner: it's a tiny app, it barely does anything: https://github.com/pmn/peeranoia
15:51arohnericey: thanks
15:52iceyarohner: do you have a Procfile defined? It sucks that the error message is so ambiguous. I have a noir app deployed out there that does a little more (but not much more) and it's working alright too (just checked on them to make sure they were still running)
15:53arohnericey: yes, I have a procfile, just 'lein run -m my-ns.server'
15:53arohnerit's a noir app, with very few changes
15:54arohnerI'm thinking there's an exception on startup that's not getting logged
15:55iceyarohner: the procfile for my noir app just says "web: lein run", but having the -m <ns> shouldn't make a difference, right?
15:55arohnericey: yeah, I've tried it both ways
15:56iceyhmmm. this is what my server.clj looks like: https://gist.github.com/1191690
15:56icey(for the noir app)
15:57arohnericey: yeah, mine looks almost identical
15:57iceyarohner: do you connect to a database or anything like that?
15:57arohnericey: nope
15:58arohnerI have some static files I serve out of /resources, but that's about it
15:59iceyhave you tried deleting the heroku app and creating a new one? the only thing i can find on google about the R10 error appear to be database related - either a bad database.yaml was included, or the correct database was defined and is unreachable
15:59arohnersigh. Now it's working, and I don't know why
15:59arohnericey: thanks for your help
16:00iceyarohner: chalk it up to random sunspot activity or something ;)
18:10sirnAnyone knows if Compojure still requires the (assoc-in response [:headers "Content-Type"] "whatever; charset=utf-8") middleware stuff for UTF-8 support?
18:11jblomoit looks like the current version adds it already
18:11jblomohttps://github.com/weavejester/compojure/blob/master/src/compojure/response.clj
18:12sirnjblomo: awesome, thanks!
18:23jblomowhat is the scope of extend-protocol? if you extend a protocol in (ns user (:require foo)) will the extension be in effect inside foo?
18:28akhudekis there a way to get a java iterator for a clojure seq? This is for interop purposes.
18:28amalloysim: that's only setting utf-8 when you tell compojure to render a string. if you render anything else, it looks like it doesn't necessarily add utf-8 (and it shouldn't, since it doesn't know what content encoding, say, a file on the local hard disk is)
18:28amalloy&(doc seq-iterator)
18:28lazybotjava.lang.Exception: Unable to resolve var: seq-iterator in this context
18:28amalloy&(doc iterator-seq)
18:28lazybot⇒ "([iter]); Returns a seq on a java.util.Iterator. Note that most collections providing iterators implement Iterable and thus support seq directly."
18:28akhudekI mean the other way :)
18:28amalloy&(supers (class (clojure.lang.SeqIterator. (seq [1 2]))))
18:28lazybot⇒ #{java.util.Iterator java.lang.Object}
18:29akhudekthat will work? hm thanks
18:29amalloyakhudek: but seqs are already Iterable
18:29amalloyif java wants an Iterator instead of an Iterable, that's not very pleasant
18:29akhudekthis function wants: Iterator<List<String>>
18:30akhudekI think the inner type can be an iterator too
18:30amalloyakhudek: right, my point is that's a dumb thing to want as of java 1.5, which is like a decade old. if you can get them to accept an Iterable instead...
18:31akhudekthe code is part of mahout, I may try to submit a request, but I imagine it's unlikely to be changed any time soon
18:31akhudekhttps://builds.apache.org/job/Mahout-Quality/javadoc/org/apache/mahout/fpm/pfpgrowth/fpgrowth/FPGrowth.html
18:38chouserI think just (.iterator your-seq) should work
18:39chouserakhudek: ^^^
18:41akhudekyep, that seems to work, thanks chouser
18:52mudgehow do I make Clojure fully evaluate this map call: (map #(str project-path %) ["lib/*:" "src/:" "resources/"])
18:52akhudekdoseq
18:52amalloyuhhhh. you can stick a doall in front, but since this operation has no side effects that really won't do anything interesting
18:53akhudekor doall rather
18:53mudgeI tried (doall (str (map #(str project-path %) ["lib/*:" "src/:" "resources/"]))), but it doesn't work
18:53amalloyclojurebot: bug report?
18:53clojurebotA bug report has three parts: What you did; what you expected to happen; what happened instead. If any of those three are missing, it is awfully hard to help you.
18:54amalloymaybe i should get him to reword that so it's clear it applies to "this doesn't work"
18:57amalloybut mudge, it sounds like you're trying to implement (System/getProperty "java.class.path"). aside from the fact that your implementation doesn't work, is there a reason not to use the builtin?
18:57mudgeamalloy, i'm trying to setup a classpath for calling java
18:58mudgeamalloy: i found a way, so I am good
18:59amalloymudge: just call lein classpath
18:59amalloyor cake classpath
18:59mudgeamalloy: i don't have lein on the remote server where the production server is
19:01mudgeis there a takeall function for taking all the elements from a lazy seq?
19:02amalloymudge: this is exactly as crazy as crazy as "fully evaluate this map call". a lazy seq already contains all of its elements; taking them all doesn't mean anything. you need to be more clear about what your goal is, rather than asking a solution to a sub-problem you think you need to solve
19:04mudgeamalloy: yes, makes sense
19:05mudgeamalloy: i am trying to append a string to each of three strings
19:05mudgeamalloy: actually preprend a string to each of three strings
19:05amalloyyour originally-posted code already does that
19:06mudgeamalloy: then I want to put the three strings inside (apply str )
19:07amalloygreat. wrap (apply str) around your original code, and you've done it
19:08amalloythat said, i'd prefer to write: ##(let [path "foo"] (clojure.string/join ":" (for [suffix ["lib/*" "src" "resources"]] (str path "/" suffix))))
19:08lazybot⇒ "foo/lib/*:foo/src:foo/resources"
19:10mudgeamalloy: so I have this: (apply str "java -cp " (map #(str "/home/nick") ["lib/*:","src/:" "resources/"]))
19:10amalloy&(#(str "/home/nick") "src:/")
19:10lazybotjava.lang.IllegalArgumentException: Wrong number of args (1) passed to: sandbox17398$eval20592$fn
19:11mudgei mean this: (apply str "java -cp " (map #(str "/home/nick/" %) ["lib/*:","src/:" "resources/"]))
19:13amalloy&(apply str "java -cp " (map #(str "/home/nick/" %) ["lib/*:","src/:" "resources/"]))
19:13lazybot⇒ "java -cp /home/nick/lib/*:/home/nick/src/:/home/nick/resources/"
19:13amalloyso what's the problem?
19:14mudgeamalloy: yea, that works, but actually I have more strings after the map, so like this: (apply str "java -cp " (map #(str "/home/nick/" %) ["lib/*:","src/:" "resources/"]) " clojure.main")
19:15amalloywell that doesn't work
19:15mudgeamalloy: yea, it doesn't
19:15mudgeamalloy: i guess only the sequence can be at the end?
19:16mudgeamalloy: i think this is what I was having trouble with and that I didn't understand before
19:17amalloyi hope you've got what you need, because tbh i'm tired of solving problems you're not actually having
19:17mudgeamalloy: yes, i understand now, the function signature for apply is: apply f args* argseq)
19:17mudgeamalloy: so the sequence has to be at the end and that's why i was having trouble
19:19mudgeamalloy: so this works: (apply str "java -cp " (join "" (map #(str "/home/nick/" %) ["lib/*:","src/:" "resources/"])) " clojure.main")
19:20mudgeamalloy: i join together the sequence into a single string so it isn't a sequence in apply
19:20cemerickredinger: Not wanting to clutter two lists up with it, but: consider the ongoing clojure-dev thread my input re: 1.3. "showstoppers". Especially given CLJ-736 (rightly) going into -beta3.
19:21mudgeamalloy: i also don't need apply now, i can just use str
19:48jblomois there a way in lein to run something without have test-resources in the classpath?
19:49kof4001hello
19:49kof4001where could I get information on how to get clojure-mode to work in emacs?
19:50amcnamar1kof4001: elpa or marmelade (emacs package managers) will let you install it easily
19:51kof4001I tried first with http://riddell.us method
19:51kof4001and then with elpa
19:51amcnamar1what problem are you seeing?
19:51kof4001I might be missing something here
19:52kof4001this appears in debug mode:
19:52kof4001Debugger entered--Lisp error: (file-error "Cannot open load file" "clojure-mode")
19:52kof4001 require(clojure-mode)
19:52amcnamara(require 'clojure-mode)
19:52amcnamaraemacs is a lisp
19:53kof4001in my init.el I have:
19:54amcnamaraalso, usually elpa handles the loading for you behind the scenes
19:54amcnamaraso you can drop that, restart emacs, and hit M-x clojure-mode
19:54kof4001(add-to-list 'load-path "~/emacs.d/clojure-mode")
19:54kof4001(require 'clojure-mode)
19:55kof4001i have installed clojure mode inside .emacs.d
19:55kof4001instead ~/opt
19:56amcnamarayou may still need to load it
19:56amcnamaratry (load "clojure-mode.el") or something equivalent off the load-path path you have above
19:57amcnamara(before the require call)
19:57lobotomy_ugh, how do i easily print a LazySeq
19:58lobotomy_(println (str "seq is " my-lazy-seq)) doesn't work so hmm
19:58lobotomy_is there a way to force the lazy seq to be evaluated? or a print-for-real function?
19:58kof4001that load did the trick
19:58kof4001thanks
19:59amcnamarakof4001: np.
19:59amcnamaralobotomy_: try (apply str lazy-seq), that should pull all the values out
19:59amalloy&((juxt print-str pr-str) (range 3))
19:59lazybot⇒ ["(0 1 2)" "(0 1 2)"]
20:00amalloy&((juxt str pr-str) (range 3))
20:00lazybot⇒ ["clojure.lang.LazySeq@7480" "(0 1 2)"]
20:00amalloythere we go. that's the point i was making
20:01amcnamara&(apply str (range 3))
20:01lazybot⇒ "012"
20:01lobotomy_(println (str "my-seq is " (apply str my-seq))) ;; still doesn't work, just prints "my-seq is clojure.lang.LazySeq@0clojure.lang.LazySeq@0"
20:01amcnamaraeveryone's a winner.
20:01lobotomy_hmm, or is that a thing that contains other lazyseqs...
20:01lobotomy_isn't there a force-print-dammit function? :)
20:02lobotomy_maybe i'll use flatten!
20:02amcnamaratry what amalloy posted
20:02lobotomy_ooh, right
20:02amcnamarabut yeah, looks like you've got lazies all the way down.
20:03amalloy&(pr-str (for [x [10]] (range x)))
20:03lazybot⇒ "((0 1 2 3 4 5 6 7 8 9))"
20:03lobotomy_yep, pr-str works fine
20:03lobotomy_cheers
20:06mudgehow to add to the lein classpath?
20:12mudgeanybody ever added to the lein classpath of their project?
20:12lobotomy_grr, now i just need to figure out how to view the print results in the slime repl... apparently scrolling with that is impossible
20:12lobotomy_there's say 100 lines, it shows either the first 5 or the last 10
20:12clojurebotHuh?
20:17amcnamaramudge: I've never needed to, lein is supposed to track and manage dependencies for you -- you tell it what to get instead of where to get it.
20:17amcnamarawhat are you tring to do?
20:17kof4001i'm sorry to be bothering again, but the (load "clojure-mode.el") in emacs, only works if i loaded it from emacs, not from init.el
20:18amcnamaralobotomy_: M-x scroll-up ?
20:18amcnamarakof4001: probably has something to do with the order that those scripts are loaded, I dump most of those things into a .emacs file on ~
20:19kof4001i think the 23 version does not use .emacs anymore
20:19amcnamaraI believe .emacs is run last (after elpa, which may be causing your problem)
20:19kof4001i do not see a .emacs file in my home
20:19amcnamarayou have to make it
20:19kof4001i'll try
20:19mudgeI'm using Clojure for a shell script type of command line program that starts/stops/restarts my jetty server. I have an extra directory in my project called scripts which i want to add to leiningens classpath
20:20amcnamaramudge: if you want them to be visable to your project but not managed by lein, dump them in myproject/lib
20:21mudgeamcnamara: thanks
20:21amcnamarayou may also wish to set :disable-implicit-clean to true in project.clj
20:22amcnamaraor else whenever you run lein deps it will kill your lib
20:22kof4001the .emacs did not work
20:23kof4001the same problem with init.el
20:23mudgeamcnamara: yes, thanks
20:23amcnamarakof4001: dump/gist the error
20:24kof4001i Debugger entered--Lisp error: (file-error "Cannot open load file" "~/emacs.d/clojure-mode/clojure-mode.el")
20:24kof4001 load("~/emacs.d/clojure-mode/clojure-mode.el")
20:24kof4001 eval-buffer(#<buffer *load*> nil "/home/nonelse/.emacs" nil t) ; Reading at buffer position 64
20:24kof4001 load-with-code-conversion("/home/nonelse/.emacs" "/home/nonelse/.emacs" t t)
20:24kof4001 load("~/.emacs" t t)
20:24kof4001 #[nil "\205\264
20:25mudgeamcnamara: I could also use the load-file function and refer to include my file that isn't in the classpath
20:27amcnamarakof4001: odd...
20:29amcnamarakof4001: lets go back to elpa, what went wrong on your install from there?
20:30kof4001i installed elpa from the site http://tromey.com/elpa/install.html
20:30kof4001should i do it again?
20:30amcnamaradid you do package-install?
20:31iceykof4001: what OS are you using? Are you sure your idea of ~ is the same as emacs'?
20:31kof4001of emacs?
20:31kof4001lubuntu
20:31amcnamarain emacs
20:31amcnamaraelpa is a program to fetch emacs plugins
20:32amcnamaraM-x package-list-packages
20:32amcnamarawill show all of the available ones
20:32amcnamaraM-x package-install clojure-mode
20:32amcnamarawill install clojure-mode using elpa
20:32kof4001well the package install is not working
20:33kof4001i guess elpa did not installed correctly
20:34amcnamararerun the script from tromley, and remove the require/load clojure mode stuff you added to init.el
20:36kof4001i managed to install elpa
20:36lobotomy_hmm, apparently one of the sets i'm giving to clojure.set/difference isn't always a set, but sometimes a lazyseq
20:36lobotomy_this looks like it might be annoying to debug
20:37kof4001but clojure-mode is not detected as a package
20:37lobotomy_does clojure.set/intersection or /union sometimes generate lazyseqs?
20:38kof4001i had to list it first
20:39amcnamarakof4001: is it showing up now?
20:39kof4001after i did a package-list yes
20:39amcnamara&(doc clojure.set/union)
20:39lazybot⇒ "([] [s1] [s1 s2] [s1 s2 & sets]); Return a set that is the union of the input sets"
20:39amcnamara&(doc clojure.set/intersection)
20:39lazybot⇒ "([s1] [s1 s2] [s1 s2 & sets]); Return a set that is the intersection of the input sets"
20:40amcnamaranope.
20:40kof4001i guess that was it
20:40kof4001i installed paredit while i was at it
20:40kof4001thanks a bunch
20:40amcnamaraparedit comes in very handy
20:40amcnamaranp.
20:41kof4001keep up
20:50lobotomy_argh, i can't seem to print the stupid things before they end up in clojure.set/difference and cause that explosion
20:51lobotomy_(do (println ...) (into {} (for [... :let (...)] (do (println ...) (let ... (clojure.set/difference foo bar) ;; and the println's all say everything is a hashset, and immediately after java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IPersistentSet
20:52lobotomy_wonder if debug printing stuff is actually this difficult in clojure or whether i just suck, heh
20:53amcnamaragist your code
21:11amalloyjira is such a damn pain. i can't even close issues i reported? they were informally marked as "not interested" by clojure/core, but jira still thinks they're "Unresolved, open, unassigned"
21:21lobotomy_here's my code: http://pastebin.com/dMB14FKb
21:22lobotomy_any ideas appreciated :)
21:25lobotomy_ah damn, that seems to be incomplete. need to fix
21:25ibdknoxunusual question: does anyone happen to know what font the Clojure logo uses?
21:27lobotomy_added the pretty print stuff so it should compile: http://pastebin.com/C96NNcMu
21:45cemerickamalloy: Those damn fine-grained ACLs. :-P You don't have a 'close issue' button at the top of the issue?
21:47jkkramerlobotomy_: it looks like you're passing hash maps, not hash sets, to clojure.set/difference
22:01mudgewhat is a an ear muff?
22:01ctran*var*'
22:02ctranhttp://stackoverflow.com/questions/3579063/conventions-style-and-usage-for-clojure-constants
22:14jkkramerlobotomy_: i was mistaken. it's like 88; remove-threatening-squares ought to return a set
22:15jkkramerlobotomy_: it may help in the future to break your code into smaller, more testable pieces. the code flow is a bit hard to follow
22:53amalloycemerick: no. or if i do it's awfully well-hidden
22:53cemerickamalloy: which issue? Maybe I can close it?
22:54amalloy714, 707, and probably 709 also
22:56thinker341hi
22:57amalloycemerick: i have to step out for a while; if you need anything more from me to get those closed, just leave a message
23:05cemerickamalloy_: Issues closed.
23:07ambrosebswhat do I need to do to request commit access to core.match?
23:07cemerickambrosebs: find someone with admin rights in the 'clojure' github organization.
23:07cemerickmsg to clojure-dev should do it, presumably
23:08ambrosebswill do, thanks chas
23:10seancorfieldthere has to be a better way...
23:11seancorfieldso, i have a vector of maps... i want to do (map (juxt :id :name) data) which gives me ((id1 name1) (id2 name2) ...)
23:11seancorfieldbut i want that as a map {id1 name1, id2 name2, ...}
23:12seancorfieldi can do (into {} (map vec *1)) but that seems ugly
23:12seancorfieldis there a nicer way to turn ((a b) (c d) ...) into a map?
23:18cemerickseancorfield: juxt produces vectors here (-beta1)
23:20cemerickOtherwise, (reduce #(apply assoc % %2) {} (map (juxt :id :name) …)) ?
23:20cemerickNot nicer, but maybe (probably not) more efficient?
23:26seancorfield,((juxt :id :name) {:id 1, :name "Sean"})
23:26clojurebot[1 "Sean"]
23:26seancorfieldhow about that... *facepalm*
23:27cemerickIt's in the docs, FWIW. I don't have 1.2.0 handy, maybe that's a change.
23:27seancorfieldso i can lose the map vec at least... no idea why i had convinced myself i got sequences instead :(
23:27seancorfieldthanx!
23:27cemerick:-)
23:28seancorfieldnow i can clean up my code quite a bit...
23:30technomancyjblomo: set the LEIN_NO_DEV environment variable
23:38seancorfieldyeah, nice... much cleaner code... comp and juxt FTW :)
23:38seancorfieldthanx cemerick !!
23:39cemerickseancorfield: np, glad it worked out :-)
23:39user317is there a transpose function somewhere?
23:42davekongI tried running clojure on jnode and got this error: http://pastie.org/2478994 just wondering if anyone might have an idea how I would go about fixing this error
23:46user317is there a good source on list manipulation in clojure for someone from a haskell background? like zip zipWith transpose etc...
23:47technomancyzip?
23:47clojurebotzip is not necessary in clojure, because map can walk over multiple sequences, acting as a zipWith. For example, (map list '(1 2 3) '(a b c)) yields ((1 a) (2 b) (3 c))
23:48user317ah, so thats transpose
23:48user317i dont have my head wrapped around the variable arg part of clojure
23:48user317makes sense
23:49user317does that work over infinite lists?
23:49technomancyyep
23:50user317cool, seems to do the right thing when they are different sizes as well
23:51technomancyI think it truncates to the shortest seq arg
23:51cemerickit does
23:51cemerick,(map list [1 2 3] [1 2 3 4])
23:51clojurebot((1 1) (2 2) (3 3))
23:52user317yep
23:53user317so, if i pass a record constructor as the function to map, that should apply each value from the list as arguments to the constructor, right?
23:54cemerickctors are not first-class; you can't apply them to a seq of args, etc.
23:54cemerickHowever, (defrecord Foo …) creates a ->Foo factory function that will do what you want
23:55user317Foo is that function, right?
23:55cemerickNo, `->Foo` is the function's name, if your record class is named Foo.
23:55user317(map ->Foo (1 2 3) (4 5 6))
23:55user317like that?
23:56cemerickyup