#clojure logs

2009-03-29

00:33dreish10^100 == 2^100 * 5^100. 2^100 is obviously divisible by 2^32. So (int (.pow 10M 100)) is 0.
01:36slashus2Does the writer function in duck_streams allow for appending?
01:38slashus2When i wrote my with-out-file macro I used FileWriter so that I could use the append functionality.
01:38slashus2The new with-out-writer doesn't seem to support appending.
03:19RaynesI think Clojure has ruined me. Everything I think about learning another language, something about Clojure makes me dread it. :|
03:21cmvkkthat's funny because, thanks to clojure being written in it, i've been learning java for the first time.
03:21cmvkkclojure has brought me closer to 'bad' languages.
03:21RaynesWhy would you learn a language just because another language is written in it. :|
03:22cmvkkfor clojure's sake, it's a boon to know java. for one thing, I can read the clojure source better which will make me better with clojure.
03:23cmvkkbut also, it means i can implement part of a clojure library in java if i want, extend clojure from java, etc.
03:23clojurebotit is too
03:24slashus2clojurebot: indeed
03:24clojurebotIt's greek to me.
03:24cmvkki'm currently thinking about writing a small 2D game engine in java, but in such a way that it's easy to extend from clojure.
03:24RaynesI want to learn Scala or Java.
03:25RaynesBut I'm worried if I learn Java, I'll become corrupted.
03:25cmvkkworried that you'll see everything in an object-oriented light, and start to add needless OO code to your clojure programs?
03:26slashus2Raynes: It just feels more rigid. Using a good IDE like netbeans helps.
03:26cmvkki personally think that knowing more languages can only make you a better programmer.
03:27RaynesI'm worried that I'll forget how great functional programming is. I'm worried that learning Clojure before learning an OO language will cause me to program horribly in Java.
03:27slashus2Righting things in the oo paradigm is sort of like a game. How can I model this problem into a complex, object oriented scheme?
03:27slashus2Writing rather
03:27slashus2need to go to sleep.
03:27cmvkkit's uh, really hard to not program OO in java. rather than code horribly in java, you'll just end up being frustrated.
03:28cmvkkyou'll want to program in a functional style, but then it turns out that you can't.
06:11maaclI get "java.lang.RuntimeException: You need to use "Import Library" to add processing.core.PGraphicsJava2D to your sketch." when I try to run the clj-processing example, even if I and PGraphicsJava2D to the imports ((:import (processing.core PApplet PGraphicsJava2D)) - any ideas anyone ?
06:18Lau_of_DKTop of the morning gents
06:18hiredmanthe very top indeed
06:18maaclLau_of_DK: hey
06:22maaclLau_of_DK: have you used clj-processing ?
06:22Lau_of_DKNo sir
06:37AWizzArdWhat is clj-processing good for?
06:50Lau_of_DKAnybody here found some interesting ways to couple servlets and ajax ?
07:00Lau_of_DKIm thinking ala Symbolic Web
07:08maaclLau_of_DK: can't say that I have
07:54antifuchsoh wow, clj-processing. neat!
07:59maaclantifuchs: yeah, except I can't get the examples to work
08:02antifuchshow so? not behaving properly or are you getting errors?
08:02maaclantifuchs: I get "java.lang.RuntimeException: You need to use "Import Library" to add processing.core.PGraphicsJava2D to your sketch." when I try to run the clj-processing example, even if I and PGraphicsJava2D to the imports ((:import (processing.core PApplet PGraphicsJava2D))
08:04antifuchshmm, it's a couple months old, maybe either processing changed?
08:04antifuchss/either//
08:08maaclantifuchs: can you get it to work ?
08:08antifuchshaven't tried yet... I promised myself I would not hack on stuff today (:
08:08antifuchstomorrow, though
08:09maaclantifuchs: if you figure it out I would love to hear from you
08:09antifuchssure thing
08:10AWizzArdmaacl: when you are in a repl and do (import '(processing.core PGraphicsJava2D)) and then type PGraphisJava2D, what does happen?
08:11AWizzArdIf that beast was imported correctly then PGraphisJava2D should eval to the class processing.core.PGraphisJava2D
08:12maaclAWizzArd: hang on
08:15maaclAWizzArd: yeah it does eval to PGraphicsJava2D
08:19AWizzArdok, that sounds good, it means that the import did work
08:20maaclAWizzArd: yeah but I can't figure out what to do to fix it
08:26AWizzArdis Processing some kind of graphics program?
08:27maaclAw
08:27maaclAWizzArd: yeah, it is a data visualization tool
08:28AWizzArdok
08:31noidiis it possible to use System/loadLibrary in clojure to load dynamic libraries?
08:32noidii tried to port a simple "JNI hello world" from java to clojure but the loadLibrary doesn't seem to be working
08:33noidii guess it has something to do with clojure using multiple classloaders, whatever they are :P
09:33hjlee,(clojure.contrib.math/exact-integer-sqrt 1000000000000)
09:33clojurebotjava.lang.ClassNotFoundException: clojure.contrib.math
11:16mozinatorFor those who might be interrested, I managed to make music with clojure + jmusic: http://mozinator.eu/?p=16
11:17cmvkkmozinator: very cool. i'm working on a similar project: http://github.com/cmvkk/lumenc/tree/master
11:17mozinatorcmvkk, cool !
11:17mozinatorcmvkk, going to check it ou
11:17mozinatort
11:18duck1123too bad I'm not a musician
11:19duck1123years ago I learn the piece of music I was supposed to be practicing by programming hypercard to play it when i clicked a button
11:21AWizzArdmozinator: does jmusic talk to the hardware midi, or does it support very high quality software instruments?
11:23mozinatorAWizzArd, don't know really, I just bumped into it via http://www.fatvat.co.uk/2009/02/jmusic-and-clojure.html and thought it was cool to let it make music live, instead of writing it to a midi file first
11:25AWizzArdyes, sounds good
11:27mozinatorthe thing I would like to accomplish is to make music on the fly
11:27mozinatora little bit like this: http://www.infoq.com/presentations/archaeopteryx-bowkett
11:27AWizzArdsounds also interesting for me.. maybe I could combine this with my GP engine
11:28mozinatorAWizzArd, GP engine ?
11:28AWizzArdGenetic Programming
11:29mozinatorAWizzArd, sounds like a cool idea, go for it :)
11:29mozinatorI got to go, visiters
11:29AWizzArdl8rs
13:29MikeSethAM HOOKED!
15:03johanmI have a question regarding swank-clojure, if anyone is up for it: if I eval a (ns ...) expression with C-M-x, my *slime-repl clojure* does not switch to that namespace. I can switch to it at the repl (and the imports have been picked up, etc.), but consequent evals from my source file is evaluated for the default "user" namespace (meaning I can't use my imports). Am I doing it wrong?
15:08dysingerhow do I get auto-indentation in the command line repl like I can for emacs? Is there any .inputrc trickery to be had?
15:46AWizzArdjohanm: if you eval a (ns ..) in a code file, then in that file you will be in that namespace from that moment on. All functions that you write into that same file and that you eval there, will become available in the repl under that namespace.
15:59johanmAWizzArd: yeah, but when I eval the (ns ...) i emacs the slime repl does not change to the specified namespace (as indicated by the prompt), like it does when you're running clojure-mode without slime, for example (I'm using slime, swank-clojure and clojure-mode from cvs/git)
16:04Lau_of_DKThis is border-line off topic, but since Im driving with compojure, I figured you'll cut me some slack: I have an menu which dynamically expands when you hover your mouse on it, problem is, it pushes the entire rest of the page down when expanding - how do I avoid this?
16:09Lau_of_DKgot it, z-index + absolute positioning
16:09Lau_of_DKthanks for nothing guys - whats keeping everyone so busy?
16:10chessguyand i know nothing about clojure anyway. that's why i'm here :)
16:11Lau_of_DKWelcome to :)
16:16chessguywelcome to smile? is that what clojure is all about?
16:18astorI've been away from clojure for a few months, and after updating to the latest lazy-seq stuff, I'm faced with the following issue. (def *foo* (some-lazy-func)) gives java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IFn
16:19Lau_of_DKtry wrapping your lazy-func in (seq) or (cons ...)
16:19Lau_of_DKchessguy, "Welcome to" was a sentense in itself, the smile was my warm welcome
16:19astor(def *foo* (seq (some-lazy-func)) gives the same problem
16:19Lau_of_DKClojure is about functional concurrent lisping
16:19Lau_of_DKastor, go to the pastebin
16:19chessguyis there a bot in here that interprets snippets?
16:20cmvkk,(+ 2 3)
16:20clojurebot5
16:20chessguynice
16:20Lau_of_DK,(doc cons)
16:20clojurebot"([x seq]); Returns a new seq where x is the first element and seq is the rest."
16:21chessguy,(list 1 2 3)
16:21clojurebot(1 2 3)
16:21chessguy,(car (list 1 2 3))
16:21clojurebotjava.lang.Exception: Unable to resolve symbol: car in this context
16:21Lau_of_DKcar.... :)
16:21chessguyjust checking :)
16:21Lau_of_DKYou got in here from last century ?
16:21chessguyhaha
16:21cmvkkyou know, i thought i would miss car and cdr.
16:21chessguybeen watching SICP :)
16:22Lau_of_DKI dont mis car and cdr, but I sometimes need cardrradrrdadrrr
16:22chessguy,(first (1 2 3))
16:22clojurebotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
16:22Lau_of_DKclojurebot: SICP ?
16:22clojurebotNo entiendo
16:22Lau_of_DKclojurebot: SICP ?
16:22clojurebotTitim gan �ir� ort.
16:22Lau_of_DKArgh
16:22qwert666is pattern matching available in clojure ? like in scala or haskell
16:22Lau_of_DKThere was a page with the SICP code ported to Clojure
16:22chessguy,(first '(1 2 3))
16:22clojurebot1
16:22chessguyah
16:22cmvkkqwert666, not quite
16:22chessguyso without the quote it was trying to apply 1 to the arguments 2 and 3?
16:23cmvkkmostly (i guess?) because there aren't types to match against
16:23hiredmanclojurebot: sicp?
16:23clojurebotsicp is http://web.mit.edu/alexmv/6.001/sicp.pdf
16:23hiredmanclojurebot: sicp?
16:23clojurebotsicp is http://www.codepoetics.com/wiki/index.php?title=Topics:SICP_in_other_languages:Clojure:Chapter_1
16:23qwert666cmvkk: so there is a chance that it will be implemented in the future ?
16:24cmvkkthere is arity overloading, but i don't think rhickey likes the pattern matching aspect
16:24cmvkkso probably not?
16:24cmvkkthere's destructuring too, which is kind of like that
16:24Lau_of_DKGuys - how do I center a div-tag which is positioned absolutely ?
16:24chessguyuh...wouldn't that be better to ask in #css or #html or something?
16:24cmvkkposition it absolutely in the center?
16:25Lau_of_DKI need something like 50%x100px
16:25cmvkkyes that is too complicated
16:25chessguy,(* (+ 2 (* 4 6)) (+ 3 5 7))
16:25clojurebot390
16:26hiredman(* 4 6)
16:26clojurebot*suffusion of yellow*
16:26chessguyhuh?
16:26cmvkkmath operations returning colors
16:27cmvkkthat's a little too cutting edge for me
16:27hiredmanhttp://www.thateden.co.uk/dirk/
16:27astorHow do I rewrite this idiom which I use everywhere in my code using lazy-seq? http://clojure.pastebin.com/m5e0facc7
16:28slashus2lol
16:28Lau_of_DKastor, replace lazy-cons with cons I think
16:28Lau_of_DKDoesnt look like anything out of the ordinary
16:29astormore like http://clojure.pastebin.com/m7354eb77.. forgot the lazy-cons recursion in the first example.
16:29astorlazy-seq does not allow recur
16:30cmvkkyour best bet is to put a lazy-seq, then use loop inside of the lazy seq
16:30hiredmanuh
16:30cmvkkor something
16:30astorso I need defn, then fn, then lazy-seq, then loop, then recur+cons?
16:30hiredmanI don't think that will work
16:30astorthat's mighty complex.
16:31hiredmanhmmm
16:31hiredmanyou don't need the fn
16:31cmvkkoh yeah.
16:32cmvkk(loop [[[f & r] s] s] ...) instead of the let and fn
16:32hiredmanusing lazy-seq typially looks like (defn f [x] (lazy-seq (cons (first x) (f (rest x)))))
16:33hiredmanthis lazy-seq looks like it just returns a laz-seq of even numbers is that correct?
16:33astorso I'd probably want something like (defn f [[f & r] x] (lazy-seq (cons f (loop ... (recur..) (f r)))))
16:34cmvkknot quite.
16:34hiredman(filter even? (iterate inc 0))
16:34cmvkk(defn f [s] (lazy-seq (loop [[[f & r] s] s] (when f ...))))
16:34hiredmanwill get you a lazy-seq of even numbers
16:34cmvkkor rather my-lazy-func instead of f there
16:34cmvkkthen use cons instead of lazy-cons. but yeah, hiredman's right, just use filter.
16:35hiredman,(take 10 (filter even? (iterate inc 0)))
16:35clojurebot(0 2 4 6 8 10 12 14 16 18)
16:35hiredman~def filter
16:36cmvkkit's not quite that simple though, there's some weird destructuring going on in the input there
16:36clojurebotit is too
16:37SethTisueclojurebot is getting sassy
16:37astormy example is simplified, in real-life f takes several parameters which makes filter inadequate.
16:38cmvkkhttp://clojure.pastebin.com/d321a3117 astor
16:38astorsometimes I use reduce, but that's ugly because the initial condition is physically separate in the code.
16:39astorcmvkk: thanks
16:39slashus2cmvkk: step isn't defined in that code.
16:40cmvkkit wasn't in the example code either...i don't think.
16:40hiredmangiven the similar structure of filter and your code I fard it hard to believe that you cannot just use filter
16:40AWizzArdOT: anybody here who speaks russian? I have a very easy question :)
16:40clojurebotfilter is not map
16:40hiredmanclojurebot: thanks!
16:40clojurebotGabh mo leithsc�al?
16:41hiredman~translate to ru one ping, one ping only
16:41clojurebot???? ????, ???? ?????? ????
16:42chessguyi'm thinking the symbolic differentiation pattern-matching thing from the video version of SICP would be a nice first project
16:43hiredmanchessguy: using zippers
16:43chessguyoooh
16:43chessguyis there a zipper module already?
16:43hiredmanyes
16:43hiredmanclojure.zip
16:43chessguythough...i don't know that a zipper is really necessary for that one
16:44chessguyrecursion should be fine
16:44hiredmancorrect
16:44hiredmanbut zippers are cool
16:44cmvkki don't know what zippers are...am i missing out on the next big thing?
16:44hiredmanhttp://clojure.org/other_libraries
16:44chessguycmvkk: zippers aren't really new
16:44cmvkkheh
16:44chessguyhttp://en.wikipedia.org/wiki/Zipper_(data_structure)
16:44hiredman,(require '[clojure.zip :as zip])
16:44clojurebotnil
16:45chessguyreading the huet paper is a good start
16:45cmvkkoh i've heard of this
16:45chessguythough i seem to remember the code in the paper being in haskell, or close to it
16:46astorhiredman: typically you have something like (defn foo [x] (let [state {} step (fn [state [[f & r] x] (when f (if (complex-expression f) (recur (update-state state) r) (lazy-cons f (step r)))))] (step x))
16:46hiredman,(zip/seq-zip '(1 ? 3) zip/down zip/right (zip/replace 2) zip/root)
16:46clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: zip$replace
16:46astorthere is probably a syntax error in there :-). the point is that there is additional state that is needed to figure out whether to recurse or not.
16:46hiredman,(-> '(1 ? 3) zip/seq-zip zip/down zip/right (zip/replace 2) zip/root)
16:46clojurebot(1 2 3)
16:46cmvkkyes in fact, you can't use filter for that scenario.
16:46clojurebotfilter is not map
16:47chessguyastor: are you saying a zipper is needed?
16:47cmvkkuh-oh, we're merging two conversations
16:47chessguyoh, whoops
16:47chessguyreferential opqueness for the loss
16:48hiredman,(pl inc $ inc $ inc $ 0)
16:48clojurebot3
16:48cmvkki was going to say, this is where something like 'lazy-loop' would come in handy, but you couldn't do it with that kind of structure either.
16:48cmvkkthe goal is to be able to recur a structure either with or without giving the next element.
16:49hiredman,(pl (?map (replicate 3 range $ 3) call � (?map inc)))
16:49clojurebot((1 2 3) (1 2 3) (1 2 3))
16:49chessguy,(replicate 3 range $ 3)
16:49clojurebotjava.lang.Exception: Unable to resolve symbol: $ in this context
16:50hiredmanpl is a macro that uses zippers
16:50chessguyah
16:50hiredman,(macroexpand '(pl range $ 3))
16:50clojurebot(do (range 3))
16:51hiredmanand it only exists in clojurebot
16:53Lau_of_DKI got the absolute positioning down :)
16:53Lau_of_DKMan - The more I work with jQuery, the more I realize how powerful a clojure-wrap could be
16:53chessguy,(do (range 3))
16:53clojurebot(0 1 2)
16:53slashus2hiredman: What does pl mean?
16:53chessguyclojure-wrap?
16:53clojurebotclojure is like life: you make trade-offs
16:53Lau_of_DKSo I'll make the most full-featured wrapper imaginable, and keep it all to myself
16:54Lau_of_DKThat'll teach you guys to ignore my questions :)
16:54chessguywhat is do?
16:54hiredmanslashus2: pointless
16:54Lau_of_DKdo is a utility for gnome, which helps you reach your apps faster
16:55chessguy,slap Lau_of_DK
16:55clojurebotjava.lang.Exception: Unable to resolve symbol: slap in this context
16:55chessguybah
16:55Lau_of_DKhaha
16:55Lau_of_DKhiredman, thats bad PR right there
16:55hiredman,(doc do)
16:55clojurebotjava.lang.Exception: Unable to resolve var: do in this context
16:55hiredmanbah
16:55hiredmando does things
16:55Lau_of_DK,(loop [] (recur))
16:55hiredman,(do 1 (+ 1 2))
16:55Lau_of_DK,(loop [] (recur))
16:55Lau_of_DK,(loop [] (recur))
16:55Lau_of_DK,(loop [] (recur))
16:55Lau_of_DK,(loop [] (recur))
16:55clojurebotExecution Timed Out
16:55clojurebot3
16:55Lau_of_DKMuhaha :)
16:55clojurebotExecution Timed Out
16:55hiredmanLau_of_DK: I will make clojurebot ignore you
16:55clojurebotExecution Timed Out
16:56chessguy,(do 2 (+ 1 2))
16:56Lau_of_DKFine - its your bot
16:56clojurebotExecution Timed Out
16:56hiredmanI'm just saying, chillax
16:56clojurebotExecution Timed Out
16:56clojurebot3
16:56hiredmando evals the forms and returns the last one
16:56chessguyoh
16:56chessguy,(do (+ 1 2) 2)
16:56clojurebot2
16:57hiredman,(do (println 1) 2)
16:57clojurebot2
16:57chessguyso it's intended for side effects
16:57clojurebot1
16:57clojurebotit is too
16:57hiredmanerm
16:57hiredmannot always
16:57hiredmanit is useful in macros
16:58hiredmanbecause macros can only return one form
16:58hiredmanso you wrap a bunch of forms in a do
16:58hiredmanlike I do with pl
16:58chessguyinteresting
17:01slashus2Do zippers make it easy to write tree data structures? (e.g. red-black, b-tree)
17:02chessguythey're more for traversing such structures
17:03qwert666have any of you seen any proj. in GSoC with Clojure ?
17:03qwert666GoogleSummerofCode *
17:03slashus2It seems like it would work with modifying a tree structure too.
17:09hiredmansomeone should do a soc on the function interface and the compiler
17:09hiredmanas in, propagating type information
17:22chessguyso if i want to start playing with some basic existing lisp code, is the defn vs define/lambda stuff going to be the only real difference?
17:22chessguy(at first)
17:22duncanmchessguy: there are other syntactic differences
17:22chessguyones that i'll run into immediately?
17:22duncanmchessguy: when you refer to DEFINE, are you talking about Scheme?
17:22antifuchsalso, things like not being allowed to modify local variables after they were bound
17:22chessguyyes
17:22hiredmanclojure doesn't have cons cells
17:22hiredmanno car and cdr
17:22duncanmso substitute that with first and rest
17:22chessguyoh right, it's first and rest, right?
17:22chessguyyeah
17:22chessguy,(rest '(1 2 3 4))
17:22duncanmchessguy: the LET syntax is different
17:22clojurebot(2 3 4)
17:22chessguy,(rest (rest '(1 2 3 4))
17:22clojurebotEOF while reading
17:22hiredmanbut, if you are watching SICP, they uses cons cells for stuff like rational numbers
17:22antifuchsalso, the cond syntax. and reader differences. check out the lisp differences page on the wiki (:
17:22hiredmanof course clojure has rational numbers built in
17:22chessguy,(rest (rest '(1 2 3 4)))
17:22clojurebot(3 4)
17:22duncanmhiredman: so does scheme
17:22chessguyhiredman: but using built-in code is no fun :)
17:23hiredmanso you would use a struct for rational numbers in clojure
17:23chessguya struct?
17:23hiredman,(doc defstruct)
17:23clojurebot"([name & keys]); Same as (def name (create-struct keys...))"
17:23hiredmanit is a kind of map
17:23chessguyyou couldn't just use a list of 2 elements?
17:23hiredmanoptimized for making a small number of keys
17:23Chousukeuh, why would you use a struct?
17:24hiredmanchessguy: you could
17:24hiredmanif you where going to go the positional route I would use a vector
17:24ChousukeI wonder what the class name was though
17:24hiredmaninstead of a list
17:24Chousuke,(Ratio. 1 2)
17:24clojurebotjava.lang.IllegalArgumentException: Unable to resolve classname: Ratio
17:24Chousuke(class 1/2)
17:24hiredmanChousuke: yes yes, the native rationals was covered
17:24Chousuke,(class 1/2)
17:24clojurebotclojure.lang.Ratio
17:25hiredmanbut, if you where making your own rationals
17:25duncanmi think the name is rationalize
17:25duncanm,(rationalize 0.5)
17:25clojurebot1/2
17:25duncanm,1/2
17:25clojurebot1/2
17:25duncanmyou don't need an explicit constructor
17:25chessguy,(defn test ((defn numer first) (defn denom [x] (first (rest x)) (denom '(1 2)))
17:25clojurebotEOF while reading
17:25chessguy,(defn test ((defn numer first) (defn denom [x] (first (rest x)) (denom '(1 2))))
17:25clojurebotEOF while reading
17:25hiredman,(struct (create-struct :denom :nom) 1 2)
17:25clojurebot{:denom 1, :nom 2}
17:25chessguyah the fun of balancing parens
17:26Chousukechessguy: def and defn won't work with clojurebot
17:26duncanmchessguy: use a real editor
17:26hiredmanchessguy: I will stop you there
17:26hiredmanno defs in clojurebot
17:26chessguyoh
17:26duncanmhiredman: just use LET! ;-)
17:26chessguywell poo
17:26Chousukeand instead of rest you want to use second anyway
17:27hiredmanand use a struct
17:27hiredman:P
17:27chessguy,(second '(1 2 3))
17:27clojurebot2
17:27duncanm(rest '(1 2)) -> '(2); (second '(1 2)) -> 2
17:27duncanma common mistake
17:27hiredmanUSE A STRUCT
17:27Chousuke(let [numer first denom second] (denom [1 2]))
17:27Chousukehiredman: why, though?
17:27hiredmana struct as clearly labeled parts
17:27chessguyduncanm: i was doing (first (rest x)), not (rest x)
17:27hiredmaninstead of just a list of numbers
17:28duncanmthen that's the same as CADR, which is SECOND
17:28chessguyduncanm: yes, but it's not wrong
17:29hiredmanso when you see (8 7) is that a rational? {:denominator 8 :nominator 7} is pretty clear
17:29ChousukeI wonder why this is being discussed as native support for rationals exists :P
17:29chessguyhiredman: i understand that. i'm trying to grok list syntax right now
17:29chessguychillax :)
17:30Chousukeyou wouldn't use lists for rationals anyway. you'd use vectors.
17:30hiredmanChousuke: because in the SICP videos they make their rationals
17:30Chousukelists are overrated.
17:30chessguypeople, I'M NOT BUILDING A RATIONAL NUMBER LIBRARY
17:30chessguygeez
17:30hiredman 14:22 hiredman : if you where going to go the positional route I would use a vector
17:31duncanmla la la
17:38chessguywell, i'm glad we got that settled
17:43hiredman,(alter-meta! *ns* assoc :killroy-was-here (Date.))
17:43clojurebot{:killroy-was-here #<Date Sun Mar 29 14:41:43 PDT 2009>, :a 1}
17:43cmvkk^*ns*
17:43cmvkk,^*ns*
17:43clojurebot{:killroy-was-here #<Date Sun Mar 29 14:41:43 PDT 2009>, :a 1}
17:44antifuchshaha
17:44cmvkk,(alter-meta! + assoc :foo 2)
17:44clojurebotjava.lang.ClassCastException: clojure.core$_PLUS___3313 cannot be cast to clojure.lang.IReference
17:44cmvkk,(alter-meta! #'+ assoc :foo 2)
17:44clojurebot{:foo 2, :ns #<Namespace clojure.core>, :name +, :file "core.clj", :line 569, :arglists ([] [x] [x y] [x y & more]), :inline-arities #{2}, :inline #<core$fn__3310 clojure.core$fn__3310@ac0f75>, :doc "Returns the sum of nums. (+) returns 0."}
17:45chessguyi'm beginning to think that clojure might be the language that finally lures me away from haskell
17:45cmvkkwait does doc operate off of the meta
17:45Chousukeyes
17:45hiredman"hey man, I left you message in +'s metadata"
17:45cmvkk,(alter-meta! #'+ assoc :doc "Subtracts two numbers. Just kidding.")
17:45clojurebot{:foo 2, :ns #<Namespace clojure.core>, :name +, :file "core.clj", :line 569, :arglists ([] [x] [x y] [x y & more]), :inline-arities #{2}, :inline #<core$fn__3310 clojure.core$fn__3310@ac0f75>, :doc "Subtracts two numbers. Just kidding."}
17:45cmvkk,(doc +)
17:45clojurebot"([] [x] [x y] [x y & more]); Subtracts two numbers. Just kidding."
17:45Chousuke:)
17:45cmvkkexcellent.
17:45chessguyhaha
17:46chessguy,(+)
17:46clojurebot0
17:46chessguy,(+ 3)
17:46clojurebot3
17:46chessguycute
17:46chessguyi like that syntax
17:46AWizzArdchessguy: in the end you could write your own reader and get any syntax you like
17:46hiredmanhuh
17:47hiredmannever noticed :inline and :inline-arities
17:47slashus2Are there any good examples of using zippers to create a tree structure?
17:47chessguyso i can do (defn foo [x] (...)) and then also do (defn foo [x y] (...)) ?
17:47chessguyslashus2: they're not used to create trees
17:47hiredmanno
17:47chessguyslashus2: they're used to define them
17:47chessguyerr
17:47chessguytraverse them
17:48hiredmanyou do (defn foo ([x] ...) ([x y] ...))
17:48chessguyoh ok
17:48slashus2chessguy: It has the ability to create new nodes and edit them.
17:48cmvkkman whenever you write ellipses it shows up as random gibberish in my terminal
17:48hiredmancmvkk: because I use a unicode ellipse
17:49cmvkkyep. do you have a button assigned to it or something
17:49Chousukecmvkk: set up your client to use UTF-8 :)
17:49cmvkkmy client is aterm :/
17:49hiredmanirssi turns ... into ...
17:49Chousukewell aterm ought to work.
17:49hiredmanbah
17:49hiredman"..."
17:49Chousukenah.
17:49slashus2It has insert-child, make-node, etc. I don't see any reason why it could not be used for that purpose.
17:49Chousukemine shows it just fine
17:49cmvkkaterm isn't unicode compatable. or so it seems...i'm running irssi on screen on aterm, and i get the weird gibberish
17:49clojurebotit is too
17:50hiredmanI use terminator (tiling temrinal thing) screen and irssi
17:50hiredmancmvkk: each of those things has it's own unicode settings
17:50Chousukecmvkk: do you have your locale set to UTF-8
17:50cmvkk............maybe
17:51cmvkkLANG=en_US.UTF-8 does that count
17:52hiredmanhttp://jerakeen.org/blog/2005/06/screen-irssi-utf8/
17:53slashus2chessguy: Huet's paper states that changes, insertion, and deletion are valid operations.
17:54hiredman...
17:54hiredman?
17:55hiredman
17:55cmvkknope. hmm.
17:55cmvkki restarted with screen -U and put /set term_charset utf-8
17:55cmvkkoh well!
17:55chessguyok, so why does this blow the stack? (defn foo ([] 0) ([x & rest] (+ x (foo rest))))
17:55hiredmanwhat do they show up as? squares?
17:55cmvkka with a mark above it, dotted square, broken pipe
17:56hiredmanyou will never get to ([] 0)
17:56chessguywhy? rest can't match against an empty list?
17:56hiredmanyou most likely want (apply foo rest)
17:56hiredman[] is not an empty list
17:56cmvkkchessguy that's not an empty list, it's no arguments
17:56hiredmanit is no args
17:56chessguyerr, whoops
17:57hiredman,(doc apply)
17:57clojurebot"([f args* argseq]); Applies fn f to the argument list formed by prepending args to argseq."
17:57chessguywhat's that * notation?
17:57hiredman* is just used there to mean more then one thing
17:57cmvkkit means like 'zero or more'
17:57hiredmanit isn't language syntax
17:57cmvkkit's a kleene star!
17:58chessguyok, typical regex-ish notation
17:58hiredman,(apply + 1 2 '(3 4 5))
17:58clojurebot15
17:58chessguyyeah, this seems to work:
17:58chessguy(defn foo ([] 0) ([x & rest] (+ x (apply foo rest))))
17:59hiredman,(apply + '())
17:59clojurebot0
17:59chessguy,(+)
17:59clojurebot0
17:59chessguy:)
17:59AWizzArdchessguy: while it works it would probably not be code that gets used in production
17:59clojurebotit is too
17:59AWizzArd,(*)
17:59clojurebot1
17:59chessguyAWizzArd: uh, this is the first code i've written in clojure. i don't expect it to get used in production :)
17:59hiredmanclojurebot: botsnack
17:59clojurebotthanks; that was delicious. (nom nom nom)
18:00chessguyso helpful for you to point that out though
18:00chessguyi was really concerned
18:00AWizzArd(defn foo [numbers] (apply + numbers)) could do the trick
18:00chessguyAWizzArd: so would (defn foo (+))
18:01chessguythat's hardly the point
18:01AWizzArdNo, that would not work
18:01AWizzArdeven (def foo +) would not be the same thing
18:02cmvkk,(let [foo +] (foo 2 3))
18:02clojurebot5
18:02AWizzArd,(let [foo +] (foo '(2 3))
18:02clojurebotEOF while reading
18:02AWizzArd,(let [foo +] (foo '(2 3)))
18:02clojurebotjava.lang.ClassCastException
18:03AWizzArd,(apply + '(2 3))
18:03clojurebot5
18:03chessguyinteresting
18:03cmvkk,(let [foo #(apply + %)] (foo '(2 3)))
18:03clojurebot5
18:03chessguynot sure i get why (defn bar +) doesn't work
18:04cmvkk (def bar +) would just make bar work like +.
18:04chessguyoh right, def
18:04chessguythat's what i meant
18:06chessguywouldn't bar then represent the same function that + represents?
18:06cmvkkyes.
18:06chessguycool :)
18:07chessguyi did learn something from SICP
18:07AWizzArdAnd apply is one of those funny functions that one can not write on the same level on which one is writing the rest of the program. Although antifuchs made a nice macro that can fake apply for most practical cases ;)
18:09chessguyhm. so you can't evaluate clojure in clojure?
18:09AWizzArdyou can
18:09chessguyhm
18:09cmvkki'm not sure what you mean, though. apply isn't a special form; it's written in clojure.
18:10astorThinking about the problem I mentioned earlier, a macro - (loop-seq sequence bindings &body) could be imagined which will go through a sequence and where bindings is used to keep state and where the exit of the loop is a (cons...). It seem that this macro is very hard to implement since there is not way to add extra arguments to (recur..).
18:10chessguyanyway, enough brain-bending for tonight. i'm off to hang out with some friends. thanks ya'all!
18:10cmvkkon second glance, apply is written with java after all.
18:10AWizzArdcmvkk: yes right.. but look at it's definition
18:10AWizzArdyup
18:11AWizzArdjust write your own apply without making use of apply itself
18:12cmvkk (defmacro myapply [f args] `(~f ~@args))
18:12cmvkk:)
18:13AWizzArdyes, that works for a subset of cases where one can use apply
18:15AWizzArda small subset
18:15dnolen,(apply apply [+ [1 2 3]])
18:15clojurebot6
18:16cmvkkmy version does that too?
18:17AWizzArdyes
18:17AWizzArdbut try for example:
18:17AWizzArd,(range 2 4)
18:17clojurebot(2 3)
18:17AWizzArd,(apply + (range 2 4))
18:17clojurebot5
18:17duncanm,(range 1 3)
18:17clojurebot(1 2)
18:17duncanmheh
18:17hiredmancmvkk: I surprised you haven't paste your lazy-loop yet
18:17cmvkktouche!
18:18cmvkkhiredman I did a long time ago
18:18cmvkk1 1 0
18:18cmvkkhttp://paste.lisp.org/display/77400
18:19cmvkkit captures a variable though
18:19clojurebotit is too
18:19AWizzArdhiredman: you gave him too much botsnacks
18:19AWizzArdtoo many
18:19Chousuke:P
18:22cmvkkastor: look at my paste above
18:22cmvkkdidn't notice that you were looking for something like that
18:22clojurebotfor is not used often enough.
18:22cmvkkideally you'd want a structure that you can either recur OR give, so that you can 'skip' iterations.
18:23cmvkkthis is something that streams would be able to do i think?
18:23hiredmanI think you can do it with seqs
18:23hiredmanyou just return a call instead of a cons
18:23cmvkkin theory
18:24cmvkkright, but then you have to start worrying about blowing the stack if you skip too many times.
18:24cmvkkyou can't use recur, since that won't work through a lazy-seq.
18:24cmvkkactually, you can't just call either. becuase then you have a lazy-seq returning another lazy-seq.
18:24cmvkkwhich isn't quite right...
18:25cmvkkactually, the way to do it would be to expand a loop right inside the lazy-seq, that just binds the same arguments as the function as a whole.
18:25cmvkkthen you can use recur normally, and if all you do is return a cons right away, it just ignores the loop entirely.
18:30lisppaste8cmvkk annotated #77400 "fixed lazy-loop" at http://paste.lisp.org/display/77400#1
18:45astorcmvkk: inspired by lazy-loop, I wrote a very simple lazy-seq-fn
18:45Chousukewhat does that do?
18:45lisppaste8astor annotated #77400 "lazy-seq-fn" at http://paste.lisp.org/display/77400#2
18:47lisppaste8astor annotated #77400 "untitled" at http://paste.lisp.org/display/77400#3
18:48astoran fn where I can use either recur or cons based on whether I want to filter or not.
18:50astoradding support for destructuring in bindings requires "slightly" more work :-)
18:50Chousuke(doc destructure)
18:50clojurebotexcusez-moi
18:50Chousukehm
18:50cmvkkmy fixed lazy-loop does that, though.
18:50Chousukeanyway, there's a function that destructures a binding form
18:50cmvkkyou can 'recur' or 'give' based on whether you want to skip or not, and it supports destructuring the same way regular loop does.
18:51Chousuke,(destructure '[x 1 y 2])
18:51clojurebot[x 1 y 2]
18:51Chousukeeh
18:51ChousukeI'm silly sometimes
18:51Chousuke,(destructure '[[x y] [1 2]])
18:51clojurebot[vec__4374 [1 2] x (clojure.core/nth vec__4374 0 nil) y (clojure.core/nth vec__4374 1 nil)]
18:53durka42oh, that's how it works
18:53durka42cool
18:53cmvkk,(doc destructure)
18:53clojurebot"([bindings]); "
18:53astorcmvkk: the (vector % %) doesn't work with destructuring.
18:53Chousukeit's undocumented :)
18:53cmvkkastor... hmm, you might be right.
18:54cmvkkHMM.
18:54astorcmvkk: lazy-seq-fn does not have the capture problems. I think it captures the essence of your idea.
18:55cmvkkyep, it's pretty much the same thing.
18:55cmvkknow i'm just wondering how to fix destructuring on both of them.
18:56Chousukeactually, since loop supports destructuring, wouldn't calling that with something like [x [y z]] end up like (loop [x x [y z] [y z]] that is completely valid? :/
18:57cmvkkthe problem is when you get [[x & y :as z] [x & y :as z]] where clearly the second is not a valid initial form.
18:57Chousukeah, true.
18:58cmvkkaha, i know how to do it.
18:59cmvkkfor the function's arglist, you just use gensyms. then for the loop, you use the actual destructed args, and the gensyms as the inits.
18:59astorcmvkk: nice
19:02lisppaste8cmvkk annotated #77400 "double fixed lazy-loop" at http://paste.lisp.org/display/77400#4
19:36hiredmanhttp://boinkor.net/archives/2009/03/clojure_and_art_of_illusion_bf.html <-- awesome
19:36qwert666hmm i`m using the fibonacci code from http://clojure.org/atoms and with a large numbers i`m getting StackOverflowError do u know any "tricks" to omit the stack problem... ?
19:36cmvkkeven with the memoization?
19:37hiredmanit depends what is blowing the stack, and how large your numbers are
19:38cmvkkah yeah, it would.
19:38qwert666hiredman: fib >500
19:38cmvkkbecause if you start it out, it still has to call back and memoize every single previous number.
19:38Puzzleryeah, that implementation would blow the stack.
19:39hiredmanI have no idea how big that number is
19:39cmvkkhiredman, it doesn't matter how big the result is.
19:39clojurebotit is too
19:39qwert666hmm so the implementation sux for big numbers :(
19:40PuzzlerSome other versions of Scheme / Lisp don't really have a stack that's limited by anything but overall memory, but in Clojure, you've got to be careful, because it's running on Java.
19:40cmvkkyeah, even if you memoize that's a really bad way to write a fibonacci algorithm.
19:40cmvkki think this sort of recurring is likely to blow the stack no matter what language you use.
19:42qwert666mhm ok thx u`r probably right
19:42dnolenPuzzler: that's not completely true, Scheme & Lisp have TCO, you can still blow the stack.
19:42dnolenScheme & CL I meant.
19:43hiredmanfrom what I hear not all CL impls have tco
19:43PuzzlerI don't know the implementation details, but I've used PLT Scheme enough to say that function calls are not implemented using a limited stack that can "blow". Eventually, you'll run out of overall memory on your machine, but far after mainstream languages would blow a stack.
19:43dnolenhiredman: you are correct.
19:44PuzzlerIt's as if everything is heap allocated (don't know if that's really how it's implemented, though).
19:44dnolenPuzzler: they will blow if the recursion calls are not in the tail posiitin.
19:44cmvkkPuzzler, are you sure you aren't thinking of tail recursion?
19:44cmvkkyeah.
19:45PuzzlerI'm sure. Yes, I know the memory will eventually run out. I'm just saying it is not as limited as languages which have a very small amount of memory set aside for stack.
19:45PuzzlerYou can do non-recursive things involving many thousands of levels deep, and it won't bat an eye.
19:45dnolenin Clojure you can do pretty much the same thing with trampolines or recur
19:45dnolenPuzzler: you can set the stack memsize to the jvm instanc.e
19:45PuzzlerI meant "non tail-recursive"
19:46dnolenPuzzler: that's because functions calls are in the tail position.
19:46cmvkkdnolen, that wouldn't be "non tail-recursive" though.
19:46PuzzlerTo put it in perspective, in Clojure, you have to be very careful about writing non tail-recursive traversals of really long lists (like simple implementation of map).
19:47PuzzlerIn PLT Scheme, if the list can fit in your memory, you'll have no problem with the accumulated function calls fitting in memory too. So basically, you can write your function in the naive way, without worrying about stack.
19:48PuzzlerThat's cause in most languages the stack is only a small percentage of overall memory.
19:48dnolencmvkk: the TCO, is tail call optimization, recursion is one case as far I understand the issue.
19:48cmvkkbut i think his point is that PLT scheme won't blow the stack, even if you don't take advantage of TCO.
19:49cmvkkyou can have recursion without having TCO.
19:50PuzzlerRight cmvkk, you'll eventually run out of memory, but after you've used all 3GB of RAM on your machine (not likely to happen), rather than after 3000 function calls deep, or some other arbitrary number.
19:51cmvkkalthough that might be the case, i don't think it makes it okay to write naive recursive algorithms
19:51cmvkkyou're right though: "At the same time, recursion does not lead to particularly bad performance in Scheme, and there is no such thing as stack overflow;"
19:51cmvkkfrom the PLT docs
19:52PuzzlerConsider something like this: (defn map [f s] (if (empty? s) () (cons (f (first s)) (map f (rest s))))
19:53PuzzlerIn PLT Scheme, you don't have to worry about stack overflow. But you do in Clojure.
19:53PuzzlerAn easy fix in Clojure is to wrap this in a lazy-seq.
19:53cmvkkit's still a bad idea to do that, though.
19:53PuzzlerWhy?
19:53cmvkkin fact, that's how map is defined in clojure...
19:53cmvkkbecause TCO is more efficient in general
19:53qwert666so if i`m geting it right... the TCO secure in some way the jvm from blowing the stack off... ?
19:53PuzzlerBut for other kinds of traversals, it's not such an easy fix.
19:54cmvkkand because using O(n) space is pointless if you can do it in constant space.
19:54cmvkk"Similarly, in Scheme, it is often important to make sure that tail recursion is used to avoid O(n) space consumption when the computation is easily performed in constant space."
19:54cmvkkalso from the PLT docs.
19:55PuzzlerYou're going to use up O(n) space anyway to build the final list. Taking up the same amount of space, temporarily, with "stack"-like allocations, doesn't change anything.
19:55cmvkkI suppose that's true...except for the extra function call stuff, I guess.
19:56PuzzlerYou can't easily make map tail-recursive without reversing the list, and reversing it again at the end (or using laziness which adds its own overhead).
19:57PuzzlerAmazingly, if you compare a tail-recursive and non-tail-recursive version of factorial in PLT Scheme, the non-tail-recursive one is faster.
19:57cmvkkYeah, the docs seem to suggest that that's the case.
19:57dnolenhey I just tried factorial in DrScheme and I ran out of memory, (fact 10000000)
19:57cmvkkheh
19:57cmvkki think that kind of input doesn't prove much...
19:58PuzzlerMy guess is that with that kind of input, the final answer is too big to fit in memory :) .
19:58lisppaste8dnolen pasted "scheme blow stack" at http://paste.lisp.org/display/77760
19:58dnoleni don't think that is true Puzzler
19:58dnolenthe problem here is that the call to fact is not in the tail position
19:59dnolenthe stack grows because of the *
19:59cmvkkyep. it's not *impossible* to blow the stack in PLT, but you have to run out of all memory.
19:59cmvkkto calculate that number, you need ten million stack frames...
20:00PuzzlerYes, what cmvkk said is exactly my point.
20:00dnolenthe point is that code cannot be TCO'ed
20:00dnolenthe multiply needs the stack to grow to resolve all values.
20:00PuzzlerI don't think 10 million stack frames is your limiting factor though. My guess is it's the manipulation of such enormous integers.
20:01cmvkki wonder. try it again with + instead of *.
20:01cmvkkthat won't come near running out of memory just because of the integer.
20:02dnolenit stills runs out of memory
20:02dnolenhttp://funcall.blogspot.com/2009/03/not-lisp-again.html
20:02dnolenthis is not my own invention, example culled from here
20:02dnolenit explains the TCO issue quite well.
20:02cmvkkin any case, factorial is a good example of a function that nobody should be defining like that, no matter how good your language handles recursion.
20:03cmvkkbut i think we can agree on that point...
20:04PuzzlerOK, I concede that PLT Scheme can't handle 10,000,000 function calls deep.
20:04dnolentrue, enuf, but it should clearly what TCO means, you need to write you code so that TCO can kick in even in Lisp and Scheme.
20:04cmvkkdnolen, well, to be fair, probably nobody's going to calling factorial ten million.
20:05cmvkkfactorial's just an example of a function that's it's really simple to write in tail position.
20:05PuzzlerIt still helps that you're not as limited as in most languages.
20:05cmvkkno, you're right. especially with functions that hare hard to make tail-recursive.
20:05PuzzlerWhen I write recursion over lists or trees, I do worry about whether Clojure will be able to handle the depth.
20:06PuzzlerI'm not used to worrying about that.
20:06PuzzlerI'm working on code right now that can't really be trampolined or turned into TCO, but potentially has a fair amount of depth.
20:06cmvkkit's a problem when you do tree recursion. since trampolines only work on tail calls too...
20:07PuzzlerI'd probably have to do something analogous to lazy-seq, storing a delay to the next node of the tree.
20:08PuzzlerFortunately, the stack limitation hasn't bitten me yet on this particular code, but it bothers me that it is fragile in this respect.
20:10qwert666i`m searching for some benchmarks results of clojure and other langs do you know any good source of info. ? i usually was using http://shootout.alioth.debian.org/ but no clojure code there :(
20:10PuzzlerHmmm, I wonder if there is a clever way to use futures to return immediately, like a delay, but continue building the tree immediately on a separate thread.
20:11PuzzlerI haven't seen much benchmarking of Clojure.
20:11PuzzlerI have been impressed with its speed overall.
20:12PuzzlerI LOVE the persistent vectors.
20:16qwert666Puzzler: ye but i think it would beat few langs anyway :) and it would be nice to compare the speedup of clojure from a perspective of time
20:22qwert666Puzzler: i think that the fib example from clojure is quite good
20:22qwert6660.044ms for fib 35
20:30dnolenPuzzler: you are right about tree walking it does present a problem in Clojure, that's where tree-seq helps.
20:30dnolen,(doc tree-seq)
20:30dnolenclojurebot kaput?
20:30clojurebot"([branch? children root]); Returns a lazy sequence of the nodes in a tree, via a depth-first walk. branch? must be a fn of one arg that returns true if passed a node that can have children (but may not). children must be a fn of one arg that returns a sequence of the children. Will only be called on nodes for which branch? returns true. Root is the root node of the tree."
20:42PuzzlerI haven
20:42PuzzlerI haven't played around much with tree-seq.
20:42PuzzlerI think I need a convenient, lazy way to *construct* trees, however.
21:38RaynesI usually feed off of Clojure Swing examples but it seems virtually no one has used JPopupMenu within Google Space.