#clojure logs

2009-03-21

00:00slashus2p_l: Try to compile openjdk on there :-)
00:04p_lslashus2: well, MVS3.8 is not going to be POSIX-compatible :D
00:04slashus2:-(
00:05pstickneWhat better way(s) are there of doing: (reduce #(str %1 "->" %2) ["hello" "world"])
00:05Raynesmultimethods are hawt.
00:06RaynesI wish Clojure had pattern matching.
00:06slashus2Raynes: Implement it.
00:06pstickneWell, it kind of does with multimethods ...
00:06psticknethey are like untyped active patterns that can be broken up among sites
00:06Raynespstickne: Kind of overkill for pattern matching. But it definitely works.
00:06Raynesslashus2: I should /totally/ do that.
00:06slashus2pstickne: You could use clojure.contrib.str-utils/str-join
00:07pstickneand it supports the neat (let [[a b c] (foo)] ...) style matching
00:07slashus2~str-join
00:07clojurebotExcuse me?
00:07pstickne(or, decomposition, rather)
00:07slashus2,(doc clojure.contrib.str-utils/str-join)
00:07clojurebotjava.lang.Exception: Unable to resolve var: clojure.contrib.str-utils/str-join in this context
00:07RaynesI keep forgetting that I can implement my own features in Clojure. :|
00:07slashus2,(apply str (interleave " " ["hello" "world"]))
00:07clojurebot" hello"
00:08slashus2:-|
00:08Raynes,(apply str (interpose " " ["Hello" "world!"]))
00:08slashus2,(apply str (interpose " " ["hello" "world"]))
00:08clojurebot"Hello world!"
00:08RaynesOwned.
00:08clojurebot"hello world"
00:08stuhoodyea, i think you want interpose
00:08slashus2Raynes: Only barely.
00:08Raynes;)
00:08stuhood,(apply str (interleave " " ["hello" "there" "world"]))
00:09clojurebot" hello"
00:09slashus2I accidentally typed interleave instead of interpose.
00:09Raynesslashus2: And I was even unplugging my Ipod when I did that.
00:09Raynes\o/
00:14slashus2 (eval (symbol "(+ 1 2)")) this doesn't seem to work :-(
00:21Victorrtry (eval (read-string "(+ 1 2)"))
00:21Victorr,(eval (read-string "(+ 1 2)"))
00:21clojurebotDENIED
00:21Victorrclojurebot, you are a bore
00:22slashus2Victorr: Thank you!
00:22Victorrmp
00:22slashus2That only reads one object.
00:23slashus2Victorr: Is there something that can read all objects?
00:24Victorrsure, just prepend "(list " to your string, and append ")", that ought to do the trick
00:24Victorrwhat exactly are you trying to do?
00:24slashus2Victorr: I was trying to hack up a plugin system. Read in the code from a bunch of files, and evaluate it.
00:25Victorrisn't that what load-file does?
00:25slashus2:-|
00:26slashus2I think so.
00:26slashus2I wonder what the best way to do it with eval would be.
00:36Victorrgood night!
01:46Raynes,(time (loop [x 5] (when (zero? x) 0) (println x) (recur (dec x))))
01:46clojurebotExecution Timed Out
01:48harpastumwoah
01:48harpastumjust ran that
01:49RaynesIt never completed for me.
01:49RaynesI don't get why.
01:49RaynesI got impatient waiting and closed the REPL.
01:49cmvkkit recurs forever.
01:49harpastum(when (zero? x) 0)?
01:49RaynesThat's what I'm trying to figure out :\
01:49harpastumwhat does that mean?
01:49RaynesI have apparently misused when.
01:49cmvkkyeah, when returns zero when x is 0, or nil otherwise.
01:50cmvkkbut THEN, the println and recur statements run, no matter what.
01:50cmvkkthey're not inside the when statement, notice.
01:50harpastumthey're inside the loop though
01:50cmvkkyeah.
01:50RaynesOh, I forgot that when wasn't if.
01:50Raynes>_>
01:50harpastumso it just runs that statement
01:50harpastumand that doesn't do anything
01:50harpastumand moves on
01:51cmvkk,(time (loop [x 5] (if (zero? x) 0 (do (println x) (recur (dec x)))))
01:51clojurebotEOF while reading
01:51cmvkk,(time (loop [x 5] (if (zero? x) 0 (do (println x) (recur (dec x))))))
01:51clojurebot0
01:51clojurebot5 4 3 2 1 "Elapsed time: 0.739 msecs"
01:51harpastumhaha
01:51harpastumthere you go
01:51Raynesharpastum: 'when' runs every time, and when it reaches zero, it runs but still continues.
01:51RaynesI know how to do it, I was just playing around with when :\
01:51RaynesYou guys underestimate me ;)
01:52harpastumi ran it in my repl
01:52harpastumi managed to stop it by the time it was printing -250k
01:52harpastumthe original function
01:52RaynesHaha.
01:53harpastumi realize that it's probably just my laziness and the fact that I'm not totally used to LISP
01:54harpastumbut i really wish there was an editor that i could hit like option-) and it would add enough parens to get back to the beginning of the declaration
01:54harpastumi guess it's also because i'm still using the repl in terminal
01:55harpastumi really have to get around to installing that emacs plugin
01:55harpastum,(time (loop [x 5] (if (zero? x) 0 (do (println x) (recur (dec x))))))
01:55clojurebot0
01:55clojurebot5 4 3 2 1 "Elapsed time: 0.709 msecs"
01:56RaynesMan, I don't think there /is/ an elegant way to write a Towers of Hanoi solver without using recursion :\.
01:57pstickneAll recursion can be...
01:57RaynesWhat?
01:57pstickneunrolled.
01:58RaynesThere a way to do it using /just/ tail recursion, but I can't figure out how to do it in an elegant way.
01:59psticknedon't like the wiki?
02:00RaynesHrm?
02:00psticknehttp://www.kernelthread.com/projects/hanoi/ :-)
02:01RaynesThere is no Clojure example there.
02:01pstickneadd one :p
02:01RaynesI added mine at rosetta code.
02:02psticknehmm, I read the CL example wrong :p
02:02Rayneshttp://www.kernelthread.com/projects/hanoi/html/gcl.html This is the kind of stuff I want to avoid.
02:02psticknewhich part?
02:02RaynesCalling itself twice is what blows the stack, but normally it isn't very noticeable, but in Clojure and the JVM's stack, it can't even handle 10,000.
02:03Rayneshttp://www.kernelthread.com/projects/hanoi/html/gcl.html My example.
02:03pstickneso move it onto the heap with an unroll? (I now of of no non-dividing solution)
02:03psticknewikipedia gave the rules for a non-recursive solution
02:04RaynesHow do you do an unroll? O.o
02:04psticknecheck out wikipedia already :p
02:04psticknethere are 5 posted solution groups
02:08p_lnice verb
02:09Raynesp_l: I can verb with the best of them.
02:09RaynesI HAVE GOT TO FINISH THIS DAMNED BOOK!
02:09durka42why 3am?
02:09durka42heh
02:10Raynesbriancarper: Hi there.
02:11Raynesbriancarper: I'm surprised you were able to realize that my Clojure example wasn't a palindrome, nice eye you got there.
02:11briancarperHi, yeah I wrote my own, then I put it through Ruby 'blah blah blah'.reverse and cried when I saw the backwards parens.
02:13p_lRaynes: then try to replace Win7 calculator :D
02:13Raynesp_l: My calculator is simpler than the Vista calculator. No one ever uses all that scientific shit anyways.
02:13RaynesMy calculator has 5 buttons and a text field \o/
02:15RaynesIs there a firefox plugin for saving entire websites for quick access later?
02:15RaynesI think there is
02:16briancarperCan't you File, Save as., and save everything?
02:17RaynesWill take too long. In hindsight it will probably take longer for me to find and install the plugin, but oh well.
02:17p_lScrapbook
02:19Raynesp_l: My hero.
02:36RaynesGood night computer.
03:34Lau_of_DKTop of the morning gents
03:38blbrownLau_of_DK, I have 3 more hours but that works
03:41cgrandmorning Lau!
03:42Lau_of_DKMorning Mr. Grand :)
03:48blbrownLau_of_DK, did you eat breakfast? I think I want a big breakfast today.
03:48Lau_of_DKYes I did :)
04:05RaynesI just finished Programming Clojure
04:05RaynesAnd right in time for bed!
04:05RaynesI feel so accomplished. <3
04:19RaynesGood night my fellow Clojurists!
04:19p_lnight
11:05jcrites"Better static safety for higher-order code" claimed by esoteric language designer Slava Pestov
11:05jcritesI read this and laughed because
11:05jcritesdoes it mean Slava is a designer of esoteric languages?
11:05jcritesor that Slava is an esoteric designer of languages? :P
11:05jcritesor both :)
11:05jcritesa. Intended for or understood by only a particular group: an esoteric cult. See synonyms at mysterious.
11:06jcritesis Slava intended for or understood by only a particular group? heh
11:07jcritesoh my
11:08jcriteswrong channel, sorry :)
12:13cconstantineDoes anyone know the bigO of dissoc?
12:25Carkconstantine : depends on the kind of map
12:25Carki beleive sorted map is log n and hashmap is log32 n
12:26Carkthough i didn't go and check the code
12:52cconstantineCark: ok. Just wanted to make sure dissoc of a hashmap wasn't something crazy like O(N)
12:59Carki'm positive about that
13:24RaynesWhoa, look at all the people that posted in my group thread while I slept.
13:42briancarperAre there any examples of people writing their own Java collection code and tying it to Clojure's seq interfaces?
13:44slashus2briancarper: What is wrong with the java collection code?
13:44marklarpaste
13:44marklarclojurebot: paste
13:44clojurebotlisppaste8, url
13:44lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
13:44kotarakbriancarper: lazymap kind of implements IPersistentCollection and can be used with Clojure's seq interface. It's using gen-class, though. Not Java.
13:45briancarperslashus2: e.g. using LinkedHashMap so I can have ordered maps.
13:45kotarakbriancarper: there's also array-map, for ordered maps.
13:45slashus2,(doc sorted-hashmap)
13:45clojurebotjava.lang.Exception: Unable to resolve var: sorted-hashmap in this context
13:45slashus2woops
13:45kotarak,(doc array-map)
13:45clojurebot"([] [& keyvals]); Constructs an array-map."
13:46slashus2,(doc sorted-map)
13:46clojurebot"([& keyvals]); keyval => key val Returns a new sorted map with supplied mappings."
13:46briancarperCool, I'll look at array-map.
13:46briancarperSorted maps aren't what I want though, I want to maintain insertion order.
13:47slashus2array map is what you want then.
13:49briancarperThanks. Now if only there was a literal syntax for them. :(
13:49slashus2briancarper: Smaller map literals are array maps
13:49kotarakbriancarper: I think for (hash-map ...) < 10 entries are array maps
13:49slashus2,(class {:a "5"})
13:49clojurebotclojure.lang.PersistentArrayMap
13:52dnolenbriancarper: structs are positional and stay positional from what I understand.
13:53dnolen,(do
13:53dnolen (defstruct my-struct :first :second :third)
13:53dnolen (prn (assoc (struct my-struct 1 2 3) :fourth 4)))
13:53clojurebotEOF while reading
13:53dnolenoops
13:53dnolen,(do (defstruct my-struct :first :second :third) (prn (assoc (struct my-struct 1 2 3) :fourth 4)))
13:53clojurebotDENIED
13:54briancarperdnolen: Oh, I didn't know that.
13:54dnolenheh, you can't defstruct with clojure bot
13:54dnolenanyways it should work.
13:54slashus2Oh, didn't think of structs
13:55dnolenbriancarper: yeah I was pondering this a while go, maps don't keep order, but I realized that structs do.
13:55dreish(Except when you add arbitrary keys that aren't part of the struct definition.)
13:55briancarperdreish: Yeah looks like arbitrary keys will appear all over the place, but struct keys are ordered.
13:55dreishRight.
14:13lisppaste8dnolen pasted "struct-assoc" at http://paste.lisp.org/display/77390
14:14dnolendreish, briancarper: you can work around this with some cleverness. note that struct-assoc is about 5X slower than assoc
14:14dnolenbut that isn't so bad considering that you care about position.
14:16briancarperOh, that's interesting. It makes a new anonymous struct every time?
14:18dnolenyes, basically you're getting hit on modification speed (maybe memory as well? structs use more than maps?), but you get positionality.
14:19briancarperThanks, it looks useful. I usually don't care about speed or memory.
14:19dnolencool, glad could be of help.
14:26dreishInteresting. I'd probably hide this behind a layer of abstraction in case I wanted to use a different implementation later, though.
15:51hiredman,(doc sorted-map)
15:51clojurebot"([& keyvals]); keyval => key val Returns a new sorted map with supplied mappings."
15:51hiredmanhmmm
15:51hiredmanah
15:51hiredman,(doc sorted-map-by)
15:51clojurebot"([comparator & keyvals]); keyval => key val Returns a new sorted map with supplied mappings, using the supplied comparator."
15:52hiredmanI think, using the right comparator, you could use that to keep insertition order
15:52hiredmanthere may even by some code for it on lisppaste
16:00cconstantineYay! I think I fixed the slow in my prime generator... now it's only 5 times slower than Chouser's instead of 400 thousand times slower :)
16:05psticknecconstantine: a small improvement ;)
16:05cconstantinehehe
16:06psticknecconstantine: using the same kind of generator?
16:06cconstantineand mine prime generator has the benefit of producing as many primes as you want :)
16:06pstickneI've only made a PRNG using the Super-7 LSFR (?)
16:07cconstantinenope, you have to give his an upper limit. (first mine) is a prime, and (rest mine) is a generator for the next prime :)
16:07pstickneoh, prime :p
16:07pstickneI was thinking...
16:07psticknecconstantine: what sizes of primes?
16:07cconstantinehow much memory and time do you have?
16:07pstickne:)
16:07cconstantineit's a lazy sequence
16:07pstickneBut it's really prime vs. probably-prime?
16:08cconstantinereally prime
16:08pstickne(and prime in sequence it sounds like?)
16:08cconstantineseive method without the array
16:08psticknecool :)
16:08cconstantineyeah :)
16:08cconstantinenow if I can just make it faster....
16:09pstickneASM ;-)
16:09cconstantineand paralelized... across a cluster, and then I can take over the world! muahahahah
16:09cconstantinebah
16:09cconstantineI do ASM for a living, clojure is for fun
16:09pstickneI've never learned what the consequences of accidently getting a non-prime number where in cryptography...
16:09psticknecconstantine: sorry :(
16:09pstickne*were
16:09cconstantineppc asm, and python, and c++ :(
16:10cconstantinegenerating a non-prime in crypto is bad.. very very bad
16:10pstickneeww :p
16:10lisppaste8slashus2 pasted "prime generator" at http://paste.lisp.org/display/77393
16:10psticknecconstantine: right, so if you have a probably-prime, and a million people a second generate it...
16:11slashus2This is probably not the best approach.
16:11pstickne(e.g. is there some final OMG DONT WANT check?)
16:11cconstantineslashus2: where's prime?
16:11slashus2oh sorry :-|
16:11cconstantinepstickne: you could try to divide it by all the previous known primes...
16:12lisppaste8slashus2 annotated #77393 "prime?" at http://paste.lisp.org/display/77393#1
16:12cconstantineslashus2: that's *a* way of doing it, but it's O(n * sqrt(n)) I beleive.... mine is O(n log n)
16:13cconstantineslashus2: you should read http://bigdingus.com/2008/07/01/finding-primes-with-erlang-and-clojure
16:13slashus2I guess the sieve is the best way of doing it?
16:13cconstantinethats the first way I did it, and it was shockingly slow
16:13cconstantineshockingly slow compared to my friend's c++ seive implementation
16:14cconstantinepstickne: what is this probably-prime you're talking about?
16:15psticknehttp://en.wikipedia.org/wiki/Probable_prime
16:16cconstantineoh! I can optimize it by incrememting by 2 instead of 1 :)
16:16psticknecconstantine: and discarding all / 5
16:16cconstantinepstickne: I do that anyway through the 5 counter
16:16pstickneanyway, they are useful: http://en.wikipedia.org/wiki/RSA
16:17cconstantinepstickne: ah, ok :)
16:17psticknecconstantine: but I dropped that class (as it was too much "let's code up an RSA implementation" vs. theory)
16:17psticknethe people in the course /still/ don't know the ramifications of not choosing a prime number :)
16:18cconstantinepstickne: bah, that's no good
16:18cconstantinepstickne: I had so much fun in my crypto class I got a job in my prof's startup :)
16:18cconstantinesorry, security class, not crypto class
16:19psticknecconstantine: I cringe at the thought of working for any professors startup (there are two in the comp-sci on this call campus)
16:19pstickne*small
16:19cconstantinewhy?
16:19pstickneWell, since we have separation of Church and State...
16:19pstickneanyway, it just smells like BadPolitics to me
16:20cconstantineconflict of interest?
16:20psticknesomewhat
16:20psticknebut it's all through and through
16:20cconstantineah. he wasn't involved in the hiring decision, and I applied after I graduated
16:21psticknefor this semester I had to do an "alternative project" for the final capstone software engineering course because I didn't want to blanket waive all my "IP" (a term which was not well defined in the waiver!) -- I am an undergrad so...
16:21cconstantinehe wanted you to waive all your IP for a class? that's wierd
16:21psticknebut it's okay, because this other project is like 10x cooler and I don't have to deal with the bunk of the other group (or the professor; we are the black sheep :p)
16:22cconstantinehehe
16:23psticknecconstantine: yeah, I guess it's "standard practice" -- I don't mind waiving rights to specified deliverables, but it was just "all IP" ^^
16:23cconstantinepstickne: well, I guess my school (purdue) has some level of rights to any work I did on purdue machines... but I don't remember signing anything
16:24pstickne(not that I think I'd come up with something cool -- I just don't like the thought :)
16:24cconstantineyeah
16:25pstickneon the other hand, colleges make oodles of money off of patents (which are another item of disgust, but ... I digress)
16:25cconstantineso, I'm testing the speed of a "test by divide by all previous primes" prime generator at 100000 primes about 20 minutes ago... and it's still going :)
16:25cconstantinehehe
16:26cconstantineeh, the initial tech our company is based on was written by a grad student... I think we had to buy it off purdue... but compared to how much we bring in now it's a pittance.
16:26cconstantineI never did grad school... and nothing I did as an undergrad is really worth anything
16:27pstickneI guess it's working out okay for you know though :-)
16:27cconstantineeh, it was still unproven (technically, and busness-wise) when they sold it
16:27cconstantineit's really only worth anything because of the work done by the company
16:27pstickneyou mean nobody will want my turtle->3bytecode compiler in clojure? :(
16:28cconstantinewait... you ahve one! oh wow I've needed one of those for like forever!
16:28pstickne:p
16:28cconstantine:)
16:30cconstantineI'm still learning clojure
16:30cconstantineI'm doing project euler to learn it
16:32pstickneI should do project euler in any language :p
16:32cconstantineso, I'm thinking about how I can multi-thread this prime generator... how easy would it be to have a lazy-seq that uses a separate thread to compute (first (rest gen))?
16:32cconstantinepstickne: it's good stuff
16:34cconstantineeffectivly use a producer/consumer pattern for lazy sequences
16:35cconstantinea half-dozen of my friends are doing project euler... only 2 of us are using a functional language (the other guy is using erlang... maybe haskel)
16:36pstickneI would not like to do it in a language that at least isn't functional-like :)
16:36cconstantineeh, one guys is learning a bunch about boost and c++
16:36cconstantinewhich is good...
16:36cconstantinewell... not c++ so much as c++'s stl
16:38cconstantinedo you have any classes on or in functional/lisp languages
16:45cconstantinehmmm... how bad would it be to produce 10s of thousands of threads?
16:47gnuvince_Probably not good
16:47Carkgive it a try and report back after your reboot !
16:47cconstantinehehe... ok
16:48cconstantineI was afraid of that
16:48Carkwouldn't be that dramatic i think
16:48cconstantineI'm thinking 10s of thousands of producers and one or two consumers... so they should be mostly stalled
16:49Carkusing agents you don't need to be concerned about that
16:49cconstantineso I need to read up on agents
16:49Carkthey live in a thread pool
16:50cconstantineahhhh
16:50Carkand are only executed when there are pending messages
16:50cconstantineso I give it a set of tasks to do, and it does them all in N threads
16:50Carkright
16:51Carkso you could have 10s of thousands agents without killing your memory
16:53cconstantineah, fantastic
16:53cconstantineall agents share a thread pool?
16:54Retonatorhey guys i am trying to understand sequences could any one explain what happens here (i understand the expansion and the values) not exactly what goes on.
16:54Retonator(def fibs (lazy-cat [0 1] (map + fibs (rest fibs))), what happens if i do lets say (take 4 fibs)
16:56jonathanturnernewbie question - how do I add 1 to every element in a list?
16:56cmvkkjonathanturner: (map inc my-list)
16:56cmvkk,(map inc [1 2 3])
16:56clojurebot(2 3 4)
16:56cconstantineI believe [0 1] is (first fibs), and (rest fibs) is the (map....) thing, but that s-expr isn't evaluated until someone runs (rest fibs)
16:56jonathanturnercmvkk: thanks, that works. Is there a way to use + also?
16:57cmvkk(map #(+ % 1) my-list)
16:57cmvkkfor example
16:57jonathanturneris that a curry?
16:57jonathanturnererr, partial function... whichever they're called in clojure
16:57cmvkkit's a function literal, equal to (fn [x] (+ x 1))
16:57Retonatorok cmvkk actually first fibs return [0]
16:57cmvkkbut i guess it's the same idea
16:57cconstantine#(..) s an anonyous function
16:58jonathanturnercool, thanks, that helps
16:58Retonatoryou have partials btw jonathan
16:58cmvkki guess you could also do (map + my-list (repeat 1))
16:58Retonator,(doc partial)
16:58clojurebot"([f arg1] [f arg1 arg2] [f arg1 arg2 arg3] [f arg1 arg2 arg3 & more]); Takes a function f and fewer than the normal arguments to f, and returns a fn that takes a variable number of additional args. When called, the returned function calls f with args + additional args."
17:00cmvkki've always thought that fibs function was too 'clever' and hard to read.
17:00cmvkkit looks nice, but...
17:01cmvkkwhat's going on is that you're mapping the fibs function so far, with one that's one element ahead of itself.
17:01Chouse1it's also not terribly efficient
17:01Retonatorvery nice but i want to get my mind around i think i know what it does but not right how ;)
17:01cmvkkusing +. so [0 1] is fibs. so (first fibs) is 0, and (first (rest fibs) is 1.
17:02cmvkkthen you're adding (second fibs) and (second (rest fibs)) which is 1 and 1, and so on.
17:02Retonatorbut in rest fibs then first fibs wil be the newly added item by the + ?
17:03psticknewhat is the \"nul" character?
17:03cmvkkyes.
17:03cmvkksomething like that...
17:04Retonatori think i understand it the map + actually gives back the next item in the sequence which you get back in rest fibs call and it will be the first argument for the next call
17:04Retonatora bit cryptic but i guess i get it ;_
17:04cmvkkyeah that's basically the jist of it.
17:05jonathanturneroh, I see it in the reference now. #() is listed as a reader macro, where there's also the (partial ) for partials
17:05Chouse1pstickne: (char 0) I guess
17:05pstickneChouse1: thanks
17:05pstickne(I really miss semi-formal language definitions :-/)
17:06Chouse1Clojure's got a very formal language definition.
17:06Retonator,(char 0)
17:06clojurebot\
17:06Chouse1so formal it's verified by the compiler, javac
17:06psticknehmm :(
17:06Chouse1:-)
17:06pstickne(str "a" (char 0) "b") :-/
17:07Chouse1I think that's the printing code
17:07pstickneyeah, length is 3.
17:07psticknebut why (pr-str (char 0)) ? :(
17:08Chouse1but I'd be a bit worried about nulls in a string anyway -- you're sure you don't want byte buffer of some sort?
17:08pstickneerr, (pr-str (str (char 0))
17:08pstickneChouse1: ohh, heh
17:08psticknefor uhm, an "eof" marker fnparse :p
17:09RetonatorChouse1: What would be an efficienter way of implementing fibs and why is the lazy-seq not very efficient (just curious)
17:10pstickneRetonator: high-order functions on the stack! :p
17:12Retonatoryeah okay so it is a stack problem is it possible to define fibs in a tail-recursive way to avoid the stack?
17:13pstickneRetonator: http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fwww.cs.toronto.edu%2F~ajuma%2F326f08%2F11Scheme4.pdf&amp;ei=llfFSfv8J6CSsQPs-Jk7&amp;usg=AFQjCNHpWLy9qHglhbnMF1n-2yZ4cpfCuA&amp;sig2=CCZ3lefpE6M1ZI9peLOVBg
17:13psticknedoh
17:13psticknesorry
17:13psticknewww.cs.toronto.edu/~ajuma/326f08/11Scheme4.pdf
17:13psticknethat was the personal google junk
17:14Retonatorthanks pstickne
17:14Chouser_Retonator: http://groups.google.com/group/clojure/tree/browse_frm/thread/3edf6e82617e18e0#doc_3cd0cb80a93aae4a
17:14Chouser_That's the thread where cgrand schooled me on this particular issue.
17:15Retonatorthanks Chouser i will read up on the thread thank you guys very helpfull :D
17:16Chouser_pstickne: a literal null char: \o0
17:16Chouser_or: \u0000
17:16cconstantineCould someone help me make use of agents to have the (rest) of my lazy-seq computed in a thread? I'll be paste-bin'ing the simple counting lazy-seq I want to work with.
17:18lisppaste8cconstantine pasted "counter" at http://paste.lisp.org/display/77397
17:18pstickneChouser_: for some reason it refuses to show up when printing, even with pr*
17:18pstickneChouser_: I'd expect pr to put back in the character escapes?
17:19pstickneor...
17:19hiredman,(prn \o0)
17:19clojurebot\
17:20Chouser_yeah, it's trying to print "\" and then the actual null char.
17:20Chouser_the printer could probably use a patch.
17:22RaynesThis is comical. Everyone waited until March 21 to post in my March 20 thread. :>
17:27cconstantineChouser_: I got my prime number generator to be within 5x the speed of yours instead of 100000x the speed of yours :)
17:28kotarakIs there a function returning the class denoted by a symbol or returning nil if there is no such class? Everything throws an exception, I'm too stupid to catch...
17:33cmvkkwhere are you getting symbols of class names?
17:34Chouser_kotarak: you tried 'resolve'?
17:34Chouser_it does vars too, though
17:34Chouser_,(resolve 'String)
17:34clojurebotjava.lang.String
17:34kotarakChouser_: I tried, ns-resolve. But I found out it works at the Repl. My jvm instance could use a restart it seems.
17:37Chouser_hm.
17:38kotarakYep. Code was not reloaded correctly.
17:38kotarakNot it seems to work.
17:38kotarakNow
17:38Chouser_,(resolve 'map)
17:38clojurebot#'clojure.core/map
17:38Chouser_I guess you can check if the returned thing is a class or not, if you care.
17:39kotarak(Although I'd still like a function returning nil if nothing is found)
17:40kotarakHooray. Omni completion is working almost completely now. Only fully qualified classes are still missing. :D
17:42AWizzArdkotarak: sounds great!
17:43AWizzArdbtw, is it an inconsistency that SOME does not end with a questionmark? (such as every? for example)
17:44Chouser_no, because some returns the value returned by the predicate, not a simple truth value
17:44kotarakAWizzArd: Clojure is awesome. The rough prototype was working in almost no time. The rest is just polishing and some corner cases.
17:45Chouser_,(some seq [nil [] () {} [1 2 3]])
17:45clojurebot(1 2 3)
17:45cmvkkChouser_ re: that thread you posted a minute ago, i don't know why you need an atom to write reduction without blowing the stack.
17:46AWizzArdChouser_: okay, this sounds plausible
17:48hiredman,(some seq [[1 2 3 4] [1 2 3]])
17:48clojurebot(1 2 3 4)
17:48hiredmanah
17:48hiredmanit returns the first of course
17:51Chouser_cmvkk: cgrand's explanation was insufficient?
17:51cmvkkwell i get that the version you had previously was O(n^2), but you don't need mutation to make it O(n) is what I mean...
17:51cmvkkmaybe i'm misunderstanding what the point of all that was?
17:52pstickneI and getting grief when trying to use ^ at the end of symbols.
17:52pstickneWhat magic is happening? :(
17:52Chouser_oh, no, earlier in the thread I had a couple implementations of reduction without using mutation.
17:53cmvkkso what was it that mutation solved? just making it faster?
17:53cmvkka faster O(n)?
17:54Chouser_I believe the version that blew the stack has a property I called "cute" :-)
17:54cmvkkheh
17:54cmvkkso then when he says "I searched for a way to define
17:54cmvkkrecursively such lists but the only way I found involves using mutation.
17:54cmvkkNow with an atom it must be cleaner."
17:55Chouser_right, my earlier definitions used a separate function which recursed.
17:55Chouser_this requires more code
17:56kotarakpstickne: ^ is not allowed in symbol names
17:56psticknekotarak: :(
17:56cmvkkso it's not that there's no way to recursively define a list like that without using mutation.
17:56cmvkki guess i was confused by that sentence.
17:56Chouser_several problems have these recursive lazy seq solutions, but the naive implementation blows the stack
17:56hiredman,(symbol "^")
17:56clojurebot^
17:56kotarakpstickne: here is more info http://clojure.org/reader
17:56pstickneI wish more symbols were valid -- what is a good way to do "prime"
17:56psticknelike a, a', a'', etc?
17:56hiredmanpstickne: I have been using -
17:56psticknemeh :p
17:57hiredmana-, a--, a---
17:57hiredman*shrug*
17:57hiredman,a^
17:57clojurebotjava.lang.Exception: Unable to resolve symbol: a in this context
17:57Chouser_so cgrand wrote rec-seq and rec-cat to allow solutions nearly as cute, but more efficient.
17:57psticknemaybe I'll go find some nice unicode...
17:57psticknewhat happens to the ^?
17:57kotarak^ retrieves meta data => reader macro
17:57hiredmanyeah
17:57cmvkkChouser_ hmm. I was just thinking about this the other day:
17:58hiredman,(symbol "a^")
17:58clojurebota^
17:58cmvkkI had coded up a macro form called lazy-loop, that worked like loop/recur but with 'give', whose first argument was a return value, and it all evaluated to a lazy-seq
17:58cmvkkis that what rec-seq is like?
17:58Chouser_,(read-string (pr-str (symbol "a^")))
17:58clojurebota
17:59Chouser_cmvkk: interesting!
17:59Chouser_'give' has to be in tail position?
17:59cmvkki.e. (lazy-loop [i 0] (give i (inc i))) would be equal to (iterate inc i)
18:00cmvkkgive would just be a macro that expands to (cons ~(first args) (fn-name ~@(rest args)))
18:00hiredmanhah, cute
18:00cmvkkor something like that. the version i have written up is a little more complicated because it does more.
18:00Chouser_quite interesting.
18:00cmvkkit seems like it would be a useful form. it could do stuff for can't, right?
18:01Chouser_I've converted a few loop/recur's to lazy-seq-producers, and I don't remember it being a straightforward process.
18:01cmvkklazy-loop would have to expand into something like (let [fn-name (fn fn-name [args] body)] (fn-name inits))
18:01Chouser_My flight should be boarding soon, so I may disappear with out further notice at any moment.
18:01cmvkkwhere the inital bindings are split into pairs for args and inits.
18:02cmvkkthe only issue is that fn-name has to be the same for every expansion.
18:02Chouser_yes, lazy-loop is quite different from for
18:04Chouser_loop/recur (and therefore lazy-loop I assume) is good for looping when there's no seq controlling the process. 'for' is not.
18:04cmvkkright.
18:05Chouser_there are only a couple ways I can think of to make a seq from a non-seq: lazy-seq with recursion, iterate, repeat
18:06cmvkkwell those are the only ways, right?
18:06Chouser_that I can think of, yes. :-)
18:06cmvkkrepeatedly is another built-in that does it I guess
18:07Chouser_oh, indeed. nearly as boring as repeat
18:07Chouser_iterate can be made to do impressive things if you're determined to use it.
18:07Chouser_Don't know why you would be, though.
18:08Chouser_I'd be curious to see how different a lazy-loop/give form is from an equivalent recursive fn with lazy-seq
18:08cmvkkwell the former would just expand into the latter.
18:09Chouser_yes, but I mean the user's hand-written form of each.
18:10Chouser_toodles!
18:10cmvkkhmm
18:12RaynesI'll miss him dearly.
18:18lisppaste8cmvkk pasted "lazy-loop" at http://paste.lisp.org/display/77400
19:05cconstantineif you do a send-off to an agent, does a deref of the returned agent want till the function passed to send-off returns?
19:05hiredmannope
19:06cconstantineif I want to ensure the the func has been called I have to wrapp the returned agent in a await?
19:20dnolenso does anybody know why definline is still considered "experimental" ?
19:23pstickneI wish arity errors contained the actual/expected :(
19:24hiredmanyes
19:24dnolenhiredman: you know?
19:24hiredmandnolen: no
19:28psticknesilly me. doto is not prog1
19:39hjleehiredman: do you remember yesterday's conversation with me?
19:40hjlee[(first (rsubseq sc < key)) (first (subseq sc > key))]
19:40hiredman,(doc subseq)
19:40clojurebot"([sc test key] [sc start-test start-key end-test end-key]); sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a seq of those entries with keys ek for which (test (.. sc comparator (compare ek key)) 0) is true"
19:40hjleesubseq and rsubseq are in log(n).
19:49hiredman2009:Mar:20:15:33:15 hjlee : ah.. but I want it in constant time. (so many keys, so many operations)
19:50hiredmanlog(n) is hardly constant now is it?
19:58hjleeyes, so i take back constant to log(n) some second later.
20:02hiredmanwell, then you have found what you are looking for, mazel tov, we should all be so lucky
20:36Rayneskib2 was in #concatenative. Traitor.
20:48hjlee`,(doc subseq)
20:48clojurebot"([sc test key] [sc start-test start-key end-test end-key]); sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a seq of those entries with keys ek for which (test (.. sc comparator (compare ek key)) 0) is true"
20:49hjlee`,(doc subseq)
20:49clojurebot"([sc test key] [sc start-test start-key end-test end-key]); sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a seq of those entries with keys ek for which (test (.. sc comparator (compare ek key)) 0) is true"
20:58hjleeclojurebot: hi
20:58clojurebotrhickey is a T-1000 sent from the future
20:58hjleeclojurebot: really?
20:58clojurebotGabh mo leithsc�al?
20:59hjleeclojurebot: who made you?
20:59clojurebotHuh?
21:00p_lwho taught clojurebot gaelic (or welsh or whatever exactly it is)?
21:10hjleewhat is your irc client?
21:11p_lmine? irssi
21:11Raynesrhickey: http://clojure.org/libraries Under Clojure+Processing "A wrapper for the Processing (processig.org)..." Processing is typo'd here.
21:14rhickeyRaynes: fixed -thanks
21:15RaynesNo problem.
21:16dreishWhat's the shortest way to eliminate reflection in (.foo (h :somekey)) ?
21:17hjleei'm clojure and irc newbie, and trying irc clients.
21:17danlarkindreish: typehint (h :somekey)
21:17dreishI don't seem to have a typehint function.
21:18dreishObviously I could do it with a let, pulling the expression apart, but is there a way to do it inline?
21:18danlarkinit's not a function... it's attaching special metadata to what you want to hint
21:18danlarkinso (.foo #^java.util.Date (h :somekey))
21:18danlarkinfor instance
21:19dreishI tried that, and it didn't appear to actually do anything.
21:19danlarkinit'll get rid of the reflection
21:19danlarkinif that's where it's coming from
21:19Raynesduck1123: I was wondering whether or not you were a Clojurist. I wasn't sure how you found my twitter :p
21:21dreishdanlarkin: So it does. I misled myself by trying to apply a wrong type hint to the result of +.
21:21dreish+ obviously didn't need it in that case.
21:22dreish(This is all because I was too lazy to look up the name of *warn-on-reflection*.)
21:33hjlee,(doc list)
21:33clojurebot"([& items]); Creates a new list containing the items."
21:55hjleeclojurebot: there?
21:55clojurebotHuh?
21:56hiredmanclojurebot: translate to kr are you korean?
21:56hiredmanbah
21:56hiredmanclojurebot: translate to ko are you korean?
21:56clojurebot??????
21:58pstickneclojurebot: translate to ru this is fun!
21:58clojurebot??? ??????!
21:58pstickneheh
21:58pstickneRussian always looks so funny to me!
21:58hjleek....
21:59pstickneclojurebot: translate to en hello!
21:59clojurebothello!
21:59hjleehiredman: how do you know about clojurebot features?
21:59pstickne*whew* basic test passes :p
21:59hiredmanI wrote them
22:00pstickne(hjlee: that means he forgot all the really cool ones)
22:01hjleewow,
22:01hiredmanclojurebot: where are you?
22:01clojurebothttp://github.com/hiredman/clojurebot/tree/master
22:04Rayneshjlee: Welcome to #Clojure may I take your order? I'd like to recommend our special - A hot bowl of parentheses and a side of Macros with Multimethods for desert.
22:06hjleeanyway I'm korean. first translation awed me.
22:07psticknehjlee: how did it translate? :p
22:08hjleeit translates something like : korea?
22:08p_lclojurebot: translate to pl This is fun!
22:08clojurebotTo jest zabawa!
22:08Raynesclojurebot: translate to ko Clojure rocks!
22:08clojurebotClojure ??!
22:09RaynesCan it to lojban? hiredman make it to lojban :).
22:11hjleelol, rocks translated to a noun.
22:11hiredmandnolen: ping?
22:13hiredmanhjlee: it uses google's translate service
22:13p_lwhich means a statistical engine, not one that understands what the hell it is translating :)
22:14hiredmanp_l: sounds like google all right
22:14p_lhiredman: doesn't mean such approach doesn't work
22:15hiredmansometimes
22:15hiredmanI wish it did esperanto
22:38p_l~and suddenly...
22:38clojurebotCLABANGO!
22:47pstickneoh, because those are clear
22:47slashus2.?.
22:47slashus2hehe
22:50pstickne if I ever design a language, every symbol operator would have to be associated with a named function :p
22:50hiredmanthey are named
22:50hiredmanthe name is .?.
22:51pstickneno, no, a what-is-that-thing-supposed-to-do-name
22:51pstickneso .?. would be valid as long as it was "associated" with a long name
22:52hiredmana long name? like .....?......?
22:52psticknesomething useful, hopefully
22:52psticknee.g. /: might be called fold-left
22:53pstickne(or the correct name, even)
22:53hiredmanso, basically you are moving backwards to only allow a subset of ascii?
22:53pstickneno.
22:53psticknesymbol names are great. but they should be tied to something with a "speakable" name.
22:53slashus2self-documenting function names is what pstickne is trying to get at.
22:54psticknewhile + is "speakable", .?. "period question-mark period" does not justice
22:54pstickneso I would allow .?. if-and-only-if there is a named function that is associated with it (e.g. they would be interchangeable)
22:54pstickne*no
22:59cconstantineI made a function that returns a lazy-sequence much like 'range' does, but it doesn't have an upper-bound ( http://paste.lisp.org/display/77397 ) I did some timing with it and found that it is 8 to 10 times slower than 'range'
23:00cconstantinethe only difference I can find is that for numbers that fit within MAX_INT, a java native class Range is used instead of a clojure-implemented iseq.
23:01cconstantineAny number I create, either as a '1' or (int 1) is a java.lang.Integer instead of a primative int... and I think this is the source of the slow-ness. Is there anyway to get a real primative or is this just a limitation of clojure?
23:01psticknecconstantine: sounds like side-effect Java is kicking the poo out of Clojure :-)
23:01pstickne(plus, working directly with a native type)
23:02psticknecconstantine: I would hate to blame the autoboxing right away, though (but from what I understand, this is the only support Clojure has)
23:03cconstantineI'd hate to blame it too... but man
23:03zpinterwould somebody please point me to the best way to apply a function to all the values of a hashmap and return a new hashmap of the result?
23:03psticknecconstantine: what if you write a side-effect class in clojure
23:04cconstantinepstickne: umm, no?
23:04zpinteri'd like to convert a key value map where all the values are strings to a key value map where all values are integers
23:04psticknecconstantine: well, you want to compare speed, so use a Java member :)
23:04psticknecconstantine: of a class, or write a Java version that only uses Integer
23:05psticknecconstantine: then you can see what part is to blame better
23:05zpinterthe closest i can come up with so far is this: (map (fn [[k v]] [k (Integer. v)]) myhash) but it returns an array of arrays instead of a hash
23:05cmvkkyes.
23:05cmvkktry wrapping that with (into {} ...)
23:06pstickneapply and hash-map should also do the trick...
23:06cconstantinepstickne: well.. I think if I can make use of Range when within MAX_INT I could speed up my counter
23:14zpintercmvkk, pstickne... got it with: (apply merge (map (fn [[k v]] {k (Integer. v)}) myhash))
23:15cconstantineodd, so if I create a clojure.lang.Range myself I'm still almost 8x slower than 'range'
23:19cconstantineok, I'm at a loss... a raw clojure.lang.Range is slower than my 'counter' for numbers up to 10 million
23:19RaynesThat's a lot of numbers.
23:20psticknehe's a counter!
23:20pstickne:-)
23:20cconstantinewell.... I'm anoyed at the required 'end' on range
23:21cmvkkyou can just make it MAX_VALUE or whatever.
23:21cmvkkInteger/MAX_VALUE i mean
23:21cconstantineit seems like lazy-sequences are a better than looping in clojure
23:22psticknewith loop/recur?
23:22RaynesWhy not just do (iterate inc 1)?
23:23cconstantineRaynes: That's also really slow compared to range
23:23cmvkk(take end (iterate inc 0)) is what range uses, whenever end isn't an acceptable integer.
23:23cconstantineexactly
23:24cmvkkso you want something that's infinitely long, right? you can't implement that with clojure.lang.Range, right?
23:25cconstantinecmvkk: Shouldn't there be a way to use clojure.lang.Range for numbers up to MAX_VALUE?
23:25cmvkk(new clojure.lang.Range 0 Integer/MAX_VALUE) ?
23:25cconstantinecmvkk: is unfortunately fairly slow
23:26cmvkkcan't be slower than range...since that's how range is implemented.
23:26cconstantineYou'd think ;)
23:27cmvkkwell, range returns a clojure.lang.Range with the arguments you give it...so if you do that, compared to range, you're going to get exactly the same type of object.
23:27cmvkkyou're not even doing anything different.
23:27lisppaste8cconstantine pasted "Counter experiment" at http://paste.lisp.org/display/77411
23:27RaynesYou can't go faster than light speed.
23:28cconstantinecmvkk: I know :) I got the clojure.lang.Range from the clojure implementation of range
23:28cconstantineRaynes: What about Ludicrous speed? :P
23:29slashus2You definitely can't go faster than Ludicrous speed.
23:29slashus2Dark helmet about died going that fast.
23:30Raynescconstantine: I would have gotten too tired waiting for those to complete.
23:30cmvkkcconstantine: is it a take issue?
23:30cmvkkyour middle test, the one with range, is the only one that isn't wrapped in a take argument.
23:30cconstantinecmvkk: I'll try that
23:30cmvkkor a take function, i mean
23:31cconstantinethat was it
23:32cconstantinewhich suggests with my numbers that my counter is 2/3 as fast as range.. which isn't nearly as disgustingly slow.
23:32cconstantinewell.... 5/7 as fast
23:33cconstantineThanks :)
23:38cmvkkexcellent. i forgot about reflection until now,
23:38cmvkki had rewritten my framework to use lazy-seqs instead of closures and atoms, and was dissapointed to find that it was 4 to 5x slower.
23:39cmvkkbut i tested for reflection, and realized i had just written one of the functions wrong, without type hints. now i think it might actually be faster than the old version.
23:39cmvkki like it when that happens.