#clojure logs

2009-07-07

00:32eyerisIs there a function or macro establish local bindings from a map?
00:33eyerise.g. given {:one 1 :two 2}, calling (let-from-map my-map (...)), would give ... the bindings one = 1 and two = 2?
00:34hiredmanI have thought about that, and fail to see a decent use case
00:35hiredmanjust use (:one my-map) instead of one
00:35eyerisIn this case, it'd would be (get-in my-map [:key-one :key two]), 4 times.
00:38eyerisAnd, in this case, I am going to use every key in the map.
00:57Knekkcan't make-array of structs?
01:01eyerisWhat about to-array?
01:05Knekkthat seems to work
01:05Knekkhow do I make it a multidimensional array? :)
01:07eyerisWhat do you need a multi-dimensional array for?
01:07hiredmanjava does not have multi diemensional arrays
01:08hiredmanjust arrays of arrays
01:08Knekkwhich is supported with make-array
01:08Knekkmaybe I am just doing to-array wrong.
01:09Knekkoh, duh
01:10Knekkgot it
02:10cataskaany tiny web library/framework for clojure recommended ?
02:11grrrtcataska: compojure is the most popular one
02:12grrrtand there's Ring, if you want something smaller and lower level
02:16cataskagrrrt: thx, i'll give them a try
02:28grrrtis there a function to test if something is a ref, similar to "var?" ?
02:29hiredmaninstaceof clojure.lang.IRef ?
02:30grrrthmm I guess that will do yes. thanks!
02:30slashus2,(instance? clojure.lang.IRef (ref 0))
02:30clojurebottrue
02:48bradfordis there some idiomatic way of wrapping macros in functions so they can be passed around?
09:25AWizzArdrhickey: When I have /hg/app/src/ in my classpath and also /hg/app/build/ into which I compile my app and then start a fresh repl and (use 'my.namespace), from which path will it then load? From the .class files or the .clj files?
09:26ChouserAWizzArd: whichever has a more recent mtime
09:32ChouserHere's the logic for that: http://tinyurl.com/mqkfyd
09:35AWizzArdthx
10:21laktekHi I got a problem in using clojure-contrib classes
10:22Chouserok
10:22laktekI have included it in my class path
10:23laktekbut yet when I do something like ((:import (clojure.contrib.server-socket))
10:23laktekit gives "java.lang.ClassNotFoundException: clojure.contrib.server-socket (NO_SOURCE_FILE:2)" error
10:23laktekWhat might be the problem?
10:24Chouseryou're at a repl?
10:24laktekyes
10:24Chousertry: (require '[clojure.contrib.server-socket :as ss])
10:25laktekI use the following command to launch repl - java -cp $CLOJURE_JAR:$CONTRIB_JAR clojure.lang.Repl
10:25laktekand I have defined correct paths to Clojure and contrib jars
10:26Chousertry: (require '[clojure.contrib.server-socket :as ss])
10:26laktekit gives nil as output
10:27laktekhow do I know whether it's loaded correctly?
10:27Chouserit worked! :-)
10:28Chousertry (doc ss/create-server)
10:28laktekyeppee!!! it did really work!
10:28laktek:)
10:29laktekthanks so much Chouser!
10:29laktekbtw, what is the difference with import and require?
10:29Chouseryour classpath was fine. the problem was that :import only works in the ns macro. a stand-alond function call needs (import ...)
10:29Chouseryes, that was the other problem
10:30Chouserimport is for getting a shorter name to a Java class.
10:30laktekso that means I need to require it first?
10:30Chousukeno.
10:30Chouseryou can either say java.security.MessageDigest, or say (import 'java.security.MessageDigest) first and later just MessageDigest
10:30Chousukethe java classes in your classpath are always available.
10:31Chousukebut clojure stuff needs to be required first.
10:31Chouseror 'use'd
10:31laktekah ok..so that means if it a general Java class such as IO i can use it without require or use?
10:32Chousukeyeah.
10:32laktekbut for clojure specific stuff needs to be required?
10:32laktekcool..now I'm really getting it
10:32Chousukeactually, require and use don't *work* with java classes :)
10:32Chousukethey're just for clojure.
10:32laktekand in a case how can I use an external java library?
10:32clojurebot
10:33Chousukelaktek: just add it to your classpath
10:33Chousukelaktek: then it will be automatically available.
10:33Chousukelaktek: you'll just need to give its fully qualified name, unless you use import beforehand, like Chouser described.
10:33laktekcool..now I get it..
10:34laktekthat convention anyhow doesn't apply to clojure namespaces right?
10:34Chousukeyeah
10:34ChousukeClojure stuff is not automatically available because it needs to be "executed" on load.
10:34Chousukeunlike java classes.
10:34laktekah right
10:34laktekbecause they are interpreted?
10:35Chousukenah, it's compiled.
10:35Chousukebut if the namespace is not AOT-compiled, then clojure will compile it when you do a require or a use
10:36ChousukeI'm not sure what it does if the stuff is AOT-compiled, but that's an implementation detail anyway :
10:36Chouserclojure has namespace objects that keep track of all available vars in the namespace
10:36Chouserto populate that list, you need to 'use' or 'require'
10:36Chousukeah, right. namespaces are actual objects. :/
10:36ChouserJava simply doesn't provide a way to see all the available classes in a package
10:37laktekah ok..so when I do a require what it does is generating the available functions and variables in that namespace?
10:38ChouserI'm not sure I'd use the word "generating", but that's roughly the idea, yes.
10:38laktekok cool..
10:38laktekand another question
10:38Chouserit'll create the namespace object and intern the vars in it
10:38laktekok
10:39laktek:require and :use is interchangeable?
10:39Chouserno
10:39laktekor are there any specific cases to use them?
10:39Knekkif I invoke the repl with a scriptname argument it runs the script... but does it run it under a different namespace? I am not seeing what I expect.
10:40Chouserthere's a lot of overlap in what they do, but some options are available only in 'use'
10:40Chouseron the other hand 'use's default behavior is not what I'd usually recommend.
10:40Knekkat the end of the script I call (run) which does some simple array manips and displays a JFrame... but it doesn't look like the array is modified
10:41Knekkbut it gets modified if I paste the command straight into the repl
10:41Chousukeyou sure you're not trying to modify an immutable thing?
10:41Chouserlaktek: These days I recommend: (ns my.ns.foo (:use [clojure.contrib.sql :as sql :only []]))
10:42Chousukeif you do (conj [1 2 3] 5) that won't actually modify [1 2 3] :P
10:42KnekkI am modifying an array
10:42Chousukecan you show the code?
10:42laktekChouser: ok cool
10:42ChouserKnekk: are you using clojure.main or Script ?
10:42Knekkyeah, but I need to get off this train first :) I'll be back from the office in 15
10:43KnekkChouser: Neither of those rings a bell, so I am guessing that's part of my problem
10:44Chouserhm, they both seem to start you in the 'user' namespace
10:44Knekkback in a few.
10:44ChouserI thought one of them used to default to 'clojure.core', but I guess that's been fixed.
10:49laktekChouser, Chousuke: thanks again for the help :)
10:58Knekkok.. let's see.
11:05KnekkShall I paste here or to the paste board I don't remember the location of?
11:06drewrlisppaste8: url
11:06lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
11:08achim Knekk: the error you described sounds like you're doing side effects stuff within lazy seqs (maps, for, ...). the REPL will print those and thus force evaluation, running as a script will not
11:09Knekkachim: you are most likely right, and it's something that keeps tripping me
11:09Knekkbut wouldn't (aget ) force evaluation?
11:10Chousukeis it inside a (for...)? :)
11:10lisppaste8Knekk pasted "repl" at http://paste.lisp.org/display/83176
11:10Knekkhttp://paste.lisp.org/+1S6G
11:10Chousukeyeah, it's the for.
11:11Chousukeuse (doseq) instead
11:11Knekkah
11:11Chousukein general, the do* functions are what you want to use if you're dealing with side-effects.
11:12Chousukelike manipulating arrays :)
11:13Chousuke(find-doc "side-effect") is probably useful
11:13achimfor is not a looping construct but a list comprehension. the same thing maths has for sets (like { x^2 | x in N }), but for lists. they don't actually do anything, just define a sequence in an abstract way
11:14KnekkI getcha
11:14KnekkI was under the mistaken impression that aget/aset would force the evaluation
11:15Knekkthank you very much
11:15Chousukelazy-seqs aren't smart enough to know when you're doing side-effecty stuff with their data :)
11:15Knekklazy and apathetic is what they are
11:16Chousukeheh
11:17Chousukeis there a reason you're working with arrays though?
11:17Chousukegenerally, you should avoid them
11:17KnekkI also have a vector implementation
11:18KnekkI am dicking around so I can learn
11:18Chousukethat's valid
11:18KnekkI do want to maintain a large array of mutable data
11:19Knekkwith elements that'll be updated frequently
11:19ChousukeHonestly, working with arrays is probably easier from Java.
11:20Chousukeso if a vector + a ref is not fast enough for you, consider writing a java class to wrap your array and using that from clojure :)
11:21KnekkI'll add that to my list of things to try. I already tried a vectors of refs, which was not... speedy
11:24Chousukeand if you wrap your array in an object you can use the (locking) macro to keep it safe I guess. :)
11:30Knekksafe data is happy data
12:45drewrwhoa, Chouser posted to his blog
12:45drewroh, it was agriffis
12:45drewranyway, n01se.net lives!
13:17Chouserdrewr: heh
13:54bpattisonI'm looking for a function that behaves similarly to map where it take [f coll init-value] where f is a function that takes [item prev-value] where item is an item out of coll and prev-value is the results of the previous invocation of f on the previous item, init-value is just the initial value to be sent to f -- does anyone know of such a function?
13:54Chousukereduce
13:54Chousuke:P
13:54danlarkinhaha
13:54Chousukeit is (reduce init coll) though
13:55danlarkinI love that... describing a function perfectly that already exists
13:55danlarkina nice surprise
13:55bpattisonreduce? excellent -- I'll take a look at that
13:55technomancydanlarkin: at least he asked instead of trying to implement it anew; that's what I often end up doing. =)
13:56Chousukeif you can find a functional programming language that *doesn't* have reduce as a standard function, I'd be interested :)
13:56Chouserbpattison: the fact that you're even asking that question shows you're really starting to "get" how to solve problems with high-level functions.
13:56Chousukeit's probably one of the first functions you'd implement when writing a standard library for functional programming :P
13:58mauritslamersquestion: is there a way to retain the intermediate values when using reduce and put them in a list?
13:58Chousukethere's a reductions function in contrib
13:58mauritslamersah, thanks, I'll take a look at it :)
13:59Chousuke~def reductions
14:00kencauseyum, is it normal for clojurebot to tell everyone the answers to such things privately?
14:00kencauseyor maybe this IRC client (weechat) somehow does not like clojurebot's responses and so is failing to render it in the appropriate buffer
14:01Chousukeit uses a notice
14:01Chousukenot a private message.
14:01Chousukeyour client is funky :)
14:01kencauseyOK, that shows up in the server buffer here
14:01kencauseythere is no information on the appropriate channel in the response it seems
14:02Chousukethat's your client being funky.
14:02Chousukeas far as I know, NOTICE is the proper method for automatic responses.
14:02Chousukeactual messages are reserved for human chatter I guess.
14:03Chousukethough clojurebot breaks that rule sometimes :P
14:06kencauseyWell, I'll just say I interact with other bots without that particular result and leave it at that
15:55bhurt_Stupid question of the day: is there something like javadoc for clojure?
15:55replaca__bhurt_: folks use doc strings in the function
15:56replaca__bhurt_: but there's no inherent format for that
15:56replaca__bhurt_: that you can use to generate html
15:56bhurt_I had thought doc comments were supposed to be short, just enough to remind you how to use the function when looking at it in the repl.
15:56replaca__but it is possible to generate html from namespaces pretty easily
15:57replaca__bhurt_: well, they shouldn't be a book, but I think they should be fairly complete
15:57replaca__in contrib we've been working on a system where folks doc their functions, but can provide longer doc with a wiki link
15:58replaca__but that's just a metadata convention I made up
15:58ChousukeI think the :doc metadata is too restricted :/
15:58Chousukeit'd be useful to have a map of documentation attributes.
15:58cemerickheh, yeah, we've been down this road before :-)
15:59Chousukeif you had a map of doc data it could contain additional stuff without polluting the "main" metadata too much.
16:00liebkebhurt_: I use clojure.contrib.gen-html-docs to generate html from the doc strings
16:01bhurt_The problem with using html in doc strings is that it looks bad when you do (doc some-function) in the repl.
16:02liebkeyeah, i don't use html in the doc strings because of that, but here's an example of what the generated html looks like: http://incanter.org/docs/api/
16:08replaca__yeah, I've been doing the stuff for contrib. (which is at github.com/tomfaulhaber/contrib-autodoc). It's in transition now, moving to github pages
16:08replaca__one of the things I had to do was use <pre> for the docstrs
16:09liebkenice, <pre> would be very helpful
16:09replaca__liebke: I was looking at the incanter doc and thought it might benefit from my new autodoc
16:09liebkeI think so
16:09replaca__I've got a couple of steps to go though, before it will be useful for other projects
16:10replaca__I'll let you know when it is.
16:10liebkethe formatting is great!
16:10replaca__liebke: btw, big props for incanter. I'm very excited about it.
16:10liebkethanks, I'll definitely switch to autodoc
16:10liebkethanks :)
16:11replaca__cool. The new version does everything "right" with HTML templates, enlive, etc.
16:11replaca__so it will be easy to make html bundles as well as static web sites
16:11replaca__(and even info files :-))
16:11technomancywow, info files?
16:11technomancycrazy talk. =)
16:12replaca__well, that's a later stage. but it should be easy, cause I've abstracted out building a big datastructure to describe what's going on so it's easy to go over that and produce whatever you want
16:12liebkethat will be great
16:13replaca__liebke: cool, I'll keep you posted
16:13technomancytexinfo is a pretty crazy format though.
16:13technomancybut I guess you're not doing a lot of fancy formatting
16:13replaca__technomancy: nah, but I haven't looked at texinfo in about 15 years, so we'll see :-)
16:14technomancyreplaca__: 15 years ago it probably wouldn't have seemed so crazy. =)
16:15replaca__technomancy: yeah, the nice thing is that I've got the doc stuff on our side pretty well organized now. So all the craziness is on the target :-)
16:17technomancyyeah, having doc strings is _so_ much nicer than having to run another parse over the source.
16:17replaca__yup
16:17technomancyand having simply vars with strings attached to them is much simpler than Ruby's OOP model.
16:17replaca__and being able to add metadata
16:18jackdempseytechnomancy: hey man, yt?
16:18technomancyjackdempsey: yeah, sure
16:18replaca__but I've reduced it to maps, keywords, and strings
16:18clojurebotmaps are *AWESOME*
16:18technomancywhat's up?
16:19jackdempseyplaying with compojure a bit more
16:19jackdempseythere's no such function as "param" right
16:19jackdempseyits just params?
16:19jackdempseyreason i ask, on your readme there's "(alter session assoc :name (param :name))"
16:19technomancymy readme?
16:19jackdempseyand param doesnt' seem to work for me
16:19jackdempseyyeah sry, your fork of compojure:-)
16:19clojurebotcompojure is a concise web framework inspired by Sinatra
16:19jackdempseyhttp://github.com/technomancy/compojure/tree/master
16:19jackdempseyhahah
16:19jackdempseythx bot
16:20technomancyoh... don't trust my fork!
16:20jackdempseyi'm posting some json and doing something a bit wrong with params, so was just looking around
16:20jackdempseyhaha, ah ok
16:20technomancyI haven't used it since like January
16:20jackdempseyah i see
16:20jackdempseyyour readme is so much nicer tho :-)
16:20technomancyheh; really?
16:21jackdempseyyeah, you actually ahve examples and stuff
16:21jackdempseyweavejester should pull it in
16:21technomancywell not if the examples are out of date. =)
16:21hiredmanI think the mainline was being rewritten to build on top of ring?
16:22technomancythe only thing I added to compojure was the html5 doctype. =)
16:22hiredmancompojure.org is very, uh, sparse
16:23jackdempseycool hiredman, looked at ring as well
16:23jackdempseywill be interested to see where it goes
16:37jackdempseyso 'show' from contrib shows info about the java aspect of something, right?
16:37jackdempseyis there a way to take something, say a float, and see what methods i can call on it?
16:38jackdempseykind of thought that's what show was for but appears i was mistaken
16:38jackdempseyclojure methods that is...just realized i can add a dot to the beginning of what i see from show and make the call to java which is useful...
16:49technomancyit's conventional to capitalize gen-classed java classes, right?
16:50ChouserI think so. I don't think - are allowed
16:57hiredman,(Character/isJavaIdnetifierStart \-)
16:57clojurebotjava.lang.IllegalArgumentException: No matching method: isJavaIdnetifierStart
16:57hiredman,(Character/isJavaIdentifierStart \-)
16:57clojurebotfalse
16:58hiredman,(Character/isJavaIdentifierPart \-)
16:58clojurebotfalse
16:58hiredman:|
16:59jackdempseyi have a function that alters a ref..."add-channel"...is it more common to put the do-sync inside that function or outside?
16:59technomancyjackdempsey: depends on what you need it to be synchronized with
16:59jackdempseyhmm ok
17:00technomancy(if you need unsynchronized mutability, use an atom instead of a ref)
17:00jackdempseyyeah, pretty simple scenario
17:00jackdempsey(def *db* (ref {:channels #{}, :subscribers {}}))
17:00jackdempseyjust need to add to that on certain http requests
17:01jackdempseyno deletes for now...so maybe an atom makes more sense then?
17:02jackdempseyhmm, says atoms are for uncoordinated synchronous changes
17:02jackdempseyjust trying to get my terminology right :-)
17:02technomancyright; in those terms you need to ask if that change needs to be coordinated with others.
17:02jackdempseyyea, ok cool
17:03jackdempseyyea i think the answer is a no then
17:06jackdempseyprobalby would be good to implement this with all three varieties..
17:07jackdempseyback to the higher level question though, i think i see what you mean about what needs to be synched
17:07jackdempseyif you have a couple pieces that all need to run in the same transaction, then a dosync around all three would be necessary
17:08jackdempseyif i can do what i need inside one method that does a simple alter, and i'm just throwing a dosync in there to get it to work, maybe an atom could work as well....
17:09technomancyexactly; no need to pull in the STM if you don't need the promises it provides.
17:09jackdempseyyep.
17:10jackdempseyah, these rusty gears in my skull need oil. been a while since i've had to think. damn web development ;-)
17:12technomancyheh. well STM is a sexy tool. =)
17:15jackdempseyheh
17:20achimhi all!
17:20achimgiven a class name (string), is there a way if that would resolve to a currently imported class?
17:21achim^ is there a way *to see* if that...
17:22achimah, plus the class name is unqualified
17:23hiredman,(class (resolve (symbol "String")))
17:23clojurebotjava.lang.Class
17:24hiredman,(class (resolve (symbol "NotAString")))
17:24clojurebotnil
17:25achimhiredman: thanks!
17:50technomancyjust committed functionality to swank-clojure to search the classpath for a class and insert import statements for it
17:50technomancyfeedback welcome: http://github.com/technomancy/swank-clojure/tree/master
17:50hornbecknice
17:51technomancyit inserts a new import line every time you run it; not smart enough to combine them yet
17:52durka421awesome
17:52technomancybut it beats using unix find for .class files. =)
17:53technomancydurka42: well I stole it from http://dishevelled.net/Generating-Clojure-import-lines-using-SLIME.html (after asking of course.)
17:54durka42indeed, he has something very similar to my "smuggler" in his user.clj code
18:57RaynesHoly shit. I just realized that after using XMonad for any length of time, I literally can't work with Compiz at all.
18:58Chousukecan't? :/
18:59RaynesI feel so out of it in Compiz.
18:59Chousukeis it like getting used to vimperator and becoming uncomfortable using any other browser on the planet?
19:00RaynesI guess...
19:01ChousukeI would like to dump firefox but so long as there's no Webkit-based vimperator clone for OS X I'm unable to do so :P
19:02ChousukeFF is good enough as of 3.5 anyway
19:49drewrhave you guys tried running swank/start-server from outside emacs?
19:52drewrclojure.core/*3 is unbound
19:57technomancydrewr: thought about it. would love to hear if you figure it out. =)
20:00drewrit's odd because in dothread-keeping-clj where the expanded code generates the exception, *3 gets loaded as part of ns-publics
20:10drewrah, got it
20:19drewrhttp://github.com/drewr/swank-clojure/commit/03158e47d9e8e18dfc5af9d61cd4f73cf7edfa36
20:20drewrthink I'll redo that with a regexp instead
20:22drewrthe asterisks just make it so ugly
20:24drewrhttp://github.com/drewr/swank-clojure/commit/99628e5f4ab9e46e4b8d30ad5380e96b86358e5a
20:29mblinnis there a way to do forward declarations in the ns or do you just use declare?
20:29mblinnhmm
20:29mblinnextra the in here
20:29mblinnthere
20:30replaca__mblinn: declare *is* the way to do forward decls
20:30replaca__mblinn: this is a subject of constant discussion, but that's the way it is
20:31mblinnokay was just curious since you seem to be able to do all the other housekeeping type stuff in ns
20:31mblinnthanks
20:42technomancydrewr: that code is a little weird
20:42technomancylots of unnecessary type hints
20:43technomancymblinn: that's not a bad idea; seems like it would look cleaner that way
20:43mblinnyeah it's a little cosmetic thing
20:47drewrtechnomancy: yep
20:48JAS415i get this error: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NullPointerException (repl-1:7)
20:48JAS415is there any way to make it more descriptive
20:48JAS415it really isn't helping me figure outwhat is going on
20:50hiredmanyou are doing something you shouldn't with nil
20:51JAS415sure that's reasonable
20:51JAS415but like in CL i get a whole long stack trace
20:52hiredmanoh
20:52hiredmanyou want the full stacktrace
20:52hiredman (.printStackTrace *e)
20:53JAS415ah sweet
20:53JAS415that will make this much easier
20:57technomancyhas anyone actually used the mstor library?
20:57technomancyI don't mean anyone in here, I mean anyone anywhere...
20:59durka42JAS415: also, clojure.contrib.stacktrace/print-cause-trace
21:08JAS415very nice, exactly what i'm looking for
22:33somethingis there a way to get the string value of a keyword without colon? basically opposite of keyword
22:35Chouser,(name :foo)
22:36somethingChouser: ah, yes. thanks
22:41kmartinHi, anyone know if there is a reason the function "reverse" is not lazy?
22:41Chouserkmartin: how could it be?
22:42Chouserthe first item it returns is the last of the input seq, so it's got to get to the last of the input seq first, which forces the whole thing.
22:43gstampAnyone know of a decent web based IRC client? I'm behind a proxy here. I'm currently using http://webchat.freenode.net/ but it tends to hang silently.
22:43kmartinI was assuming that it could be done with a closure, but I see what you are saying. Thanks.
22:50drewrtechnomancy: ran into other problems
22:53drewrhaven't figured out how these bindings work
23:11technomancydrewr: =\
23:20lisppaste8technomancy pasted "with-preserving-file macro" at http://paste.lisp.org/display/83209
23:20technomancyany idea why that macro fails when AOT'd but seems to work from the repl?
23:24drewrhm, similar issue I'm seeing with swank
23:25drewrmine's not with compilation though
23:26Chouser'if' isn't a var (anymore)
23:27durka42,if
23:27durka42in my repl that gives var unbound
23:29ChouserI get "Unable to resolve"
23:29technomancyChouser: is the usage in that macro such that it expects it to be a var?
23:29Chouser(resolve 'if) returns nil
23:31ChouserI don't see anything wrong with your usage, but exception seems to indicate it thought it was a var. or something. odd.
23:37technomancyit's gone now... I'm using the exact same code (checked in). =\
23:37Chousermaybe just needed a clean re-compile?
23:37technomancyI guess so
23:56Knekkcan't get to the clojure google groups pages.. bleh
23:56Knekkah there we are