#clojure logs

2011-08-13

00:00sriddeleting the first item of a list is surely O(1)
00:00amalloyno. vectors don't allow you to delete the first item
00:00sridright. immutability.
00:01sridso if you poping from seq is O(1) why not just use vectors as queue (instead of using PersistentQueue)?
00:01amalloyno, i mean you can't do it and keep it a vector. but it's easy to drop an item from a sequential *view* of a vector
00:01srids/vector/seq of vector/
00:01lazybot<srid> so if you poping from seq is O(1) why not just use seq of vectors as queue (instead of using PersistentQueue)?
00:02amalloy&(let [v [1 2 3]] (map class [v (rest v)])))
00:02lazybot⇒ (clojure.lang.PersistentVector clojure.lang.PersistentVector$ChunkedSeq)
00:02sridah. I didn't realize lazybot was a bot; though someone was fast enough to correct my question.
00:02sridthought*
00:04sridok - so popped items are not garbage collected until the seq expires (and it expires when about half of the queue items are popped)
00:05sridsay, you have a queue of length 1000 (with 500 items in a list). until the 500th pop, none of the half of the queue's memory won't be freed.
00:05srids/won't/will/
00:05lazybot<srid> say, you have a queue of length 1000 (with 500 items in a list). until the 500th pop, none of the half of the queue's memory will be freed.
00:05amalloythat's true, but 1/2 is a random guess
00:06amalloyif you conj them all before you consume any of them, the whole thing will be a vector before you seq it, and none will expire until you consume the full thousand
00:07sridright
00:10srid"[…] subsequent attempts to use conj on [the value of (pop aPersistentQueue)] won’t preserve the speed guarantees of the queue type and the queue functions pop peek and conj won’t behave as expected."
00:14amalloysrid: link?
00:15sridthis is from 'The Joy of Clojure'
00:19amalloymisquote
00:20amalloythe part in brackets should read [the value of (rest aPersistentQueue)]
00:21sridah, right. I mistook what the word "former" (in the preceding sentence) referred to.
00:32dnolenfun stuff, https://gist.github.com/1143483
04:38leo2007does , also mean unquote in clojure?
04:39leo2007seems , means space
04:46amalloyyou're looking for ~
04:48leo2007yeah
04:48leo2007does anyone know if fuzzy completion in swank-clojure works fully? I cannot see any thing started with .
05:32leo2007What does #' do?
05:38thorwil,(macroexpand-1 '(#'x))
05:38clojurebot((var x))
05:38leo2007I see. thanks
05:39thorwilcalled var quote on the clojure cheat sheet
05:39thorwilhttp://clojure.org/cheatsheet
09:33pyrhi
09:33pyrfacing a weird problem with swank-clojure
09:33pyri have one box where it constitenly fails with:
09:34pyrException in thread "main" java.lang.IllegalArgumentException: No value supplied for key: true
09:34pyrwhether in when calling lein swank or clojure-jack-in from emacs
09:34pyrthe call stack goes up to start-server in swank.clj
09:34raekpyr: I think that is caused by having multiple versions of swank-clojure on the classpath at the same time
09:35pyrah
09:35pyrweird, i killed the previous one i thought, i'll check
09:35raekpyr: check for old versions in the project.clj and in .lein/plugins/
09:35raekalso, does your project use incanter?
09:35pyryes
09:36pyrraek: good find
09:36raekincanter pulls in an old version of swank
09:36pyrindeed incanter pulled swank
09:36raek:dependencies [[org.clojure/clojure "1.2.1"] [incanter "1.2.3" :exclusions [swank-clojure]]]
09:40pyrthx
10:08wunkianyone else had the problem that the "_id" field from a mongodb database (congomongo) couldn't be parsed to string?
10:08pyrmeh, incanter has other problems it seems
10:15pyrso using leiningen fails but using the repl stuff works
10:36tufflaxI have 32 bits as an integer, what's the easiest way to cram them into an int? The int will possibly become negative.
10:50pyranyone ever got to the point where they could run incanter from leiningen ?
11:07wunkican anyone familiar enough with congomongo see this is intented behaviour: https://gist.github.com/1143937
11:08sleepynatewunki: (into [] (fetch ...))
11:13wunkisleepynate: then I'm putting a json string inside a list, since :as :json returns a string.
11:14wunkiI want to return it in the body, with jetty, so I need a string
11:16hiredmanclojurebot: ping
11:16clojurebotPONG!
11:16sleepynatewunki: erp? perhaps i misread your gist
11:17sleepynateoh apparently
11:17sleepynateso it's giving you {...}\n{...} as opposed to [ {...}, {...} ]
11:17wunkisleepynate: yes, exactly
11:18wunkiand since I just began with Clojure, I don't know how to fix this
11:23sleepynatewunki: give me a few minutes and i'll help you investigate further :)
11:23wunkisleepynate: that would be awesome, appreciate it
11:24sleepynatesadly soldering waits for no man :p
11:25wunkiwell, I'll be waiting, since I'm stuck :)
11:25sleepynatewatch a video from clojure-conj while you wait! http://clojure.com/blog/2011/03/23/conj-talks-all-up.html
11:34duck1123wunki: so your problem is the elements aren't wrapped in a list?
11:34wunkiduck1123: yes, and comma separated
11:35duck1123well, comments are whitespace in clojure, but this is coming back as a json string?
11:35duck1123I haven't used congomongo in a while, I switched to karras
11:36sleepynate(in https://github.com/aboekhoff/congomongo/blob/master/src/somnium/congomongo.clj#L229 <-- looks like the json is coming straight from mongo
11:36duck1123so you might be better off getting it as clojure and convert it to json when you're done
11:37sleepynatewunki: can you gist the minimal amount of code to reproduce your issue?
11:37duck1123You could even make a simple middleware to convert to json at the end
11:38wunkiduck1123: I tried switching to clojure and I was able to replace the _id. But then came the "date" type
11:38duck1123ahh, I have the code for that
11:38duck1123one sec
11:39duck1123https://github.com/duck1123/jiksnu/blob/master/src/main/clojure/jiksnu/model.clj
11:39wunkisleepynate: I can do that
11:39duck1123it's in there
11:40wunkiduck1123: should I move to karras? Do they do it correctly?
11:40duck1123I've never used any as-json option
11:41duck1123I prefer to always have it back as clojure
11:41wunkiduck1123: yes, but I'm building an API that needs to return a json. That's why I thought :as :json would be handy, since it does all the conversions for me
11:42duck1123I can't comment on karras vs congomongo except to say I like karras' concept of entities
11:42eskatremHello, is someone using incanter with clojureBox?
11:43duck1123I've found that I very rarely want to send the results of a mongo request as is
11:44sleepynatewunki: with congomongo "0.1.6" mine is coming back separated just fnie
11:45sleepynatebut you're obviously pruning the id
11:45wunkisleepynate: do you get a good output from :as :json?
11:45duck1123is that coming back as a seq of strings?
11:46wunkiI'm also on 0.1.6 btw
11:46sleepynatewunki: i do
11:46sleepynateduck1123: no, it comes back as properly formatted sjson
11:46sleepynatewunki: aren you removing the id yourself?
11:46eskatremsleepynate, i dont know how to set up incanter
11:47wunkino, I'm doing nothing. I do use :only though
11:47sleepynate(fetch :collection :only [:title] :as :json)
11:47sleepynateahh
11:47sleepynatehm
11:48wunkisleepynate: this is my gist: https://gist.github.com/2f49b471f21eb341891f
11:48wunkiall json-response-cm does is adding the correct headers
11:49sleepynateduck1123: oh yea it is a seq of strings
11:49sleepynatewunki: so
11:49sleepynatewunki: here's my recommendation
11:50duck1123(str "[" (string/join ", " col) "]")
11:50duck1123may have the order of join wrong
11:50sleepynateduck1123's suggestion will also work
11:51sleepynatei was going to say fetch a native structure and use clj-json
11:52wunkisleepynate: I tried doing that. But clj-json cannot handle the _id type
11:52duck1123is there much difference between clj-json and c.d.json?
11:52sleepynateduck1123: probably not
11:53leo2007folks, is fuzzy completion fully implemented in swank-clojure?
11:53duck1123if you go with c.d.json, the code at the bottom of the file I linked should sort you
11:53duck1123that's what I use for my site
11:54wunkiso I would need to use c.d.json and then look at your file for how to replace mongo's native types?
11:56Hodappyup, banned from #java again.
11:56duck1123yeah, the last 4 block set handlers for date and ObjectId
11:57duck1123you might need to adjust to fit your needs. Ie. I just print the id field
11:57duck1123and I format the date as close to xsd:dateTime as I've been able to get it
11:57HodappAnyone here messed with Processing, particularly in its Clojure instantiation as Incanter and clj-processing?
11:58duck1123still need to put a colon in the timezone
11:58wunkiduck1123: thanks, will try to incorporate it in my code
12:00duck1123so is #java particularly ban-happy?
12:22eskatremHello, can anyone help me install Incanter on ClojureBox?
12:24duck1123what issue is it giving you? Never used incanter
12:24eskatremIt's not even an issue, I cant find at all how to install it
12:25duck1123are you trying to use it in your project?
12:25eskatremyes
12:25eskatrem(I am a Clojure noob)
12:25raekeskatrem: my suggestion is to use a project manager like leiningen and install clojure-mode in a clean emacs install
12:26raekclojurebox offers no way to add dependencies, afaik
12:26raekeskatrem: http://technomancy.us/149
12:26duck1123I suggest emacs-starter-kit
12:26eskatremraek: thanks!!!
12:26raekI agree with duck1123 :)
12:27duck1123incanter is on clojars http://clojars.org/incanter
12:27eskatremhmm it's kind of frustrating, I thought I would be able to install add any package from clojureBox
12:27duck1123so just add the code to whatever build system you use
12:28raekeskatrem: you add your dependencies with Leiningen: https://github.com/technomancy/leiningen
12:28duck1123clojurebox doesn't have elpa?
12:28eskatremI dont think
12:28eskatrembut I can add it I guess
12:28raekclojurebox is just emacs with slime and clojure-mode installed and with a script to start a swank server
12:29duck1123eh, just get the starter-kit and then install the clojure stuff via packages
12:29eskatremok
12:29raekeskatrem: when you add incanter to your project.clj, you have to do a special thing currently: :dependencies [[org.clojure/clojure "1.2.1"] [incanter "1.2.3" :exclusions [swank-clojure]]]
12:30eskatremso you guys are suggesting to forget clojureBox, install clojure and stuff to a standard emacs,, so that would include leiningen, and then I can add easily incanter and whatever else I want
12:30raekyes
12:30eskatremok
12:30eskatremI gonna try that then
12:31raekwhen you have it set up, it works just like in clojurebox, except that you start the clojure instance in a different way
12:31eskatremhmm sorry for asking another dumb question, but what exactly is the starter kit?
12:31eskatremI can have that from elpa?
12:32duck1123https://github.com/technomancy/emacs-starter-kit
12:32raekeskatrem: the official docs for https://github.com/technomancy/leiningen and https://github.com/technomancy/swank-clojure are the places to look at. there are a number of other tutorials that are outdated.
12:33duck1123check that out as your ~/.emacs.d then M-x package-list-packages
12:33raekeskatrem: emacs-starter-kit sets up things like elpa for you and also includes the recent Marmalade repo
12:33eskatremraek and duck: thanks! I will try that
12:33eskatremnow
12:33raekit's basically a bunch of good defaults for various things
12:35raekeskatrem: you need to create a clojure project with "lein new your-project-name". in its project.clj you add incanter as a dependency.
12:35eskatremraek: thank you
12:37raek1) install emacs-starter-kit 2) install clojure-mode with M-x package-list-packages 3) create a new project with lein new 4) add dependencies and run lein deps 5) install the swank-clojure lein plugin 6) visit a file in the project directory and launch clojure with M-x clojure-jack-in
12:38raekonce you have everything set up, only 6) is required to get to work
13:33dabdhen I (spit <lazy-seq>) clojure writes the internal name of the seq instead of the literal representation. How do I
13:33dabdWhen I (spit <lazy-seq>) clojure writes the internal name of the seq instead of the literal representation. How do I force it to evaluate the seq?
13:33AWizzArddabd: try (spit "c:/file.txt" (pr-str your-lazy-seq) :encoding "UTF-8")
13:34dabdthx
13:34AWizzArdIf your-lazy-seq is too big you want to doseq through it (or have some comparable mechanism) and spit it out in pieces, where you add :append true
14:00wunkiwhere should I look if I want to apply the ``str`` fuction to all "_id" elements in a sequence?
14:01wunkicorrection ":_id" elements
14:04AWizzArdwunki: what is a ":_id" element?
14:04wunkiAWizzArd: It's the data I get from a MongoDB request.
14:05AWizzArdwunki: is it a sequence of maps?
14:05wunkiAWizzArd: I think so (forgive me, started Clojure yesterday). This is how it looks: https://gist.github.com/537c470cd7459d036ba7
14:08AWizzArdwunki: ah okay, so it is a seq of maps that contain an :_id key.
14:08AWizzArdYou can (map :_id your-seq) and will get a seq of the objects
14:08wunkiyes, and I want to apply the str function to every :_id
14:09AWizzArdSomething like (apply str (map :_id your-seq))
14:09wunkieven those that are nested
14:10wunkiAWizzArd: that leaves only a ""
14:11duck1123is this for converting to json?
14:11wunkiduck1123: yes, still
14:12AWizzArdwunki: then the values of those maps have the empty string as string representation.
14:12duck1123which json lib are you using now?
14:13wunkiclj-json, but I was able to make strings from _id's, now I only need to do it recursively
14:16wunkiapplying ``str`` to the _id's does return a clean string with the sha
14:16algernonwunki: if you're using congomongo, it can do the json conversion automatically (fetch :as :json)
14:16duck1123it looks like clj-json has a coersions mechanism. You should be able to coerce ObjectId's into strings
14:17wunkialgernon: yes, and that works great, but only when you have one objects. A list of objects doesn't work
14:18duck1123wunki: are you using 1.3?
14:18algernoninteresting. it worked for me two weeks ago. (for some value of worked, it spew out a bunch of independent json strings)
14:18wunkiduck1123: no, clojure 1.2
14:19duck1123algernon: that's what he had, it was returning a seq of strings, and he wanted it as a single string
14:19wunkiduck1123: but only because 1.2 was in homebrew. Could use 1.3, I wouldn't know the difference at this stage
14:19duck1123ok, it looks like clj-json may not be 1.3-ready yet
14:20duck1123it suggests binding *coercions*, but it's not marked as dynamic
14:20duck1123I like the official lib's way of doing it better, personally
14:23duck1123you're going to run into issues if you ever decide to store ObjectId's in places other than :_id
14:24wunkiduck1123: I'm now able to replace the _id's with "test" string: https://gist.github.com/89b06d5d1dcadcc5e3bd
14:26duck1123(let [id (:_id s)] (assoc s :_id (str id)))
14:26wunkiinstead of "test" ?
14:26duck1123That would set :_id to the string version of :_id
14:27duck1123Is there a fn that applies a fn to the value of a key in a map?
14:28duck1123like alter, but one that just returns
14:28st3fanto each value of a key i a map?
14:29duck1123something like (alterish m :foo inc)
14:29wunkiduck1123: that is pretty close now! https://gist.github.com/b63c6e601e074e1c0cf0
14:30duck1123it's easy enough to get that effect, just wondering if there's a name for that
14:31tomojthere is (update-in m [:foo] inc)
14:31duck1123wunki: I'm doing something very similar to yours apparently. http://beta.jiksnu.com/api/statuses/public_timeline.json
14:31duck1123tomoj: nice. I'll have to remember that
14:31wunkiduck1123: yes, you are right
14:32wunkionly yours works :)
14:33duck1123are those dashes in your output, or just from copy/paste
14:33wunkino, somethings goes wrong
14:33wunkithe output is nested to much
14:34wunkiI think I didn't implement your code
14:34wunkiat the right place
14:37duck1123form that last gist, it looks like you're associng the activity into the id
14:40wunkiduck1123: omg, I think I did something right: https://gist.github.com/94af2114aa9456d1a280
14:41wunkicreates: https://gist.github.com/47dab998331e446bc6c6
14:45duck1123nice
14:51wunkiduck1123: two negatives, it now creates a :_id for every item in the sequence and it doesn't traverse deeper into the tree. Any pointers where to look?
14:53duck1123see, that's why I suggested using c.d.json originally. It would have gotten every objectid
14:53wunkiduck1123: no, It does return the collection the right way, I just want to apply the "str" function deeper into the tree
14:54duck1123you could look into clojure.walk and family
14:55duck1123right, The code I linked you to originally would've formatted every objectid just the way you wanted it
14:55kjeldahlAny cljs experts on? I'm struggling with "WARNING: Use of undeclared Var cljs.core/defn" and many similar when trying to get noir-cljs going...
14:56wunkiduck1123: your code on github?
14:57duck1123yeah, the bottom of the model file was the code to add support for serializing ObjectId in json with the official json library
14:58wunkiduck1123: I tried, but I couldn't get it to work. Sorry. Do you have the URI again? I know more know
14:58duck1123https://github.com/duck1123/jiksnu/blob/master/src/main/clojure/jiksnu/model.clj#L146
14:59duck1123I extend the json writer so that it calls write-json-object-id whenever it gets an object id
14:59duck1123but that doesn't work with clj-json
15:00wunkiduck1123: I will swap my json engine with the one you use
15:01duck1123(binding [clj-json.core/*coercions* {ObjectId #(str %)}]
15:01duck1123I beleive that's what you need with clj-json, but I don't use it, so I'm not sure
15:03Hodappduck1123: To answer your question from several hours ago: Yes, #java is very ban-happy.
15:14wunkiduck1123: where does the output of the json happen in your code?
15:16duck1123For jiksnu, that happens in the Ciste framework https://github.com/duck1123/ciste/blob/master/src/main/clojure/ciste/formats/default.clj#L11
15:16duck1123ignore the content-type part. I need to fix that
15:19wunkiduck1123: I got it working, thank you very, very much for your help
15:19wunkiduck1123: keep an eye out on epis.to, you now have contributed to that :)
15:21duck1123glad I could help
17:31XPheriorI have a vector like the following: [((3) (7 4)) (10 13 15)]. Is there a way that I can take the last element of the vector and merge it into the first one? The result would be [((3) (7 4) (10 13 15))]
17:31XPheriorBeen having trouble getting cons to work how I want it to.
17:33arohnerXPherior: I'm not sure what you want to happen. both sides of that look the same to me
17:33XPheriorThe (10 13 15) is inside the first list
17:33XPheriorSo it becomes a vector of one list.
17:34XPheriorRather than two
17:34arohnerah, ok
17:34XPheriorYeah, it's mildly confusing. Haha
17:34arohnerI would use butlast and concat
17:34XPheriorIt's really getting me
17:34arohnerand update-in
17:34arohnerdoes the structure need to be that complicated?
17:34XPheriorOkay. I'll check the docs on all of those. Thanks arohner! :)
17:35XPheriorProbably not. I'm just hacking away to pass my test, then I'll refactor.
17:35XPheriorClojure is still a bit confusing for me.
17:35arohneryeah, it takes a little while to get used to functional thinking, and understanding what kinds of structures work well
17:36arohnerin general though, cons is a low level operation
17:36XPheriorI can see the point, though. Functional code is so much cleaner.
17:36XPheriorOh? I wasn't aware of that.
17:38arohnercons specifically deals with seqs. many of clojure's data structure operations work against broader interfaces
17:38arohneri.e. conj
17:38arohnerconj will work on a seq, or a vector or a map, or a set
17:38XPheriorShort for conjoin?
17:38arohneryes
17:38XPheriorNeat. =o
17:46XPherior,(concat [(1) (2)] (3))
17:46clojurebot#<ClassCastException java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn>
17:46XPheriorWhy? :(
17:46XPheriorOh wait. Nevermind
17:46XPheriorAh, nevermind. I still dont know.
17:48duck1123XPherior: If you do (1) it tries to execute the fn 1 with no args. you want '(1)
17:49XPheriorAhhh, that makes sense.
17:49XPheriorI get tripped up on things like that so easily.
17:49duck1123,(concat ['(1) '(2)] '(3))
17:49clojurebot((1) (2) 3)
17:50XPheriorThanks!
18:11tomojhmm
18:11tomoj(defn foo "bar")
18:11tomojwhat is foo's arity??
18:11tomojit seems to have no arity at all
18:11tomojit's unarible
18:13amalloytomoj: well, its arglists are (nil)
18:13tomojweird
18:13amalloyso you call it with a list of arguments which does not exist, rather than one whose length is zero
18:13tomojI almost didn't notice it compiled
18:14tomojI guess it will return a non-existent value?
18:14amalloy&(macroexpand '(fn))
18:14lazybot⇒ (fn*)
18:14amalloy&((fn)
18:14lazybotjava.lang.IllegalArgumentException: Wrong number of args (0) passed to: sandbox7610$eval9966$fn
18:14tomojaha
18:15tomoj(fn boom)
18:15tomojfor quick "where is this called and with how many args"
18:15amalloyhah
18:16ldhin my webapp i've got a record which implements a data access protocol. what i'd like to do is track how many queries are made against the datastore to fulfill the request, and display that on the page. in javaland i might wrap calls to the query methods with AOP advice which increments a counter. what's the idiomatic clojure way to do this?
18:20amalloyoh man, aop. invisible code, for when spaghetti code is too easy to follow. anyway, i'd just wrap it in a function that increments a counter
18:22amalloy(def counter (agent 0)), (defn get-data* [] (whatever)), (defn get-data [] (send counter inc) (get-data*))
18:22duck1123I guess the best answer is you would find a way to not have to
18:24amalloyduck1123: i disagree. that's a perfectly useful thing to want to do
18:25amalloyand in a webapp using ring, you can just make it a middleware
18:26duck1123exactly, wrapping is useful, but you're better off trying to work around redefing fns and whatnot
18:26ldhamalloy: okay, thanks. that looks workable. i am using ring, so that's kind of an angle i was hoping to pursue
18:26ldhduck1123: so what do you propose?
18:27duck1123I do something like that in my app actually
18:27duck1123I have the notion of actions, and for every action, you can append triggers that fire in a different thread
18:28duck1123https://github.com/duck1123/ciste
18:28duck1123I make all of these types of changes my actions and then I add triggers to them
18:29duck1123I'm sure there are simpler solutions
18:29ldhinteresting, thanks. i'll look at that.
18:31duck1123oh duh, you're looking for robert hooke
18:31duck1123that'll do exactly what you want, although it stopped working for me
18:32amalloyblech. hooke doesn't compose well, and you can't do stuff like add a hook then remove it
18:32duck1123yeah, I don't use it anymore
18:33duck1123I've been going between using ciste's triggers and lamina's channels
18:38kjeldahlHard to say why, but I could not get noir-cljs working. However when I included the one source file in my own project instead of pulling it in through project.clj (jar), it works just great. An issue with the jar file perhaps?
18:59paulKhey everyone, have you worked with clojurescript?
18:59paulK I wonder how you got started and what your experience was
19:10grant_this must be easy, but i just am having all sorts of bad luck
19:10grant_in a lein generated project i have /src/myproject and /src/sample, sample being a sample project that uses files from myproject
19:11grant_how do i get /src/sample/core.clj to include functions from /src/myproject/core.clj?
19:11grant_i swear i have tried every combination of import and names separated with dots
19:11grant_from logical to totally nonsensical
19:12amalloy(ns sample.core (:use myproject.core))
19:12grant_thanks!
19:13amalloyi probably shouldn't recommend a wholesale :use. a better practice is (ns sample.core (:use [myproject.core :only [myfn1 myfn2]]))
19:13grant_right
19:14grant_so what does :use do?
19:15grant_actually i should be able to figure this out myself huh :P
19:15amalloygrant_: ns forms are hard to intuit
19:16grant_mm.
19:16amalloy(ns (:use ...)) really just calls (use), but that's not a very informative answer
19:16grant_well, that lets me do (doc use) :)
19:17amalloy(use) in turn calls (require), which loads the functions in myproject.core and makes them accessible by their long names, such as myproject.core/myfn; then (use) calls (refer), which gives you aliases to [some of] the functions without the namespace prefix
19:17grant_aah, neat, so core is pretty much hardcoded to be the main file of a project?
19:18amalloyno
19:18grant_why not, if use only loads stuff in core?
19:19amalloy(use) loads whatever files you give it as an argument. perhaps it's clearer if i write (use ...)?
19:19grant_yes that makes more sense