#clojure logs

2009-01-06

00:40zakwilsonSlime is evaluating expressions from a file (via C-x C-e and C-c C-c) in the user namespace instead of the file's namespace. I've eval'd the ns form and set the ns in the repl. Am I missing something obvious?
00:43dhayazakwilson: are you sure it is evaluating in the user namespace? try evaluating *ns* and see what that returns.
00:44zakwilsonI did. It returns #<Namespace user>
00:47zakwilsondhaya: it only returns the correct ns in the repl.
00:50dhayastrange. i don't seem to have that problem.
00:54zakwilsonAnd now that I've updaded everything to the bleeding edge, the repl doesn't come up properly - just the *inferior-lisp* buffer.
00:54dhayaany error messages?
00:56zakwilsonYes: Exception in thread "Call-on-write Stream" java.lang.RuntimeException: java.lang.IllegalArgumentException: No matching method found: sleep for class java.lang.Class
00:56dhayadid you update swank clojure? IIRC that was fixed a while back.
00:56zakwilsonThough I seem to remember seeing an exception when Slime started before, as well as some discussion to the effect that it isn't a problem.
00:57zakwilsonYes. I just now updated it - it didn't do that until I did.
01:05dhayaFWIW, I am on the bleeding edge now and I don't have any trouble starting slime/swank.
01:07zakwilsonjava.lang.Exception: No such namespace: clojure (swank.clj:11)
01:08zakwilsonThough I don't see where it's getting that, looking at the file.
01:08danlarkinyeah you're probably pulling in an old swank-clojure, since clojure hasn't been a namespace for a while
01:13zakwilsondanlarkin: It looks like it might be pointing to an old file I forgot was there. Working on it.
01:17zakwilsonI've eliminated any references to old files that don't work anymore, but I'm still not getting a repl.
01:17zakwilsonNo more exceptions though.
01:18danlarkinI'm also on bleeding edge and everything is working okay for me
01:18danlarkinbut now I'm off to bed
01:18danlarkingoodnight all
01:28durkai'm working on a program to help with missing imports
01:28durka=> (lookup "Ref")
01:28durka["java.sql.Ref" "sun.misc.Ref" "com.sun.xml.internal.bind.v2.model.core.Ref" "com.sun.xml.internal.bind.v2.runtime.reflect.opt.Ref" "com.sun.xml.internal.xsom.impl.Ref" "clojure.lang.Ref"]
01:28durkathis only works after a time-consuming scan of the classpath
02:49fffejif I apply map to a hash-map, what should be the structure I return so as to keep the returned collection working with assoc / get etc?
02:53cmvkkmap just returns a list i guess
02:54fffejis there a way I can return that list that is easily converted back into a hash-map?
02:54cmvkkyeah, if you use pairs in vectors
02:54cmvkk(into {} '([:a 1] [:b 2] [:c 3])) will return a map as you expect
02:55fffejsweet - pairs in vectors was the magic I was looking for, thanks!
03:12fmezaquit
03:12fmezaexit
03:58Lau_of_DKOla 'el Kota'
03:59kotarakHola, se�or.
05:05AWizzArdMoin
05:07AWizzArdHow can I make POST requests in Clojure?
05:12kotarakAWizzArd: HttpURLConnection has a setRequestMethod....
05:17Lau_of_DKAWizzArd: Theres a http-client in Contrib which handles that stuff very nicely
05:20AWizzArdyes, and I wanted to use this http-client in the past for get requests and got the suggestion to better use duck-streams reader.
05:20AWizzArdAnd is there already something for xml-rpc in Clojure?
05:21Lau_of_DKCheck out lazy-xml in contrib :)
05:21Lau_of_DKThat might be it
05:46knaprhow do I break a line in a string without adding a \n or \r ?
05:52AWizzArdknapr: inside the quotes press enter
05:53AWizzArdLau_of_DK: I think lazy-xml is more for parsing than doing xml-rpc requests via http post.
07:20AWizzArdIf I have a directory with 10 .jar files, is there then a way to add them all to the classpath by specifying a placeholder or something like that? "classpath=/home/user/lib/*"
07:21Lau_of_DKjava -cp .
07:21Lau_of_DKwill add all files in current directory to cp
07:26AWizzArdoki, I will try the dot as placeholder instead of the star for the windows env var
07:32StartsWithKAWizzArd: There is no wildcard substitution for -cp
07:32StartsWithKwhat you can do is write small shell script, like: CP=lib/* java -cp $CP ...
07:33StartsWithKand bash will expand lib/* for you
07:33Lau_of_DKStartsWithK: I heard people say that, but wildcards work fine here
07:33StartsWithKLau_of_DK: Is that only a windows thing then?
07:34Lau_of_DKMight be, Im on Linux
07:34StartsWithKjava -cp lib/* clojure.lang.Repl
07:34AWizzArdStartsWithK: I want to put the 10-20 .jars into the environment variable in Windows.
07:35StartsWithKthis will fail
07:35StartsWithKjava -cp "lib/*" clojure.lang.Repl
07:35StartsWithKthis will work
07:35StartsWithKform prompt
07:35StartsWithKfrom*
07:35StartsWithKAWizzArd: maybe this quoted form will work? "lib/*"
07:36AWizzArdI will try some variations
07:36Lau_of_DKah thats right K, its got to be quoted
07:36StartsWithKit works for me on linux
07:36Lau_of_DKbut I think everything needs to be quoted in Windows anyway
07:36Lau_of_DK/clojure$ java -cp "./*" clojure.lang.Repl
07:36Lau_of_DKClojure
07:36Lau_of_DKuser=> (+ 2 2)
07:36Lau_of_DK4
07:36Lau_of_DK
07:38StartsWithKi always used small launcher script so didn't even notice this quoted form
07:38StartsWithKcan it be used like "lib/**/*.jar"?
07:48knaprcan I say "select avg(cast(grade as double)) from reviews for customerid in customers"?
07:48knaprsql that is
07:48knaprsomething like that
07:48knaprI have a bunch fo moviereviews and want to find the highest average reviewers and lowest
07:48knaprI have 3 tables, customers(:customerid), reviews(:customerid, :grade, :review-date, :movieid) and movies(:title, :releasedate, :movieid)
07:52knaprgroup by?
07:57knaprhow do I set primary key with contrib/sql?
08:01AWizzArdHow do you want to "set" a primary key?
08:01AWizzArdWhen you insert you just specify a value...
08:02AWizzArdOr in the case of mysqls auto-increment even that is not needed.
08:08knapr(query "select avg(cast(reviews.grade as double)), customers.customerid
08:08knaprfrom reviews join customers on reviews.customerid = customers.customerid
08:08knaprgroup by customerid")
08:08knaprjava.sql.SQLSyntaxErrorException: Column name 'CUSTOMERID' is in more than one table in the FROM list. (db.clj:0)
08:08knapruser=>
08:08knapruh?
08:10StartsWithKgroup by reviews.customerid
08:12knaprah
08:29knaprhttp://paste.pocoo.org/show/98246/
08:30knapr^^ anyone can help me with tis fairly complex sql-statement
08:30knaprcode and sql error ^^
08:31Lau_of_DK:) Well, I could, if you used a proper lib :)
08:34knaprok
08:34knaprim pulling uit
08:38cgrandknapr, try replacing customers.customerid by reviews.customerid
08:38Lau_of_DKOk, review the demos, ask me or kota tonight if you need help, im at work, he's offline I believe. the run macro will feed you a resultset-seq, you can cast values on their way out of that
08:38knapryeah wait
08:39knaprwhy am i even joining lol?
08:40knapr(query "select avg(cast(grade as double)), customerid
08:40knaprfrom reviews group by customerid")
08:40knaprbut does this calc the average grade for all customers?
08:45knapris defn like pythons _thisisprivate_ ?
08:46knapris defn- like pythons _thisisprivate_ ?
08:46knaprnot enforced privacy, just "dont touch this t is internal k thanks"
08:50knaprhow do I require clojure-ql?
08:51lisppaste8gnuvince pasted "defn-" at http://paste.lisp.org/display/73180
08:51gnuvince_knapr: see this link
08:54knaprthanks
08:57knaprwhere is condp Lau?
08:58knapris condp in a new clojure-version? im using december
09:03Chousukeknapr: I think condp is SVN-only right now.
09:05Lau_of_DKknapr: Its in the latest SVN, you must update
09:08knaprwhat does condp do?
09:08Lau_of_DKIts a clever way of nesting cond's
09:08Lau_of_DK(doc condp)
09:08clojurebotNo entiendo
09:08Lau_of_DKits similar to a switch statement
09:10knaprah
09:10Chousukewow, condp is pretty complex.
09:10Chousuke:>> seems pretty useful though
09:52knapranyone doing the netflix prize?
09:55gnuvince_When I use SLIME at work (no GUI), I can start slime just fine, but I just get the *inferior lisp* buffer, not the *clojure repl* one where typing a function name displays the arguments in the mini buffer. Anyone had this problem before?
09:56gnuvince_The config file is the same than the one at home and so are the versions of Clojure, slime and swank-clojure.
09:58gnuvince_Ah, I caught billc's message about breaking changes
09:58Lau_of_DK:)
10:00gnuvince_That's sad :(
10:01Chousukesad?
10:01gnuvince_Yeah
10:02Chousukein the new slime you just need to enable the fancy repl manually
10:02Chousukeit's pretty easy.
10:04gnuvince_How is that done?
10:04gnuvince_(slime-setup '(fancy-repl)?
10:05Chousukehttp://github.com/Chousuke/dotfiles/tree/master/Aquamacs-customizations.el#L59
10:06knaprwhen using drop-table from contrib.sql doesnt that delete the table forever?
10:06Chousukeyes.
10:06Chousukewell, drop table usually dpes that :P
10:06Chousukedoes*
10:07gnuvince_great
10:07gnuvince_thanks
10:07gnuvince_Chousuke++
10:11gnuvince_hmmm
10:11gnuvince_it worked before I restarted Emacs...
10:13ChouserI enjoy having an environment that doesn't break when I upgrade things.
10:14Chousukegnuvince_: is your clojure-swank also recent? :/
10:15gnuvince_yes
10:15gnuvince_It's a git submodule
10:15gnuvince_I seem to have it...
10:15Chousukesubmodules are one feature of git I have no clue about :/
10:15gnuvince_I'm clueless about most git features
10:16gnuvince_I dislike it
10:16ChousukeI would probably like most of the DVCS systems.
10:17Chousukebut I'm familiar with git so obviously I like it the best.
10:17gnuvince_argh...
10:17gnuvince_stupid submodules...
10:17gnuvince_they're the cause of my problem
10:18Chousukeone thing is certain though. I will never again use SVN for any of my projects :P
10:18Chousukeit's too... restrictive.
10:19gnuvince_I like Mercurial myself. It makes a whole lot of sense, but it seems that git is poised to become the de facto DVCS for open source projects, so I make an effort to use and learn it.
10:19Chousukemercurial and git are probably not too different.
10:20ChousukeI wonder if there's a hg equivalent to the "git magic" tutorial :/
10:21gnuvince_Dunno what that is.
10:21gnuvince_But Hg feels less disparate than git
10:23Chousukegit magic is this: http://www-cs-students.stanford.edu/~blynn/gitmagic/
10:23Chousukeclojurebot: git?
10:23clojurebotgit is http://www.github.com
10:23Chousukehm
10:27gnuvince_Fuck this sucks...
10:27gnuvince_I do git submodule update and slime breaks
10:54triddellIn case anyone is interested, I just posted (to the google group) a pretty print function for xml/xhtml which uses the javax.xml classes in the JDK.
11:17Chouserpretty print is marked as done on the clojure todo, but I'm not aware of any complete (non-xml) pretty printer. Did I miss it somewhere?
11:27danlarkinnews to me
11:36triddellChouser: so was there a clojure-based pretty print for xml that I missed before writing this function? I asked on here and searched yesterday but didn't find one.
11:40Chousertriddell: not really. clojure.xml/emit adds newlines, but doesn't indent
11:44triddellChouser: ok, well the function I wrote is a big hammer for this problem but solved the issue for me for now
11:44Chousersure, thanks for sharing it.
11:45AWizzArdDoes anyone here use the xml-rpc lib from http://ws.apache.org/xmlrpc/ from time to time? I am having a problem when I say (def client (XmlRpcClient.))
11:46AWizzArdThis throws a NoClassDefFound exception for org.apache.xmlrpc.common.TypeFactoryImpl.
11:46rhickeyChouser: pprint is done as far as the todo list - moved to issues - http://code.google.com/p/clojure/issues/detail?id=16
11:46rhickeytodo list is soon to be no more
11:46AWizzArdBut when I type org.apache.xmlrpc.common.TypeFactoryImpl into the repl it returns the class. So, the class is in the classpath.
11:47Chouserrhickey: ah! very good.
11:53triddellAWizzArd: I haven't seen any issues with importing classes and name resolution
11:57AWizzArdI also didn't have this problem before.
12:54sulo_hi folks... can anyone tell me.. is there a clojure tutorial or something like that around? on the webpage i couldn't find anything
13:00vogelrntutorial as in how to use it or how to install it?
13:00meredyddWhat happened to clojure.contrib.def? Specifically, how do I get 'defvar- back, or something like it?
13:01technomancysulo_: the book is definitely the best resource for that. there's not anything else that's well-organized and canonical.
13:01technomancyalthough you could try the wikibook
13:01technomancyclojurebot: wikibook?
13:01clojurebotI don't understand.
13:01danlarkinclojurebot: wiki
13:01clojurebotwiki is http://en.wikibooks.org/wiki/Clojure_Programming
13:10danlarkinsulo_: I will still recommend the videos at http://clojure.blip.tv
13:14zargon_how can I (take ) n values from a seq and later take another n values from the now "shortened" seq?
13:14technomancythe videos are great for getting excited. not sure if they're so good for coding though.
13:16danlarkin(doc drop)
13:16clojurebotReturns a lazy seq of all but the first n items in coll.; arglists ([n coll])
13:16danlarkinzargon_: ^
13:16hoeckzargon_: maybe look at split-at
13:16hoeck too
13:16danlarkin(doc partition)
13:16clojurebotReturns a lazy sequence of lists of n items each, at offsets step apart. If step is not supplied, defaults to n, i.e. the partitions do not overlap.; arglists ([n coll] [n step coll])
13:16Chousukeor partition
13:16Chousukeright
13:17zargon_aha, ok
13:20zargon_I guess (drop n) on a seq is O(n), right? So dropping in a loop is a bad idea ...
13:21danlarkinif you tell us what you're trying to achieve perhaps we can help suggest a good way to accomplish it
13:22zargon_I just wondered how to consecutively take n values from a seq without too much of a performance hit, but i think (partition ) would be the solution
13:23danlarkinjust be careful of the following:
13:23danlarkin(take 2 [1 2 3 4 5])
13:23danlarkin,(take 2 [1 2 3 4 5])
13:23clojurebot(1 2)
13:23danlarkinerr
13:23danlarkinwell my point is that 5 is left dangling
13:24zargon_?
13:24danlarkin,(partition 2 [1 2 3 4 5])
13:24clojurebot((1 2) (3 4))
13:24danlarkinsorry, that is what I meant to write
13:24zargon_ok i see
13:37knaprhow can I set primary key and foreign key in contrib.sql?
13:37knapr(defn create-reviews-table [] (sql/create-table :reviews [:customerid :int]
13:37Lau_of_DKknapr: May I recommend to you, the Google Group, for those question that do not get answered here, even after posting them 5+ times
13:37knapr[:foreignkey =?
14:03duck1123Lau_of_DK: would you recommend ClojureQL for use yet, or is it still unstable?
14:04Lau_of_DKduck1123: It depends on the scope I'd say. The function that are currently implemented, are all stable as far as we have been able to test, but admittedly, we have not tested it sufficiently
14:04Lau_of_DKFor common use (select, insert, update) I wouldnt hestitate to use it myself
14:07duck1123I was looking at it last night when I was getting frustrated at using format to create queries. It still needs a bit more documentation. I would have to play with it a bit before trying to replace c.contrib.sql
14:08Lau_of_DKPoint taken, we do need to invest some time documentating the features, however if you review the demo files included in the repo, you should be able to catch on pretty quickly
14:08Lau_of_DKAnd if you have questions, shoot
14:10duck1123quick question, do the results come back as a struct or a hash-map, or other?
14:11Lau_of_DKCurrently all queries return as resultset-seq's, which are available while the connection is open only, they are sort of lazy
14:12Lau_of_DK@ duck1123
14:12technomancyis the SQL lib in contrib lazy?
14:12Lau_of_DKdunno
14:12Lau_of_DKI think so
14:13technomancyso the main advantage is decent syntax rather than constructing SQL strings
14:14Lau_of_DKtechnomancy: Its more than just syntax, the queries themselves become qualitifed for standard clojure set operations like union, intersect, concat and so on, so you can perform clojure-code on them
14:14duck1123Lau_of_DK: contrib requires the connection to be open as well, so that's no big deal
14:14technomancycool
14:15Lau_of_DKduck1123: I didnt say it was, you just asked how the results were returned
14:16duck1123I ran into an issue last night when trying to dissoc the results from a contrib.sql query, so I was wondering if the same would apply with clojureql
14:17kotarakduck1123: what do you mean by dissoc?
14:17Chouserif each result row is a structmap, you can't dissoc any basis key
14:18Chouseryou can set the value to nil, but not dissoc
14:18duck1123I was trying to remove a key-val from the results of a query, but since it's a struct, you can't dissoc the base keys
14:18Chouseryou could copy into a new map, though, and dissoc from that.
14:18kotarakAh. Ok. For now we also use struct-maps.
14:18ChouserI think struct-maps are probably the right solution
14:19duck1123Chouser: I tried that, but I don't think I was getting the syntax right.
14:19Lau_of_DKduck1123: For what purpose did you want to filter data ?
14:19Chouser(dissoc (into {} result-row) :col-to-remove)
14:20Chouserseems like an odd use-case, those. I don't think I'd warp an API to support it any better than that.
14:20duck1123Chouser: thanks. That was not what I was trying. Much better
14:20Lau_of_DKduck1123: If there are features you want in result-handling, now's the time to make your case
14:21duck1123Lau_of_DK: I am joining tables, and I was trying to convert the last column into a vector of maps of the values of the second table
14:22duck1123There's probably a much better sollution, but it was late when I was working on this
14:25Lau_of_DKduck1123: Yea there might be a better way to construct that query, but I'll think it over. Im not bent on the resultset-seq solution, but for what we support now it makes a very good fit
14:25duck1123I'm trying to produce something like: {:id 1, :name "duck1123", :identities [{:url "http://duck1123.myopenid.com/&quot;, :primary false}, {:url "http://kronkltd.net/&quot;, :primary true}]}
14:25whiddenAre there any examples of clojure.contrib.Monad laying around? If so a gentle pointer to their locaction would be nice.
14:26Chouserwhidden: did you search the google group?
14:27whiddennope.. not yet... just saw the new checkins, did a google search on Monad, and got a bucket full of Haskel.
14:27Chouserheh
14:27whiddeni don't grok haskel, not sure if this is good or bad at the moment.
14:27kotarakduck1123: (let-query [result1 (query ...) result2 (query ...)] (do-something-arbitrary with result1 and result2) ; should return a seq)
14:28Chouserthere are a couple threads on monads in the group. I'm not sure, but I think the contrib is based on one of those, and there may be examples in the discussion.
14:28kotarakduck1123: The return value of let-query is again a query, which can be passed to run or whatever.
14:29duck1123kotarak: thanks. I think I'll play with clojureql when I get home tonight
14:29kotarakduck1123: be warned! docs? nope stable? nope
14:30duck1123Then it'll fit in nicely with the rest of my site. :)
14:30kotarakhehe :)
14:31Lau_of_DKkotarak: Why do you say not stable?
14:32duck1123Lau_of_DK: so I wouldn't be disappointed if I find a problem
14:32kotarakwell. we are not a rekease,yet. So maybe something may change in the interface. Or maybe not. But one should not rely on it for now.
14:32Lau_of_DKYou shouldnt be, you should report the bug. But I just havent come across anything that was buggy yet in the current form
14:32Lau_of_DKThough, that form may change in the next couple of hours :)
14:33kotarakThere are specialities how to use it, which are not documented, yet.
14:38Chousukeit's kind of confusing that even though rng is a function, in the domonad syntax in one of your examples, there are no parens around rng, so it looks like you're simply taking its value :/
14:43whiddenok back from reading about monads in google groups.. not a lot, saw the parser, will play with that tonight and see how my groking goes. Thanks for the pointer.
14:46Chousukekotarak: what's the status of your parser btw?
14:47Chousukekotarak: your page on it is outdated at least. In your example, you have a #(.isLetter Character %) which is no longer valid :)
14:47kotarakChousuke: Currently fiddling around with my multimethod monads. I spent some time on the monad transformer part, but I can't say, that I understand this.
14:47kotarakChousuke: yes it's very outdaten.
14:48kotarakChousuke: Have to bring it up-to-date, but Lau interrupted me with ClojureQL. ;)
14:52danlarkinoh speaking of parser
14:53danlarkinhttp://github.com/joshua-choi/fnparse/tree/master
14:54kotarakdanlarkin: yeah. I'm still unsure on how to represent the parser result.
14:54hiredmanoooo
14:56danlarkinit's not a parser combinator, but it's definitely interesting work
14:57kotarakdanlarkin: yeah, definitively. There so much going on around Clojure at the moment! :) Nice pointer. :D
14:57duck1123see, this is why we need an EBNF for Clojure. We'll be able to parse Clojure in Clojure. :)
14:58danlarkinduck1123: I see what you did there...
14:59gnuvince_Is it not possible to give meta data to a function? (def y (with-meta (fn [] :y) {:foo :bar}))
14:59gnuvince_?
15:00kotarakNo.
15:00Lau_of_DKkotarak: sure? I think something changed in that regard in one of the recent revisions
15:00gnuvince_Is there a way to carry around additional information about a function then?
15:01kotarakNamespaces have know meta-data.
15:01kotaraks/know/now/
15:03gnuvince_Ok
15:03gnuvince_Weird thing
15:03gnuvince_This works: (defn #^{:foo :bar} y [] :y)
15:03mfredricksonLau_of_DK: is this what you want?
15:03mfredricksonhttp://gist.github.com/43965
15:03kotarakgnuvince_: that attaches the metadata to y, the symbol.
15:03Chousukegnuvince_: that attaches the metadata into the var.
15:04Chousukehm? was it the symbol?
15:04kotarak#^ works on follows, that is the symbol y. From there it's probably transferred to the Var by def.
15:05Chousukenope, you need to do (meta #'y)
15:05gnuvince_This doesn't work however: (defmacro x [] (let [name 'y] `(defn #^{:foo :bar} ~name [] :y)))
15:06Lau_of_DKmfredrickson: gnuvince_ wants :)
15:06kotarakChousuke: it is attached to the Var, but #^ is a reader macro. At that moment there is no Var. So it is attached to the Symbol y. From there it's transferred to the meta-data of the Var.
15:07mfredricksoni must admit I still don't have a great understanding of the Var vs. Symbol difference in clj
15:07mfredricksonvs. keywords
15:07Chousukevars hold values
15:07kotarakgnuvince_: (defmacro x [] (let [name 'y] `(defn ~(with-meta name {:foo :bar}) [] :y)))
15:08technomancya symbol is a name; nothing more
15:08technomancyall code is made up of symbols
15:08Chousukemfredrickson: keywords are symbols that resolve to themselves
15:08Chousukemfredrickson: symbols normally resolve to vars.
15:08technomancyChousuke: keywords are mostly like in CL right? except for additionally being functions?
15:09technomancyand the colon isn't used to mean "no package"
15:09ChousukeI'm not sure what they are like in CL
15:09Chousukewell, single-colon keywords have no namespace .)
15:09mfredrickson,(macroexpand-1 #'foo)
15:09clojurebotjava.lang.Exception: Unable to resolve var: foo in this context (NO_SOURCE_FILE:0)
15:09kotarak:foo/bar
15:10Chousukeexcept wehn like that yeah
15:10technomancyin CL you use the notation package-name:symbol to refer to a symbol in a different package in a way that evals to itself. leaving out package-name becomes just :symbol, which IIRC is like being in a null package
15:10mfredrickson,(macroexpand-1#'+)
15:10clojurebotjava.lang.Exception: Unable to resolve symbol: macroexpand-1# in this context (NO_SOURCE_FILE:0)
15:10mfredrickson,(macroexpand-1 #'+)
15:10clojurebot#'clojure.core/+
15:10Chousukemfredrickson: I don't think macroexpand works with reader macros.
15:11Chousuke,(macroexpand-1 '#'+)
15:11clojurebot(var +)
15:11mfredricksonChousuke: i think you are correct
15:11Chousukeah, they do.
15:11Chousuke:P
15:12mfredricksoninteresting
15:12mfredrickson,(meta (var +))
15:12clojurebot{:ns #<Namespace clojure.core>, :name +, :arglists ([] [x] [x y] [x y & more]), :file "core.clj", :doc "Returns the sum of nums. (+) returns 0.", :line 546, :inline #<core$fn__2956 clojure.core$fn__2956@1e21f52>, :inline-arities #{2}}
15:13knapranyone good with statistics and math? i need to calculate rmse(root mean square error). but i dont get form wikipedia exactly how i do it. lets say a simple example is. correct is 4 3 3 and I guess 4 2 3, what would the rmse be then? sq(sqrt((4-4)+(3-2)+(3-3)) / 3) ?
15:13knaprand is the closer to 1 the better=?
15:18mfredricksonknapr: take the difference of all predictions with observed. square them. sum them. take the square root
15:20mfredricksonoops: finally divide by the square root of the number of pairs
15:21whiddenknapr: and the closer to zero better.
15:21wlrwhidden, monads.clj in the Google Group's Files section is a monolithic file with examples included
15:22whiddenthat would mean your predictions and results matched perfectly.
15:22whiddenwlr: thanks.. I'll look at that.
15:24Chouser(/ (apply + (map #(* % %) (map - obs prd))) (Math/sqrt (count obs)))
15:24Chouserbased on mfredrickson's description
15:24whiddenwlr: I did not realize there was a files section for groups.. Thanks for the pointer.
15:27rhickeyChouser: thanks for comments patch!
15:28whiddenChouser: wouldn't it be (Math/sqrt (/ (apply + (map #(* % %)(map - obs prd))) (count obs))?
15:28mfredricksonwhidden: yes.
15:29wlrwhidden, np
15:31gnuvince_I have *another* question about metadata (sorry)
15:32gnuvince_If I have this function:
15:32gnuvince_(defn #^{:foo :bar} f [] :f)
15:33Lau_of_DKgnuvince_: If we have to start appologizing for asking questions, I have a big backlog :(
15:33Chouserrhickey_: heh. sure.
15:33gnuvince_is it possible to "copy" the meta-data to another instance?
15:33gnuvince_For instance:
15:33gnuvince_(let [x f] (:foo (meta x))
15:34Chousergnuvince_: the metadata from your defn is on the Var named f, not it's value (which is a fn)
15:34kotarak(defn f (meta #'g) [] :f) like that?
15:35gnuvince_Chouser: so if I pass f as a parameter to another function, I don't have access to the meta-data, right?
15:35Chousergnuvince_: so the moment you say (let [x f] ...), the Var f gets dereferenced to its current value (the fn) which is then bound to the local x. There's no way to get to f's metadata from x.
15:35Chousergnuvince_: right.
15:35gnuvince_meh
15:35Chouseryou could choose to pass the Var
15:36gnuvince_That would be ugly for the user
15:36gnuvince_I'll have to think of something else.
15:37ChouserI do think it'd be nice to be able to put metadata on fns, but I think there's something about what they really are in the JVM that makes that a bit tricky to do.
15:43gnuvince_There we go
15:44gnuvince_I used a map instead. {:fn (fn [] ...), :the-meta-data-i-want [foo, bar]}
15:45knaprmfredrickson: [4 3 4] and [4 2 2] -> ((4-4)^2 + (3-2)^2 + (4-2)^2) / (sqrt 3) ?
15:45knaprhttp://paste.pocoo.org/show/98364/
15:45stuarthallowaywhat should a function that alters multiple refs return?
15:46stuarthallowaythere is something dissatisfying about returning the last modified thing, when conceptually everything happens at once
15:46mfredricksonknapr: see whidden's version -- take the sqrt of (/ (sum diff) (count diff))
15:46stuarthallowaybut on the other hand it seems ridiculous to write extra code when nobody is expected to look at the return value
15:53Chouserstuarthalloway: this is a function with a dosync in it? Or one that is expected to be used in a dosync?
15:53stuarthallowayreset-game from snake
15:53paois anyone using vim for clojure?
15:53paois it viable?
15:53stuarthallowayit has a dosync in it
15:53stuarthallowayit updates two things
15:53kotarakpao: yep
15:54stuarthallowayand returns (coincidentally) the last thing listed
15:54Chouserpao: absolutely
15:54paokotarak: thx
15:54durka_pao: yes
15:54stuarthallowayI find myself wanting to add a "nil" form at the end
15:54durkathanks largely to kotarak
15:54stuarthallowayvim is as viable for Clojure as for anything :-)
15:54kotarakpao: http://kotka.de/projects/clojure/vimclojure.html
15:54paowhat reading list would you suggest for a completely lisp ignorant (I'm familiar with python/haskell)
15:55paokotarak: thanks
15:55paostuarthalloway: vim rocks... :-)
15:55stuarthallowaypao: practical common lisp by Seibel
15:55red_fishpao: http://books.pragprog.com/titles/shcloj/programming-clojure
15:55paostuarthalloway: I'm inclined to abandon a language if it's not "vim friendly" ;-)
15:55knaproops: finally divide by the square root of the number of pairs
15:55kotarak+ stuarthalloway's blog about practical common lisp -> clojure
15:55red_fishi am reading it now
15:55knaprjust so there is no misconception, ^^ that staement was wrong?
15:56Chouserstuarthalloway: I would leave it alone -- let dosync return what it does. I suppose you could wrap [] around the ref-set's, but it hardly seems worth it.
15:56stuarthallowayseibel book is all online: http://www.gigamonkeys.com/book/
15:56stuarthallowayChouser: my concern is leaking implementation detail
15:56knaprit is square root of the average?
15:56stuarthallowayor possibly having a consumer of the code, not looking at the source, think that the return value is meaningful
15:56Chouserstuarthalloway: oh, then maybe explicitly return nil?
15:56stuarthallowayright
15:56Chouserthat's not too terrible
15:57stuarthallowayI hate the extra work
15:57stuarthallowaywas thinking about writing a macro around dosync that returns nil
15:57Chouserthere are a couple places in clojure code where you end up with a separate return value at the end of a 'do' block of some sort
15:57Chouserlike agent action functions that are meant for side-effects and want to return their first arg unchanged.
15:58paostuarthalloway: kotarak: thanks for the help
15:58Chouserpao: my only real lisp knowledge pre-clojure was from PG's "on lisp"
15:59kotarakpao: no problem
15:59paoChouser: PG?
15:59kotarakPaul Graham
15:59Chouserhttp://www.paulgraham.com/onlisp.html
15:59paokotarak: ops... ashamed
16:00stuarthallowaypao: PG is terrific
16:00stuarthallowaybut I think Seibel is better suited for hands-on tutorial
16:00paostuarthalloway: is a good sense I suppose :-)
16:00pao*in
16:00stuarthallowaythe real right answer is to read both of them
16:01paostuarthalloway: PG + siebel, right?
16:01stuarthallowaypao: yes, plus Norvig, Dybvig, and Friedman/Felleisen :-)
16:02paostuarthalloway: wack! :-)
16:03paostuarthalloway: that doesn't sound like lisp in 24 h ;-)
16:03stuarthallowayChouser: I posted the return value question on the mailing list
16:03stuarthallowaypao: http://norvig.com/21-days.html
16:03kotarakpao: though it's a bit old and for Scheme: "Teach yourself Scheme in Fixnum days" might also help
16:04stuarthallowayand while I am posting random "Norvig rocks" links: http://norvig.com/Gettysburg/making.html
16:06lisppaste8gnuvince pasted "lame quickcheck attempt" at http://paste.lisp.org/display/73202
16:07paois it reasonable to use clojure for trying out material from siebel&PG or is better to stick to clisp?
16:07gnuvince_pao: better stick to clisp
16:08paognuvince_: thanx
16:08Chousukethere are translations of some of the examples to clojure though.
16:09gnuvince_Anyone got comments on that quickcheck thing?
16:10kotarakgnuvince_: you could use classes for the arbitrary methods. (arbitrary Integer)
16:10paois it difficult to migrate from clisp to clojure?
16:10stuarthallowaygnuvince_: have you looked at Fact?
16:11gnuvince_stuarthalloway: I have not. Link?
16:11stuarthallowayhttp://groups.google.com/group/clojure/browse_thread/thread/193023afbf87698d
16:12stuarthallowaygnuvince_: Fact is also embedded in Compojure, which uses it for its tests: http://github.com/weavejester/compojure/tree/master
16:12gnuvince_Hmmm
16:12gnuvince_That's pretty cute
16:12gnuvince_Oh well
16:13gnuvince_at least I got to learn a little about metadata and symbols and macros :)
16:13Chousukepao: well, immutability kind of forces you to rethink some algorithms :)
16:13kotarakgnuvince_: then there clojurecheck. But I have a hard time at the moment to work on it.
16:14stuarthallowaykotarak: I was just looking for a link to that
16:14gnuvince_I think I saw that
16:14kotarakI haven't put up a site, yet. But the repo is online.
16:14gnuvince_stuarthalloway: didn't you actually write that?
16:15gnuvince_http://groups.google.com/group/clojure/browse_thread/thread/2cfdd49dace71125
16:15stuarthallowaygnuvince: I wrote a few suggestions, but kotarak ran with it
16:15gnuvince_ok
16:15stuarthallowayI have to keep reminding myself that my day job is writing prose, not code, at least for a few more weeks
16:15gnuvince_;)
16:16gnuvince_How's the book coming?
16:18kotarakgnuvince_: if you are interested: http://www.bitbucket.org/kotarak/clojurecheck/overview/, but Fact and the others are probably farther down the road...
16:18gnuvince_I like how Fact is looking
16:18gnuvince_I'll look at clojurecheck
16:19gnuvince_Although you have extra points for using Mercurial ;)
16:19kotarakhehe :)
16:20danlarkinI was sighing at bitbucket :)
16:21gnuvince_danlarkin: why?
16:24danlarkinMmmm
16:25durkai thought all of the #= were supposed to be gone from the repl?
16:25stuarthallowaygnuvince_: slow but steady. The Snake example will complete the "tour of libraries" chapter
16:25danlarkinit's a *lot* like github, but some of the ways it differs I do not like
16:25stuarthallowaywhich I have been thinking about renaming "Pandora's box" Having all of Java to choose from is a mixed bag
16:27gnuvince_danlarkin: so what if it's similar?
16:27gnuvince_stuarthalloway: I'll probably buy it when it comes out. I got enough stuff to read these days, I don't want to have a beta book as well ;)
16:31knaprIm noobish to a lot of CS-stuff. are there general parsing packages where you could define a few attributes to a parser and then it would construct one for you?
16:33hiredmandanlarkin just pointed out http://github.com/joshua-choi/fnparse/tree/master
16:33zakwilsonknapr: the short answer is yes.
16:36Chouserthat looks nice
16:36Chousukeclojurebot: parser?
16:36clojurebotPardon?
16:36Chousukeclojurebot: parser is http://github.com/joshua-choi/fnparse/tree/master
16:36clojurebotOk.
16:36durkathat makes sense...
16:36durkathe major version of class files in java 1.5 is 49
16:42kotarakclojurebot: #()
16:42clojurebot#() is not a replacement for fn
16:43hiredmanclojurebot: monads?
16:43clojurebotI don't understand.
16:43hiredmanclojurebot: monad?
16:43clojurebotPardon?
16:43hiredmanclojurebot: monads is http://www.bolour.com/papers/monads-through-pictures.html
16:43clojurebotOk.
16:43RSchulzNo one does.
16:44RSchulz(Understand monads, that is)
16:44technomancykotarak: it's not a replacement for fn just because it has the implied parens?
16:45kotarakyes and because the doc says so.
16:45danlarkintechnomancy: it's not a replacement because it has a subset of the functionality
16:45kotarakand it can't be nested.
16:45ChousukeRSchulz: After much meditation I finally feel like I understand them enough to see why they're useful.
16:45RSchulzCongratulations!
16:45Chousukemany of the details still escape me though.
16:45RSchulzI'm still working on it.
16:47technomancyI always felt like lambdas in other lisps were just a bit too verbose after being spoiled by Ruby's {} block syntax, but clojure's #() is even more succinct
16:48Chousukearc has pretty nice shorthand too
16:48Chousukethat is, []
16:48Chousukewith _ for the arg IIRC :/
16:49Chousuke#() is just as nice though. saves the brackets for something even more useful :)
16:56zakwilsonThe Clojure version also allows for multiple args - Arc's bracket syntax does not.
16:58Chousukezakwilson: IIRC it was expanded in anarki to support multiple args though
17:01zakwilsonChousuke: that may be.
17:01zakwilsonI really wanted to like Arc, and I didn't want to like Clojure.
17:02ChouserI wanted to like Arc too.
17:02hiredmanclojurebot: arc?
17:02clojurebotHuh?
17:02Chouserexactly
17:03hiredmanclojurebot: Paul Graham?
17:03clojurebotPaul Graham is the creator of the other new lisp
17:04zakwilsonEven if it had taken off like Clojure did, I don't like the feel of it as much.
17:04ehirdew, arc
17:09technomancyI think enough time has passed that "heh, arc" is an appropriate response
17:09technomancyor "heh; remember arc?"
17:10ehirdarc is now an adjective
17:10ehird"Clojure is totally unarc."
17:18pjb3So I was at a haskell meeting yesterday, saw something that was pretty cool, so I'm going to discuss it in here :)
17:18pjb3In #haskell, and in the other room we were in, #novalang, they have a lambdabot
17:18knaprthe whole idea of a 100-year language seems very self-masturbating and somewhat ridiculous
17:19knaprclojure wins heavily on being awesome now
17:19knaprbest language + best platform
17:19pjb3lambdabot is pretty cool, it does a bunch of stuff, but the best is that it can eval haskell expressions
17:19hiredman,(println "lambdabot envy")
17:19clojurebotnil
17:19clojurebotlambdabot envy
17:19hiredmanhmmmm
17:19Raynes#Scala has a lambdabot.
17:19pjb3clojurebot: You can eval expressions?
17:19clojurebotNo entiendo
17:19pjb3,(+ 2 3)
17:19clojurebot5
17:20hiredmanlambdabot is in #freebsd too for some reason
17:20pjb3Hey!
17:20pjb3So, ok, I'll be the asshole, how do you deal with this:
17:20gnuvincepjb3: some might consider that a feature of lambdabot: access to IO is completely restricted
17:20pjb3,(System/exit 0)
17:20clojurebotjava.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0) (NO_SOURCE_FILE:0)
17:20pjb3AH!
17:20pjb3very cool
17:21technomancyhiredman: did you have to do much to sandbox stuff like that, or are there built-in mechanisms for it?
17:21pjb3That was part of the discussion, saying how haskell is awesome because as long as the expression gets evaled outside of a monad, you know it can't do anything malicious
17:21hiredmanclojurebot: sandbox?
17:21clojurebotsandbox is http://calumleslie.blogspot.com/2008/06/simple-jvm-sandboxing.html
17:21hiredmanis the main thing
17:21technomancycool
17:22hiredmanand I use tree-seq to weed out certain expressions
17:22hiredman,(def a nil)
17:22clojurebotDENIED
17:23pjb3What happens if I do (iterate inc 1)
17:23hiredman,(interate inc 1)
17:23clojurebotjava.lang.Exception: Unable to resolve symbol: interate in this context (NO_SOURCE_FILE:0)
17:23hiredman,(iterate inc 1)
17:23hiredmanonly one way to find out
17:24pjb3Hey, you did it, not me :)
17:24pjb3clojurebot: still there?
17:24hiredman*sigh*
17:24clojurebotGabh mo leithsc�al?
17:24pjb3so don't ask clojurebot to eval an infinite lazy sequence
17:24pjb3clojurebot: you're back?
17:24clojurebotI don't understand.
17:24hiredmananyway, after ten seconds the thread the expression is eval'ed in gets killed
17:25pjb3ah
17:26gnuvince,(.toUpper "j�r�me")
17:26clojurebotjava.lang.IllegalArgumentException: No matching field found: toUpper for class java.lang.String (NO_SOURCE_FILE:0)
17:26gnuvince,(.toUpperCase "j�r�me")
17:26clojurebotJ�R�ME
17:26technomancynice i10n, clojurebot!
17:26technomancyor is it i18n?
17:27pjb3I think it;s i18n and l10n
17:27hiredmanit's unicode
17:27Chousukehmm
17:28gnuvincei18n is internationalization: translating an app
17:28Chousukewonder what toupper does to something that has no such operation defined.
17:28Chousukeprobably leaves it as is.
17:28gnuvinceChousuke: yes
17:28gnuvince,(.toUpperCase "33")
17:28clojurebot33
17:29Chousuke,(.toUpperCase "???")
17:29clojurebot???
17:29clojurebotExcuse me?
17:29Chousuke:D
17:29Chousukeit does not understand japanese.
17:29gnuvinceIs there such a thing as uppercase in japanese?
17:30Chousukenah.
17:30hiredmanwell, I was just mucking with the sandbox
17:30Chousukehiredman: does the sandbox kill things launched in subthreads now too?
17:30hiredmanand I broke something and fixed it, so you may have hit a broken window
17:30hiredmanChousuke: nope
17:30hiredman,(throwsome and exception)
17:30clojurebotjava.lang.Exception: Unable to resolve symbol: throwsome in this context
17:30Chousukeso I can still run an infinite loop in a new thread, right?
17:30gnuvince,(.toUpperCase "?
17:30clojurebotEval-in-box threw an exception:EOF while reading string
17:30gnuvince,(.toUpperCase "?")
17:30clojurebot?
17:31Chousukecool.
17:31hiredmanChousuke: yes (sshhh)
17:31danlarkinto late! secret's out! bahhah
17:31RSchulzSo why are we using this (fn ...) business when we could use a real lambda??
17:31hiredmanno ? key
17:32hiredman,(let [x ?] x)
17:32clojurebotjava.lang.Exception: Unable to resolve symbol: ? in this context
17:32hiredman,(let [x '?] x)
17:32clojurebot?
17:32Chousuke,(clojure.core/def ? fn)
17:32danlarkinRSchulz: the fortress channel is thataway ------->
17:32clojurebotjava.lang.Exception: No such var: clojure.core/def
17:32Chousukeoh. hmm
17:32technomancyRSchulz: I have Emacs render (fn as (?
17:32RSchulzEh?
17:32technomancyit's pretty nice
17:32technomancybut rendering javascript's "function" as "?" saves a lot more chars
17:32Chousuke,(eval '(def ? fn))
17:32clojurebotDENIED
17:33Chousuke,(eval '((symbol "def") ? fn))
17:33clojurebotDENIED
17:33Chousukegah
17:33RSchulzI sense the presence of Mac-o-philes...
17:33danlarkinI love "DENIED"
17:33RSchulzAnybody ever use MPW?
17:33ChouserRSchulz: in what way is fn not a "real lambda"?
17:33RSchulzI loved that thing.
17:33RSchulzI mean the letter. The glyph.
17:33ChousukeChouser: it's not ?
17:33technomancyChouser: I think he meant typographically
17:33Chouseroh! sorry. My IRC client renders all these as ?
17:33hiredmanChousuke: btw java.lang.Exception: Can't take value of a macro: #'clojure.core/fn (NO_SOURCE_FILE:1)
17:34ChouserI suppose I should try to fix that.
17:34knaprcant i just (alter a (fn [x] 100)) to set the ref a to 100? i get "no transaction running"
17:34Chouserknapr: wrap (dosync ...) around it
17:34RSchulzThen you can get the snowman glyph, too.
17:34knaprdosync
17:34knaprah
17:35Chousuke,(clojure.core/defmacro mydef [& rest] `(~(symbol "def") ~@rest))
17:35clojurebotnil
17:36Chousuke,(mydef x 1)
17:36clojurebot#'sandbox/x
17:36Chousukehooray.
17:36RSchulzSecurity Schmecurity.
17:37kotarakmaybe we need (ns #^{:read-only true} sandbox), now that we can have metadata with namespaces?
17:37Chousuke,(clojure.core/defmacro ? [& rest] `(~(symbol "clojure.core" "fn") ~@rest))
17:37clojurebotnil
17:37Chousukethere we go.
17:37hiredmanoooo
17:38technomancy,((? [x] (+ 2 x)) 8)
17:38clojurebot10
17:38technomancyclojurebot: high-five!
17:38hiredman:(
17:38clojurebotI don't understand.
17:40ChousukeI don't think defn and defmacro are that dangerous in the sandbox though.
17:40Chousukeor hmm
17:40Chousuke(mydef clojure.core/+ -)
17:40Chousuke,(mydef clojure.core/+ -)
17:40clojurebotjava.lang.Exception: Can't create defs outside of current ns
17:41Chousuke,(clojure.core/require 'hiredman.clojurebot-core)
17:41clojurebotPardon?
17:41Chousukeno access outside :(
17:43hiredmanChousuke: you can use def to make new names for things, and use that to get around checks for stuff that breaks Thread.stop
17:44hiredmanspecifically (catch ...)
17:44Chousukewell, yeah
17:44Chousukethe blacklist is rather ineffective.
17:44Chousukebut blacklists always are.
17:44Chousukeneed to figure out something different.
17:45Chousukewonder if it's possible to modify the clojure.core namespace so that those operations are nops
17:45gnuvinceMaybe we could have a data structure into which we could wrap IO stuff to prevent bad thigns from happening. We could call those "Gonads"
17:45hiredmanyou can do stuff like (binding [defn nil] stuff)
17:46hiredmanbut all the cool stuffs are special forms
17:46hiredmanso binding doesn't work
17:46Chousukeyeah
17:46Chousukeso it'd need reader hackery :/
17:47hiredmanor delving more into the jvm security stuff
17:47ChousukeI don't think it can help us anymore.
17:47Chousukethe default sandbox is a minimum permission sandbox :/
17:47hiredmanno
17:47Chousukeas far as I know anyway
17:48hiredmanthe default is the applet permission set
17:49knaprbah i must be stupid today, http://paste.pocoo.org/show/98383/, isnt there a very simple way to parse that? i included some of the file, it is a complete example
17:49knapri mean completely representative
17:49hiredmanclojurebot: sandbox
17:49clojurebotsandbox is http://calumleslie.blogspot.com/2008/06/simple-jvm-sandboxing.html
18:09hiredman,(java.security.AccessController/getContext)
18:09clojurebotjava.security.AccessControlContext@eed4d3
18:10hiredman,(bean (java.security.AccessController/getContext))
18:10clojurebot{:class java.security.AccessControlContext, :domainCombiner nil}
18:10hiredmanpfft
18:10hiredmanuseless
18:13knaprbah i must be stupid today, http://paste.pocoo.org/show/98383/, isnt there a very simple way to parse that? i included some of the file, it is a completely representative example. anyone could simplify it?
18:13Chouserwhat are you trying to produce? {1 (30878 ...), 10 (1952305 ..)} ?
18:18Chouserknapr: (second (reduce (fn [[k m] [_ n c]] (let [i (Integer. n), k (if c i k)] [k (if c (assoc m k []) (assoc m k (conj (m k) i)))])) [nil {}] (re-seq #"(\d+)(:)?\s+" x)))
18:21hiredmanhow evil is it to make an object whose hashCode method always returns 1?
18:22technomancyI'd rate that at a Mugabe-level evil.
18:23danlarkinthat's pretty high up!
18:23technomancyless than Hitler-level or Cthulu-level, but worse than anyone should have to deal with on a regular basis.
18:26hiredmanugh
18:30powr-tocHi all, does Stuart Halloway frequent here often? :-)
18:30durkayes
18:30durkanot at present apparently, but his username is surprisingly stuarthalloway
18:32powr-tocdurka: ok... was just wondering if he was in... A clojure example on his blog doesn't appear to work with the latest version... I've got a trivial fix for him, but his blog comments are closed.
18:35knaprclojurebot: is_rhickey_a_minor_god?
18:35clojurebotExcuse me?
18:35knaprclojurebot: is_rhickey_is_a_minor_god? is yes
18:35clojurebotIk begrijp
18:35knaprclojurebot: is_rhickey_a_minor_god?
18:35clojurebotNo entiendo
18:36knaprwhy doesnt that work?
18:36durkaclojurebot: rhickey?
18:36clojurebothe works hard so you don't have to
18:36durkaclojurebot: is_rhickey_a_minor_god is yes
18:36clojurebotIk begrijp
18:37durkaclojurebot: is_rhickey_a_minor_god?
18:37clojurebotis_rhickey_a_minor_god is yes
18:38dreish,'#=(eval (def x-ploit "myvalueforx"))
18:38billc1Is yes
18:38dreish,#=(eval 'x)
18:39dreishHmm. I wonder how they prevent that.
18:39dreish,(+ 1 2)
18:39clojurebot3
18:39hiredmanclojurebot: where are you?
18:39clojurebothttp://github.com/hiredman/clojurebot/tree/master
18:39dreishAh, you're here.
18:40dreishSo, did you think of that one already, or did I screw something up?
18:40hiredman,(identity #=(eval 'x))
18:40clojurebot1
18:40dreishI read the code earlier today and couldn't see anything ...
18:40hiredman,(identity #=(eval x))
18:40clojurebotEval-in-box threw an exception:java.lang.Exception: Unable to resolve symbol: x in this context
18:40hiredmandreish: magic I guess
18:41hiredmanit throws away anything that does not start with a (
18:41dreishOh, duh.
18:41hiredmanwhich I explicit coded in, then removed, but it still does it for some reason
18:41dreish,(identity #=(eval (def x-test "test2")))
18:41clojurebot#'clojure.core/x-test
18:41dreishHmm.
18:41hiredman:(
18:41dreishSo it does have that problem.
18:41hiredmanyeah
18:41dreishI think the fix is easy, though: just scan the string for "#="
18:42dreishNot much else you can do, unless you want to implement a special reader.
18:42hiredmanI really wish I could make sense of the jvm security stuff
18:48dreishIt might be worth having a LispReader.readWithoutEval().
18:49dreish,(identity #=(eval (def plea-to-rhickey "Can we have a LispReader.readWithoutEval()?")))
18:49clojurebot#'clojure.core/plea-to-rhickey
18:50rhickeydreish: this for security?
18:50dreishYeah. Is it a lost cause?
18:50rhickeynot at all - planned
18:50rhickeynecessary
18:50dreishAwesome, thanks.
18:50rhickeywill be some sort of flag
18:50dreishRight.
18:51danlarkinoh that will open up a lot of neat possibilities
18:52rhickeydreish: might as well call it *read-eval* a la CL, want to make an enhancement request in the issue system?
18:52rhickeyhttp://code.google.com/p/clojure/issues/list
18:52dreishrhickey: Okay, but it'll mean learning two things in one day.
18:52knaprhow an for what do I use with-open?
18:53hiredmanrhickey: I dunno how plausable this would be, because catch is special, but it would be nice if I could thread local bind catch to nil somehow
18:53hiredmanknapr: anything with a .close method
18:54hiredman(with-open [file (java.io.FileWriter "foo")] (.write file "bar"))
18:54knapri see now, it worked
19:00dreishWould *read-eval* be binding-able?
19:01dreishI guess it would have to be.
19:16ole3hello
19:16ole3can i ask some questions about packages
19:16ole3ok, i simply ask
19:17rhickeydreish: yes, that's how it would work - defaults to true
19:17ole3how do i define a package, or where can i get info about how to do it
19:17Chousukeclojurebot: namespace?
19:17clojurebotHuh?
19:17Chousukehm
19:18Chousukeole3: anyway: you need to define a namespace, using the (ns) macro
19:18dreishclojure.contrib has several examples.
19:18ole3ok, i look it up
19:18Chousukeole3: the name of a namespace must match the layout of files in a certain way similar to java.
19:19Chousukeexamples are best I suppose. :)
19:19ole3thank you, i found the ns macro
19:20ole3i got no idea about the java files layout
19:23Chousukeole3: well, if you have ~/mycode/ in your classpath, and want a namespace net.ole.myprog, the ns declaration must be in the file ~/mycode/net/ole/myprog.clj
19:23ole3Chousuke: that means i have a directory structure like /src/main/resources etc. ?
19:23powr-tocole3: I think Chousuke is referring to how in Java classes are organised into packages e.g. foo.bar.BazClass and tend to be stored in a matching directory tree e.g. /foo/bar/BazClass.(java|class)
19:24ole3ok, thank you
19:25technomancymy co-worker jokes about how he gets paid by the directory for writing Java
19:25Chousukeole3: there's one catch with the naming though: if you have dashes ("-") in the namespace name, the corresponding file must have an underscore, due to a java limitation :/
19:25waltersi wonder if that one is fixed in jdk7
19:25technomancyChousuke: that's weird; I haven't run into that problem
19:25waltersjrose did a blog about symbolic freedom
19:26technomancyI have a test-models.clj file that works fine
19:26technomancyoh... nm; the namespace doesn't match up for that and I load it only via slime
19:27ole3ok, i have a file named project.clj, which includes a ns definition that says (:require foo bar)
19:28waltershttp://blogs.sun.com/jrose/entry/symbolic_freedom_in_the_vm
19:28ole3means that that i need to have a dir named foo with a file named bar.clj ?
19:28hiredman(doc require)
19:28clojurebotLoads libs, skipping any that are already loaded. Each argument is either a libspec that identifies a lib, a prefix list that identifies multiple libs whose names share a common prefix, or a flag that modifies how all the identified libs are loaded. Use :require in the ns macro in preference to calling this directly. Libs A 'lib' is a named set of resources in classpath whose contents define a library of
19:29hiredmanole3: generally . is used as a directory seperator
19:30hiredmanI think (:require foo bar) would require foo.clj and bar.clj, but that would not work because namespaces need at least two segments
19:30hiredmanso (:require foo.bar foo.baz)
19:31hiredmanwhich would need foo/bar.clj and foo/baz.clj to be in the classpath
19:31ole3ok, so namespace = path + filename
19:31ole3thank you
19:31ole3i will try
19:33ole3ah, i find the doc
19:34ole3last question: is there a way to perform an operation after a lib has been loaded?
19:34blbrowndoes anyone have tips for this question. http://groups.google.com/group/clojure/browse_thread/thread/88d7f7b706ebf62f?hl=en
19:34ole3like cl asdf:oos :after?
19:37ole3hiredman: thanks for your help, sometimes i can't thing straight
19:37ole3good night
19:44technomancybut I guess html generation is pretty much the same in any lisp. =)
19:44technomancyjust used to some really ugly stuff in Ruby
19:48Nafaitechnomancy: Is it basically just some sexp representation of the html?
19:48technomancyyeah, in vectors
19:48NafaiCool
19:48technomancyat the bottom: http://github.com/weavejester/compojure/tree/master
19:49NafaiNice
19:56Chouserblbrown: It'll be a lot of work to allow a config.clj to set some things and not others if you're trying to block malicious intent.
19:56Chouserbut if you want to have it default to 'def'ing vars in a particular namespace (like my-app.config), that shouldn't be too hard.
19:57blbrownChouser, that is goal. I don't like java properties files, I wanted something a little bit more customizable
19:59Chouser(binding [*ns* (create-ns 'my-app.config)] (load-file "/tmp/config.clj"))
20:00amageehey if i have a list, say '(\a \b \c), how can i convert it to a string "abc"?
20:00ChousukeI think (str yourlist) should do
20:01amageeno that gives "(\\a \\b \\c)"
20:01Chousuke,(apply str '(\a \b \c))
20:01clojurebotabc
20:01Chousukeright, apply to the rescue
20:01amageeah cool
20:02amageehow come that is different?
20:02Chouser,(str \a \b \c)
20:02clojurebotabc
20:02Chousukeapply expands the seq(s) to be the arglist of the function
20:02amageeah i see
20:02amageethanks
20:03ole3is there an argument limit to apply?
20:03ChousukeI don't know.
20:03Chouserole3: no
20:03ole3wow
20:03Chouserinfinite seqs are ok
20:04Chousuke... how does that work?
20:04ole3infinite ...?
20:04Chousukeis the function required to treat its argument as infinite?
20:04Chousukepossibly infinite*
20:04ChousukeI think I might be asking stupid questions.
20:05Chouser,(apply (fn [& args] (take 3 args)) 1 (iterate inc 10))
20:05clojurebot(1 10 11)
20:05ole3,(* 123 123)
20:05clojurebot15129
20:05ole3ah
20:05Chousukeole3: infinite seqs like (iterate inc 1)
20:06ChouserChousuke: sorta -- you'd have to have a & rest part to take advantage of it.
20:06Chouserkinda hard to provide an infinite number of named args. :-)
20:06Chousukeheh
20:06ole3so i do not evaluate the whole seq
20:06Chousukewasn't there some limit to named args though?
20:06Chousuke20 or something.
20:07ole3in cl, yes, in bash, yes, in clojure, who knows
20:07Chousukemore than enough in any case
20:07Chousukeif you have a function that takes even 10 args, it's getting too big :P
20:07Chousuke10 named args that is.
20:08ole3and & body args?
20:08ole3do they not count as named?
20:08ChousukeI think so.
20:09Chousukedoesn't really matter to me.
20:09Chouserjava.lang.Exception: Can't specify more than 20 params
20:09Chousuke20 was the number of overloads rhickey bothered to write I guess :)
20:10ole3:)
20:14ole3i did start to write a little toy webserver to learn clojure and java, if someone is interested to join, please contact me oruppert@googlemail.com, project page http://code.google.com/p/clojure-web/, thanks
20:15ole3good night
20:23knaprwhat time-complexity does "select grade from reviews where movieid = 12 and customerid = 100" have?
20:23knaprif the primary key is over customerid and movieid
20:24Chousukerather fast.
20:24Chousukethe exact complexity depends on the DBMS I guess.
20:26danlarkinknapr: what does time-complexity mean?
20:27Chousukein any case, a query like that is not something you should worry about, on any system :)
20:32knapryes it is already slow for 500 movies and 300K users
20:32knaprand in the end i have 17770 movies and 500K users...
20:40vogelrnselect should be linear
20:41vogelrngiven a large enough N, however, that doesn't mean it will be fast :P
20:41Chousukeyou're using something that doesn't automatically index by primary keys? :/
20:58falconairWhen I instantiate an object from a third party jar like such: (SGRectangle.) (or (new SGRectangle)), I get the following result:
20:58falconair#<SGRectangle null com.sun.scenario.scenegraph.SGRectangle@b76fa>
20:59falconairnote the "null" ... when I try to use this object, I get a null pointer error...object is clearly found by clojre, howcome instantiation returns null?
20:59falconairIn java I can instantiate it as "new SGRectangle()" and it works fine
21:00MarkVolkmannWhat does this error message mean?
21:00MarkVolkmannjava.lang.IllegalStateException: Var my-function-name is unbound
21:01ChousukeMarkVolkmann: you have no function named my-function-name :/
21:01ChousukeMarkVolkmann: that is, someplace where you're trying to use it.
21:02MarkVolkmannI do have a function with that name before any calls to it. However, it's a function that takes either 1 or 4 parameters.
21:02MarkVolkmannThe 1 parameter part calls the part that takes 4.
21:02MarkVolkmannI verified that all calls to it pass either 1 or 4 arguments.
21:03arbschtcan you paste a snippet somewhere?
21:05ChousukeMarkVolkmann: has the defn actually been evaled?
21:05ChousukeMarkVolkmann: for example, if you're doing this in emacs or something.
21:05MarkVolkmannI'm running it as a script from a Terminal window.
21:06MarkVolkmannI'll try to simplify things to isolate the problem. Thanks for the tips!
21:08dreish,(time (count (range 1000000)))
21:08clojurebot1000000
21:08clojurebot"Elapsed time: 156.434 msecs"
21:08dreish,(time (count (range 999999 -1 -1)))
21:08clojurebot1000000
21:08clojurebot"Elapsed time: 6667.267 msecs"
21:08dreishIsn't that odd?
21:09Chousukesomewhat.
21:09dreishI'd take longer to count backwards too, but I'm not a computer.
21:10dreishOh, I see. With 1 arg or 2, it uses a clojure.lang.Range, and with 3 args it calls iterate, which uses lazy-cons.
21:10falconairany idea why my instantiation is returning a null?
21:13arohnerdreish: so then does (time (count (range 1 1000000 1))) take the same amount of time?
21:13dreishSame as the -1, yes.
21:14Chousukesounds like Range should be extended to support a step /:
21:14dreishMaybe someday.
21:15Chousukedid you already post an issue?
21:15dreishI think it might also be nice to have ASeq implement an nthRest() method, to speed up nth on seqs on randomly-accessible data structures.
21:16dreishI posted one issue today, yes. :)
21:16Chousukesounds like another thing worthy of an issue
21:16dreishI don't really need it myself.
21:17rhickeyissues is not a wish list
21:17Chousukethey're easy to discard, but as long as you post them there's a single place for people to look for ideas and such :)
21:17Chousukehm
21:17Chousukethen there should be a wish list :/
21:17dreishWhere's the wish list?
21:17rhickeythere's a user wiki
21:25yangsx hi, do you agree it's a but that (merge-with '({:a 1, :b 2})) returns nil instead of the single map?
21:25yangsxbug
21:34dreishNo, because the first arg is supposed to be a combining function.
21:35falconair...so...any one have a clue what this message means: #<SGRectangle null com.sun.scenario.scenegraph.SGRectangle@b76fa> ? it seems to find the object, but null is returned
21:40Chouseryou're not getting a null, you're getting a SGRectangle instance with id (or at memory location?) b76fa
21:40ChouserThe 'null' is most like a datamember, but I'm not quite sure yet.
21:40Chousermost likely
21:43falconairhm...i guess if it actuall was null, clojure would call it "nil" correct?
21:51yangsxdreish: I know the first arg is to be a function, but (apply merge-with list-of-maps) works exactly as I'd expect: add up the values of same keys in all maps, like magic
21:51yangsxand a map is a function
21:52Chouserfalconair: yes
21:53yangsxso I guess if the test (when (some identity maps) ...) can be changed to just return the first arg if it's a map
21:53yangsxif the test fails
21:53Chouser,(apply merge-with '({:a 1} {:b 2}))
21:54clojurebot{:b 2}
21:54Chouserperhaps you want just 'merge'?
21:54cmvkksomething interesting: when I run 'count' on a large enough seq it will generate a StackOverflowError...is this known/normal?
21:55Chousercmvkk: what kind of seq were you trying it on?
21:56cmvkkhard to say...when i print it it looks like a list of maps but it's supposed to be a vector?
21:56Chouserfalconair: try running (.toString foo) where foo is your SGRectangle object.
21:56cmvkkif you run cons on a vector will the result still be a vector?
21:57Chousercmvkk: the function(s) that are producing the seq may be overflowing the stack.
21:57Chousercmvkk: no
21:57Chousercmvkk: cons operates on seqs, so you'll get back a seq
21:57cmvkkit's a list then. anyway i can print the seq out (although it goes beyond my scroll capabilities)
21:57yangsxChouser: you're right, I didn't noticed merge-with discard key-value pairs in the first map, but work correctly with the rest maps
21:57cmvkkbut trying to (count) it gives a stack overflow.
21:58Chouseryangsx: it doesn't discard the first arg, it uses it to resolve conflicts in keys of the following maps.
21:58yangsx,(apply merge-with '({:a 1} {:b 2} {:a 2 :b1}))
21:58clojurebotEval-in-box threw an exception:No value supplied for key: :b1
21:58Chousercmvkk: when you print it, it prints to the end of the seq?
21:58cmvkkif i run (take ## foo) where ## is some number much larger than the size of the seq, well, that I can count.
21:58cmvkkyes, it prints to the end of the seq.
21:58yangsx,(apply merge-with '({:a 1} {:b 2} {:a 2 :b 1}))
21:58clojurebot{:a 2, :b 1}
22:00Chousercmvkk: can you paste the code that errors out?
22:00Chouserlisppaste8: url
22:00lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
22:00cmvkknot feasable with the current code, which is 400 lines long or so and requires jumping through some hoops...let me see if i can't come up with a small test case first.
22:01Chousercmvkk: great
22:02Chousercmvkk: It's not more than a million items?
22:02Chouser,(count (map identity (range 1000000)))
22:03clojurebot1000000
22:03cmvkkthe problem with using range is that it's a lazy seq, right?
22:03cmvkkmy example case is one line long, can i just write it in here?
22:03Chousercmvkk: if long is < 256 or so chars
22:04cmvkk(count (loop [c 0 x [0]] (if (< c 4601) (recur (inc c) (cons 0 x)) x)))
22:04Chousercmvkk: laziness isn't the issue. range by itself knows its length and would return instantly. by running it through 'map' it loses knowledge of its length, and 'count' has to walk it.
22:04cmvkkhmm, okay.
22:05cmvkkanyway, my code above only generates a list that's 4601 elements long...
22:05cmvkkbut it errors for me... it might take a larger number for someone else?
22:05cmvkknote that if you do (count (take 10000 (loop ...))) that works
22:06Chousercmvkk: I'm reproducting the error here. interesting.
22:06falconairChouser: running toString returns "null com.sun.scenario.scenegraph.SGRectangle@c26ede" ... so I think I'm not getting a null object back, the prob is somewhere else
22:06falconairthanks!
22:07Chouserfalconair: you're welcome.
22:07Chousercmvkk: Cons.count() is recursive
22:09Chouserthat's the problem.
22:09cmvkki see.
22:12ChouserI'm not sure how best to solve it.
22:13cmvkkother than changing how count works?
22:13cmvkkas far as a workaround goes, this doesn't affect anything i'm doing anyway, i just thought it was interesting
22:14Chousercmvkk: it is interesting, thanks.
22:16Chouseroh! Range objects do not know their length
22:19Chouserbut PersistentList objects do.
22:22gnuvinceRanges don't know their lengths?
22:22gnuvinceCan't you call count on them?
22:23Chouser(count (range n)) is O(n) not O(1)
22:23gnuvinceah
22:23gnuvincethat's weird...
22:23cmvkkyeah, that's definitely the case
22:23Chouserheh, yeah.
22:23cmvkkbut it won't overflow the stack either
22:23Chouserbut this works fine: (count (reduce #(cons %2 %) '(0) (range 4601)))
22:23gnuvinceIt seems it would be a pretty simple arithmetic thing to find it with the start, end and step
22:24cmvkkwhat, what's the difference between that and my example?
22:24Chouser'(0) vs [0]
22:25Chouserin the former, it's cons'ing onto a PersistentList, creating new PersistentLists for which 'count' is O(1)
22:26Chouserin the latter, it's cons'ing on (seq [0]), so you're getting back Cons objects, for which 'count' is O(n) and blows the stack
22:27cmvkkI see. on a semi-related note, what i was basically doing was creating stack behavior, and using 'cons', 'first' and 'rest' to accomplish this, starting with an empty vector []. is it better to do it some other way?
22:28Chousercmvkk: start with an empty list ()
22:28cmvkkokay
22:39Chouser(count (cons :a big-vector)) ; nearly constant time
22:40ChouserCons.count() being recursive allows it to go from linear (for counting the Cons chain) to constant time for the vector seq.
22:43cmvkkbut the price is that you have to handle conses in a different way than for a list?
22:45Chouserwell, each class can provide it's own class() method
22:45Chousercount() I mean
22:46ChouserCons delegates to the "rest" object, whatever it is.
22:47arohnerI have a CA. how do I get commit access to contrib?
22:47arohner(or do I?)
22:48Chouserarohner: I guess you ask rhickey_ -- he's the only one who can grant commit privs, I think.
22:51arohnerChouser: thanks
22:59jackywhat is the best source to see some idiomatic clojure code? Most of the real life code that I have seen seems to be rehash of java in clojure
23:01Chouserjacky: there's a book on the way -- the examples are available for free
23:01jackychouser: do you mean stuart H's book?
23:01Chouserjacky: clojure-contrib is good, and the projecteuler wiki isn't bad.
23:01Chouserjacky: yes
23:02jackyprojecteuler has clojure code?
23:02Chouserno, there's a wiki of clojure solutions to their problems.
23:02Chouserclojurebot: project euloer
23:02clojurebotexcusez-moi
23:02Chouserclojurebot: project euler
23:02clojurebotproject euler is http://ProjectEuler.net
23:02Chouserclojurebot: projecteuler
23:02clojurebotPardon?
23:02Chouserhmph.
23:03Chouserjacky: http://clojure-euler.wikispaces.com/
23:03jackyCool. The best one that I have seen so far is the context free art thingy
23:05jackychouser: clojure-euler looks cool. Thanks.
23:06Chouserjacky: If you have the time, I'd recommend trying to solve them yourself, then checking your work against the wiki
23:06Chouserit's more fun that way 'round.
23:07jackysure, that is what I plan to do.. I basically want to know the best way to express ideas in clojure
23:08Chousersure. I have no better advice than practice, and projecteuler is good for that
23:17cmvkkis there a way to use 'apply' with a static class method?
23:17cmvkki.e. (apply java.lang.Math/hypot some-list)
23:18cmvkkoh wait, i guess i can just wrap it in an fn
23:18Chousernot directly.
23:18Chouserright
23:18Chouser(apply #(Math/hypot %1 %2) some-list)
23:21cmvkkhow come you can't use numbers to index into a list?
23:22cmvkki.e. (get '(1 2) 0)
23:22cmvkki'm full of questions this evening
23:22Chouserbecause 'get' promises O(1), and lists can't deliver
23:22cmvkkI see.
23:22Chouseryou can use 'nth'
23:22cmvkkaha.
23:29Chousercmvkk: http://groups.google.com/group/clojure/msg/a24abca88ae1af1e
23:30cmvkkooh, neat.
23:30Chouser:-)
23:36Chouserand thus I've avoided for another evening doing what I ought to do, by doing Clojure instead.
23:36Chouserg'night, all.
23:37cmvkkgoodnight!
23:44arohnerdo ref validators take the ref, or the deref'd new state?
23:45cmvkki believe they take the state.
23:45cmvkk"will be passed the intended new state on any state change" from the api
23:46arohnerthat's what I thought, but it's blowing up for me, saying 'invalid state', and I can't figure out why
23:46arohnerpassing the @ref to the validator fn manually works fine
23:48arohnernm, returning nil is not acceptable