#clojure logs

2008-11-16

02:25Lau_of_DKMorning gents
02:29ChouserHey, Lau, having some emacs/irc issues there?
02:29Chouser:-)
02:34Lau_of_DKHey Chouser
02:34Lau_of_DKIm not sure what happend, suddenly the screen turned dark, smoke came out of the back of my laptop - I heard the hard-drives reader-head break off and destroy all my data. And sinking back into the couch I remember thinking "this still beats Vim"
02:35Chouserha ha
02:37Lau_of_DKChouser: but this actually rocks. Im sitting code, sending code directly to my Repl having it evaluated. And if I need your advice on something, I hit F1 type "Cho<tab>" and we're chatting
02:37Lau_of_DKAny text you write, I can send to the Repl :)
02:37Chouseryes, that sounds nice.
02:38Lau_of_DKIsnt it around midnight where youare at ?
02:38Chouser2:30 AM. I should definitely not be awake.
02:38Lau_of_DKThats gonna hurt in the 'morning' :)
02:39Chouserindeed
02:39Lau_of_DKDid you produce some outstanding code tonight though ?
02:39ChouserI'm in the thick of it. Got ClojureScript spun up to work post-AOT, and now I'm writing a little C program.
02:40Lau_of_DKHow does C fit into this ?
02:40ChouserI want something with very fast startup time to use as a little cgi bridge for a ClojureScript REPL in a browser.
02:41Lau_of_DKoh, so you start that on the webserver and then connect to it?
02:42Chouseryeah, pretty much.
02:42Lau_of_DKSounds like an awesome idea
02:42Lau_of_DKHow far along are you ?
02:43Chouserthe repl works pretty well locally, but I need this lame C program to get it all hosting nicely at n01se.net
02:43Lau_of_DKConsidered ... I dare not say it... Perl for the job?
02:44Chouseryeah, but I want very fast lightweight startup.
02:44Chouserand the requirements are pretty thin, so I thought I'd try C
02:45ChouserI'm sure I'll regret it eventually.
02:45Lau_of_DKFair enough
02:45Lau_of_DKhehe
02:48Lau_of_DKLets say I want to store 500Mb of data in RAM - How do I go about this in Java?
02:57Chouser(make-array Byte/TYPE (* 500 1024 1024))
02:58hiredmanis there an encoding for clojure source?
02:58Chouserhiredman: I think it defaults to UTF-8
02:59hiredmanare there rules for vars?
03:00hiredmanthe last release of clojure seems to think ? (the interrobang) is =
03:00hiredmanuser=> (def I? I)
03:00hiredman#'user/I=
03:26Lau_of_DKNever heard of any interrobang :)
03:31hiredmanYou've never heard of the interrobang?
03:31Lau_of_DKno
03:32hiredmanwell, now you have
03:32Lau_of_DKYea, thanks
03:33Lau_of_DKBut all the Americans are sleeping now (presumeably) so you might gain more from posting your question to the ggroup
03:33hiredmanI guess
03:33hiredmanuser=> (def ? :heart)
03:33hiredman#'user/e
03:48Lau_of_DKDo you see any special use for this?
04:05kotarakHmm.. recur in a catch clause doesn't work?
04:10Lau_of_DKWhats your experience MR. Kota ?
04:11kotarak(try ... (catch Exception e (loop [x e] .... (recur (do-something-to x)))) complains
04:13Lau_of_DKIf possible, maybe you should just wrap the execution of that whole func in a try/catch ?
04:13kotarak(try :x (catch Exception e (loop [x e] (if (.getCause x) (recur (.getCause x)) x))))
04:13kotarakjava.lang.UnsupportedOperationException: Cannot recur from catch/finally (NO_SOURCE_FILE:1)
04:14kotarakI think, this is a valid use of loop.
04:14Lau_of_DKk, so do what I said
04:14Lau_of_DKIts quite clear "Cannot recur from catch"
04:14Lau_of_DKI have to jet, bubye
06:02AWizzArdClojure lists know their length, yes? (count list) ==> O(1)
06:04PupenoHello.
06:04AWizzArdHi Pup
06:05PupenoAWizzArd: I haven't been called Pup in quite a while :)
06:06PupenoAWizzArd: I would expect count to be O(n) on lists, but O(1) on vectors, but there might be some optimization.
06:12polliAWizzArd: for PersistentLists it's O(1)
06:14pollijudging from scimming through its implementation
06:24kotarakAWizzArd: according to clojure.org count is O(1) for lists, vectors and maps
06:33AWizzArdkotarak: thx
08:09pjb3So with the latest clojure, if I have some directory on my classpath, and in that directory I have a foo directory that has a bar.clj file in it, that file should declare (ns foo.bar) at the top, correct?
08:09rhickeypjb3: yup
08:10pjb3and then I should be able to do (require 'foo.bar), right?
08:11rhickeyyes
08:13pjb3ah, I got it now, had a typo in my classpath, thanks
08:20rhickeypoll - if you enter (cast 4 String) at the repl, do you get a CastClassExceptionMessage naming both types or only Integer, and if both, what message do you get and what VM are you running?
08:20rhickeyI get: java.lang.ClassCastException: java.lang.Integer
08:21pjb3java.lang.ClassCastException: java.lang.Integer (NO_SOURCE_FILE:0)
08:21kotarakjava.lang.ClassCastException: java.lang.Integer
08:21rhickeywould prefer: java.lang.ClassCastException: had java.lang.Integer wanted java.lang.Class orsomething
08:21pjb3The 1.5 JDK that comes with Mac OS X Leopard
08:21kotarakmac 10.5.5 stock java 1.5
08:21rhickeyI'm only interested if it's different from mine
08:22rhickeyI know I've seen messages with both types in stack traces from users, but didn't ask then
08:23mehrheitjava.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Class (NO_SOURCE_FILE:0)
08:23mehrheiton Sun JDK 1.6
08:23rhickeymehrheit: what OS?
08:24mmcgranajava.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Class (NO_SOURCE_FILE:0)
08:24mehrheitubuntu 8.10
08:24rhickeymmcgrana: what JVM/OS?
08:24mmcgrana1.5 OS X leopard
08:25rhickeyok, so maybe fixed in JDK 6, same here on JDK 6
08:26mmcgranao wait sorry rhickey i'm actually 1.6
08:27mmcgranai had switched back and forth yesterday trying to get the core precombile thing to work. sorry about the confusion
08:27mmcgrana*precompile
08:30pjb3I jut noticed the REPL prints the expression that you entered as well as the value the expression evaluates too
08:30pjb3Has it always done that or is that a recent thing?
08:31kotarakI had this with a broken rlwrap.
08:31rhickeypjb3: it doesn't do that
08:32pjb3Ah, that is an aquamacs thing I guess
08:32pjb3rhickey: your right, doesn't do that when I run the REPL from the command line
08:32pjb3does it when it is the inferior-lisp in aquamacs
08:45rhickeypjb3: not for me, but I haven't updated my clojure-mode in ages
08:46pjb3rhickey: weird, maybe that's just another setting somewhere in aquamacs
08:47rhickeypjb3: you type 42 enter and get 42 newline 42?
08:47rhickeyuser=> 42
08:47rhickey42
08:48pjb3rhickey: yeah, I get it twice
08:48pjb3user=> 42
08:48pjb342
08:48pjb342
08:48rhickeyyikes
08:48pjb3user => (+ 1 2)
08:48pjb3(+ 1 2)
08:48pjb33
08:48pjb3yeah, it's annoying, what did I do! :)
08:48kotarakpjb3: I had this with an old version of rlwrap. Maybe this effect is similar. How do you start clojure?
08:50pjb3kotarak: http://github.com/pjb3/clojure-bin/tree/master/clojure
08:50pjb3I set that script as the inferior-lisp-program
08:51pjb3then press C-C C-Z when I'm in a .clj file
08:51kotarakDo you have jline somewhere in your cp? Maybe this interferes?
08:51pjb3it does it in aquamacs only, not if I start that command line
08:51pjb3Yeah, I do have JLine, let me try to take that out
08:53pjb3kotarak: Yeah, jline seems to be the problem
08:53kib2\join #lyx
09:15pjb3What's up with this?
09:15pjb3user=> (contains? [\b \y] \b)
09:15pjb3false
09:15pjb3user=> (contains? #{\b \y} \b)
09:15pjb3true
09:16pjb3oh right, contains is has-key?, that confuses me every time :/
09:17pjb3Is there a function for "does this sequence has this value in it?"
09:18mmcgranaincludes? in seq-utils in contrib
09:18rhickeyuser=> (some #{\b} [\b \y])
09:18rhickey\b
09:19Chousukenifty use of sets, that :P
09:19mmcgranabtw rich what was the inspiration for the name some - does that come from another lisp?
09:19rhickeyplus you can put in more than one search item
09:20rhickeymmcgrana: CL has some
10:02duck1123if I want a param with a default optional param, I need to use multimethods? or something else?
10:03kotarakduck1123: (defn foo ([x] (foo x 5)) ([x y] (+ x y)))
10:03duck1123ok, thanks
10:10Chouseror: (defn foo [a & [b]] (+ a (or b 5)))
10:24mibuI have two questions regarding future development of clojure: 1. I saw there are plans to deprecate the . function - has it become too late to drop it anytime soon and nip it in the bud? 2. What is the plan with the contribs? Is it going to be a repository like system, or are there inclusive intents to get anything good into clojure core like in python and java?
10:25Chousukemibu: some stuff from contrib might end up in core. nothing has been decided yet, though.
10:25ChousukeI don't know about .
10:25ChousukePersonally I'd like to see it disappear, though.
10:26ChouserThe namespace loading stuff (use, require, alias, etc.) started off in contrib
10:27kotarakthere is vote going on for extensions from contrib to be included in core
10:27rhickeyThe value of . is that all of the other sugar just turns into that at macroexpand time, so code analyzers need only deal with . and not static/member, .member, ctor. etc
10:27mibuchousuke: I also don't like it. But its presence is just calling for people to use. Has clojure reached the point where it can't be just be removed because of concerns of breaking code?
10:28kotarakthen almost all my code will break
10:28Chousukemaybe people should just be encouraged not to use . outside of macros :p
10:28duck1123Once nobody ever sees use of . they'll never think to use it like that
10:28miburhickey: so will . remain for macros?
10:28rhickeyChousuke: yes, I just need to change the docs to emphasize the other forms
10:28Chouseroh, I was under the impression . was going away for statics
10:29rhickeyChouser: undecided on that, in fact there is a new need for it to disambiguate calls to static members of classes corresponding to namespaces
10:30rhickeyadmittedly rare, but my.ns/foo will not resolve to the class my.ns
10:32Chouseryeah, I've noticed related issues for ClojureScript. I can't use the Class/member syntax for JS classes because the compiler assumes they're namespaces.
10:32miburhickey: I'm confused. what are the long-term plans for . ?
10:32Chousukemaybe I should remove uses of . from the clojure wikibook... to manipulate new users into not using it.
10:33rhickeymibu: there are no plans to change .
10:33mibuoh ok.
10:35Chouserany plans to make StructMap$Def implement IFn? :-)
10:36rhickeyChouser: I dont know if you saw my comment to cemerick on structmaps in the light of AOT (will try to find it)
10:38miburhickey: about the contribs issue, what's your take on the core library in general - an inclusive battery-included kind of core with plenty of common use facilities or a more compact core which is supplemented with 'require'd extensions?
10:41rhickeymibu: the latter. OTOH, you shouldn't have to require anything for basics, so some of what is in contrib (i.e. case) can move in. Maybe contribs could have those things that are proven separated somehow from those that are gestating, the former being included with the distribution.
10:41Chouserrhickey: I saw it, but I suppose I didn't understand the implications.
10:42rhickeythe implications are you have to wait for me to figure that out before I do any more enhancements to structmaps :)
10:44miburhickey: is there some kind of plan for a standard repository and install mechanism? you know, to avoid a fiasco like we have with CL library installation...
10:45rhickeymibu: AOT and the solidification of the directory structure serve as a basis for library management mechanisms, including some of those successful in Java-land.
10:48miburhickey: yeah, but will there be a standard to avoid making it a chore to figure out how to quickly install depended extensions? Something as simple as (install 'sql)
10:48Chousukemibu: I don't think that's going to be a problem
10:48rhickeymibu: the community will figure that out
10:48Chousukemibu: you can just download a jar, add it to classpath, and use it
10:49duck1123We have all the options open to java available to us
10:49rhickeythere are a lot of models, and Clojure has the benefit of a community with knowledge of those of CL/Scheme/Ruby/Python/Java etc
10:49duck1123has anyone tried Ties yet?
10:50Chouserif structmap basis become named classes and structmaps instances of those, people will immediately begin dispatching multimethods on basis type.
11:07rhickeyChouser: I'm not sure that is bad vs everyone reinventing their own metadata-based mechanism for his common case - the main problem with real classes here is their lack of dynamism - can't add a field without a restart
11:07rhickeythis common
11:08rhickeyI don't have a solution for this yet, but would like structmaps to be 'serializable' at some point
11:09mibuthere is a mention in boot.clj that import is not the preferred way to import, yet in every example I see there is import. what am I missing?
11:11rhickeymibu: a) those examples may have predated ns having :import capability, or b) for a one-off script you might not have a ns
11:11kotarak(ns (:import ...)) is preferred over (import '(...)), as I understand it.
11:11rhickeyif you have a ns, don't use import
11:12kotarakrhickey: but I found it necessary sometimes: (when *compile-files* (gen-class-stuff-here)) (import '...) because ns assumes that everything is already there.
11:13rhickeykotarak: gen-class should become much better when integrated into AOT
11:13kotarakrhickey: hopefully. :)
11:13miburhickey: the distinction of uses (import,:import) is not clear in the docs.
11:14kotarakAlthough: *compile-files* eliminated a separate compilation step for gen-class.
11:15miburhickey: if you add "if you have a ns, don't use import" to the docs. it'll solve a lot of headaches later :-)
11:17kotarakIs it possible to get the remaining string out of a string reader? (def x (new java.io.StringReader "hello")) (.read x) (.read x) (??? x) => "llo" ?
11:20danleiem
11:20danleimiss
11:36DrakesonIs there a simple way to import and rename java camelCase classes and methods into dash-seperated names?
11:49Drakesonlike, can I ship an fn to :rename? (e.g., as in (refer ... :rename (fn [x] ..)))
11:50Drakesonthe API only says "map"
11:51rhickeyDrakeson: rename fn is interesting, a concrete map is expected right now
11:52rhickeybut the rename of Java API is likely to be a bad idea because: other people can't read your code, IDEs can't help you etc
11:58Drakesonit is not an arbitrary/hackish renaming. It is to make all the names in clojure and libraries consistent. Currently the names seem ... a bit funny.
12:01Drakesonalso it slightly improves readability. something-or-the-other can be read easier than SomethingOrTheOther, IMHO.
12:04danleihow do i get a string of a seq of chars?
12:04rhickeyDrakeson: I prefer dash-separated-names too, but we didn't name these things, someone else did, and I'm now in the camp that says it's best to leave them as named by their owners - all conversion strategies have problems, difficult-to-guess transformations, need to be supported by all tools etc
12:04danlei(??? (seq "hello")) -> "hello"
12:04kotarakdanlei: (apply str (seq "Hello"))
12:05danleikotarak: ah, thanks
12:40pjb3testing...1...2...3...
12:42rhickeypjb3: testing what?
12:42pjb3rhickey: just some IRC thing, plz ignore, sorry
12:43rhickeynp
12:43pjb3specifically http://mibbit.com
12:43pjb3web-based IRC thing
12:43pjb3that's what all those mib_* join/left messages were about
12:47kotarakChouser: thanks for the discussion yesterday. I have now a working vim repl with multiple expression send. Ugly, but working. :)
12:50Chouserkotarak: sounds just like vim itself. :-)
12:50kotarakyeah, in some way :)
13:24Lau_of_DKGood evening gents =)
13:31Lau_of_DKDesign question for those of you who like agents. I have a swing program, which runs several agents (in the 100s). All these pile up some type of data. I have another agent, which in a transaction reads the queue, outputs the data to a visual log, and clears out the global ref which they all log into.
13:31Lau_of_DKIs this the correct way to handle that type of thing?
13:34AWizzArdIs that all to have a user not waiting? Or do you just want to write logs?
13:52Lau_of_DKNoone here likes agents?
13:53SnowBuddyWhen you see an agent, you run.
13:54Lau_of_DKNot me - I bend backwards really fast, making a clear statement
13:55Lau_of_DKBut doesnt anyone here have a take on my design question?
13:56arbschtLau_of_DK: is the read-clear routine atomic?
13:57Lau_of_DKI was thinking about that earlier, because for accuracy it needs to be ofc. How could I accomplish that?
13:57arbschtis it in a single transaction?
13:59Lau_of_DKYes
13:59Lau_of_DKI mean, theres really no need to do the reading in a transaction, but it can be done ofc
14:18Lau_of_DKIn practical terms, how do I choose between alter/commute, they seem very similar
14:18Lau_of_DKOr, rephrase: When do I prefer one above the other?
14:22mortis`humbly requesting help...going through the PP book, trying to get lancet to load
14:22mortis`I have added what I think is the correct path to the classpath: (add-classpath "file:///home/mortis/personal/projects/clojure/lancet")
14:23mortis`though, when I: (require 'lancet)
14:23Lau_of_DKPP??
14:23gnuvince_PragProg
14:23mortis`I get: Could not locate Clojure resource on classpath: lancet/lancet.clj (NO_SOURCE_FILE:0)
14:23mortis`PP => pragmatic programmers book
14:23mortis`the PDF
14:24mortis`...and this returns true: (. (new java.io.File (str "/home/mortis/personal/projects/clojure/lancet/" "lancet/lancet.clj")) exists)
14:24mortis`which is what I think it'd be doing when I attempt to use lancet
14:24Lau_of_DKNever heard about the book Im afraid, but if its free and you have a link I can have a look
14:24mortis`er, it's not
14:24Lau_of_DKk
14:25mortis`the books is irrelevant to the issue I"m having, it was just a bit of context
14:25Chousukemortis`: I think the classpath needs the final /
14:25mortis`I'll try that
14:25mortis`ok, that worked, thanks
14:25mortis`all classpath-urls have to end w/a filesep?
14:25mortis`well, I suppose that's teh case
14:25Chousukeand please use .method syntax instead of . ;( . is difficult to read
14:26mortis`any chance we could have add-classpath do that for file:// urls?
14:26Chousukemortis`: java thinks they are jars if they don't
14:26mortis`ah ok
14:26mortis`is there a difference between the jscheme style (.method instance args) vs the (. instance (method args))?
14:27Chousukeno. except that the latter is not as nice.
14:27rhickeymortis`: the former is preferred
14:27Chousuke.foo also works for fields, not just methods.
14:27mortis`oh, great
14:28Lau_of_DKrhickey: Can you answer my design-question above, is it the correct use of agents, and can it be done atomic, the print/clear log ?
14:29rhickeyif you want a queue, use j.u.concurrent queues
14:29Lau_of_DKI think I cant avoid having a queue when its a log we're talking about, but I'd much prefer to use the wrappers if thats at all possible ?
14:30rhickeyClojure doesn't wrap, j.u.concurrent, but works with it
14:30AWizzArdWould that be also the right thing for something that is just a side effect and needs no data itself? Say, my app wants to write every minute some data into a file, then an agent would feel a bit artificial, as I would have no data that needs a change.
14:31rhickeyAWizzArd: agents make fine thread wrappers, or you can use Thread
14:31rhickeyAWizzArd: agents also encapsulate thread pools
14:31Lau_of_DKrhickey: works with it? Just to avoid misunderstandings: I consider the whole agent setup as wrapers of Javas threads, correct? So when you say that Clojure works with java queue class, do you mean something beside the usual java interop?
14:32rhickeyI mean java.util.concurent queues - these are data structures, not threads - agents can communicate through queues
14:33rhickeyi.e. don't use STM to implement anything proved by j.u.concurrent
14:35Lau_of_DKk, thanks rich
14:36Lau_of_DKNow about agents, without thinking too much about it, all repetive agent-funcs end with the line (send-off *agent* self) right? My agent for some reason becomes an error after the first cycle, where do I look for a more precise error message?
14:37rhickeyLau_of_DK: I will eventually provide a wrapper API for j.u.concurrent since so few people know about it
14:37duck1123just saw that #! is now a comment. Very cool
14:37quuuux_hi, while making my first steps with clojure i stumbled upon the following maybe-problem... calling "with-in-str" in r1106 fails with "java.lang.IllegalArgumentException: with-open now requires a vector for its binding". Wrapping name and init in the call to "with-open" (core.clj, line 2397) in a vector seems to fix the problem for me.
14:38Lau_of_DKrhickey: thats very kind of you =)
14:39Chousukequuuux_: it seems with-in-str has a bug :)
14:40rhickeyquuuux_: got it, thanks
14:41quuuux_np
14:41Chousukehmm
14:43Chousukewould it make sense to extend with-open to support multiple bindings? like (with-open [a (File.) b (File.)] ... ? currently with-open will not complain about that, but only the first file will actually be closed :/
14:43Lau_of_DKYou wouldn't need it that often would you? But on the other hand, it couldnt really hurt?
14:44Chousukeit might hurt if people assume with-open supports multiple bindings but doesn't actually close anything but the first...
14:44Lau_of_DKrhickey: Now I understand that using j.u.concurrent is the correct approach, but just out of pure interest in agents/STM - Can I make 2 transaction be virtually atomic? (like f.i clearing a log and outputting the data)
14:46rhickeyLau_of_DK: nest transactions join the enclosing transaction
14:46rhickeynested
14:48Lau_of_DKrhickey: Normally I have absolute no problem understanding Americans, but for some reason you sometimes come across almost cryptic. Can you further explain "join the enclosing transaction" ? Does it mean that the STM locks down the I/O while comitting everything in the dosync?
14:49rhickey(dosync ... (dosync ...) (dosync ...)) is one atomic transaction
14:50ChousukeIf I want to map a function that has side-effects, the correct way to do that is (dorun (map ...), right?
14:51rhickeyi.e. if you have two functions that themselves are transactions and call them within another dosync, they become part of that outer transaction and all occur together
14:51AWizzArdChousuke: dorun or doseq?
14:51rhickeyChousuke: yes, if you don't need the resulting seq
14:51Lau_of_DKoooh :) Thats fantastic, thanks rhickey
14:51ChousukeAWizzArd: I don't think I want to use doseq for this
14:51AWizzArdcan one make circular structures in Clojure?
14:53Chousukegoing to experiment with changing the finally block in with-open to do (dorun (map #(.close (first %)) ~(partition 2 bindings))) instead of just (.close ~(first bindings))
14:53astorI've seen that I need async lazy sequences - kind of producer/consumer, but where the consumer is in the form of a lazy sequence. To me, a channel abstraction of some sort would be natural for this, and the produer/consumer example I've seen is kind of cumbersome. Is a channel something that should be built on top of agents, or where does this fit into the clojure world?
14:57rhickeyastor: you could look at seque
14:57rhickey(doc seque)
14:58Lau_of_DKI think (ref-set alter and commute) are a bit confusing. If I have a ref to a vector [1 2] and I want to conj 3 onto that vector, whats the recommended approach?
14:58rhickeyLau_of_DK: (alter aref conj 3)
14:59Lau_of_DKThanks
15:03gnuvince_What's the difference between setting the value of ref and setting the in-transaction-value of ref?
15:06gnuvince_THe number of people in here just keeps growing, doesn't it?
15:07Lau_of_DKgnuvince_: I presume in the first example you speak of the value which is commited once the transaction closes, and the other is visible within the transaction ?
15:12astorrhickey: thanks
15:16Lau_of_DKI just want to share this with you Emacsers. Most of you have got slime working so that you can eval code directly from your buffer. But did you know that with ERC you can also have #Clojure scrolling right in a buffer, so that you can copy/eval code directly from the channel without ever leaving emacs? I think this is great, so I just wanted to share :)
15:17AWizzArdit's nice, but for lot's of code it is even nicer to post it online somewhere, instead of spamming the channel :-)
15:19Lau_of_DKIts a matter of taste, for debugging I prefer lisp.paste, for sharing cool snippits, I prefer in chan, but thats just me
15:25Chousukehmm
15:26Chousukemy multiple-binding with-open appears to work. yay
15:26Lau_of_DKyay :)
15:26danleiLau_of_DK: also beware that you could end up like me: sending random snippets and stuff to unrelated channels, because you keep hitting the wrong buffer from time to time ;)
15:26Chousukeit's a ~one-line change though :p
15:26Lau_of_DKdanlei: oh my - you do that too ? :)
15:27Lau_of_DKChousuke: Thats Lisp for you :)
15:29Chousukecan't send a patch though as I have no CA.
15:32blarfowha is ~ ? gensym? or @ in common lisp
15:32Chousuke~ is unquote
15:32Lau_of_DKblarfo: I think gensym is var#
15:35Chousukewonder if I could just release my patch as public domain to circumvent the need for a CA :P
15:36fandaHello! Just a question about 'symbol' fn
15:36fandauser=> (symbol "abc")
15:36fandaabc
15:36fandauser=> (symbol nil)
15:36fandajava.lang.NullPointerException (NO_SOURCE_FILE:0)
15:36fandaWhat would you expect to return (symbol nil)? Is this an expected behavior?
15:36fandaThanks!
15:38rhickeyfanda: symbol takes a name string, nil is not a name
15:38rhickeyso, yes, NPE
15:39fandarhickey: hm... so exception is pretty much ok
15:39fandajust thinking about different tests for functions
15:42leafwif one has a vector [1 2 3] .. what is the proper way to check if number 'a' is contained in the vector?
15:42leafw(some #{a} v) is failing for me
15:45Lau_of_DK(some #(= 5 %) [1 2 3 4 5])
15:45danleileafw: if i understand you right: (let [a 1] (some #(= % a) [2 3 1]))
15:46rhickeyuser=> (some #{2} [1 2 3 4])
15:46rhickey2
15:46blarfocan i shorten this: (fn [x] (= x true )) ?
15:46Lau_of_DKGuys, if you check out the macro time in core.clj - I would like to modify it, so that instead of just printing the execution time, that it actually attaches it as meta-data, but Im having some difficulty - Can anybody see how that could be accomplished?
15:47rhickeyleafw: what didn't work?
15:47leafwnever mind. Extra tick in macro.
15:47leafwthanks guys.
15:47leafwdebuging macros is hard.
15:47Lau_of_DKblarfo: #(= true x) ?
15:48hiredmanI have the latest clojure release, and if I try to def ? to :x it binds :x to the symbol e similar thinsg happen when trying to use other unicode entities as symbols
15:48rhickeyblarfo: true? does that
15:48hiredmanthe interrobang ? turns in the symbol =
15:49hiredman? seems to work ok though :P
15:53Lau_of_DKCome on guys, its a very simple macro, any takers? :)
15:55AWizzArdLau, what exactly did you try so far, and what happened?
15:56rhickeyhiredman: did that work in the past?
15:57Lau_of_DKAWizzArd: Im trying to return (with-meta ret# (calculus)) instead of prn then ret#
15:57Lau_of_DKBut Im not sure if I can still get an accurate time
16:01AWizzArdIn principle the timing should be over before you attach the meta data and/or print it out into the repl. So I guess the timing would stay as accurate as your current hardware allows.
16:02Lau_of_DKuser> (timer (take 10 primes))
16:02Lau_of_DK(clojure/let [start__4753 (System/nanoTime) ret__4754 (2 3 5 7 11 13 17 19 23 29)] (clojure/with-meta ret__4754 {:time (clojure/str (clojure// (clojure/double (clojure/- (. java.lang.System (user/nanoTime)) start__4753)) 1000000.0))}))
16:02Lau_of_DKThis looks funny
16:03AWizzArdOh, clojure// is division yes? :-)
16:03Lau_of_DKBut the timing here is pretty important since its a benchmarking/stress-testing program Im writing
16:03Lau_of_DKyes
16:04AWizzArdWhat I find very strange is that there are still no complex numbers in the standard java lib.
16:06Lau_of_DKIn a macro like (defmacro test [expr] (let [ret# ~expr]).. Does ret# already at the point hold the return value of expr?
16:07hiredmanLau_of_DK: you may have already run into this, but (with-meta ret# {:x :y}) as the tail of the macro raises and exception
16:08hiredmanbut (with-meta [ret#] {:x :y}) does not
16:10Lau_of_DKI cant even get a result, I just get a macro-expansion
16:10hiredmanhuh?
16:10hiredmanhuh?
16:11Lau_of_DKhehe
16:11Lau_of_DKuser> (timer (take 10 primes))
16:11Lau_of_DK(clojure/let [start__4817 (System/nanoTime) ret__4818 (2 3 5 7 11 13 17 19 23 29) user/benchmark (clojure/str (clojure// (clojure/double (clojure/- (. java.lang.System (user/nanoTime)) start__4817)) 1000000.0))] (clojure/with-meta [ret__4818] {:time user/benchmark}))
16:11Lau_of_DK
16:11Lau_of_DKLike this - This is not what I paid for
16:12Lau_of_DKIn a macro like (defmacro test [expr] (let [ret# ~expr]).. Does
16:12Lau_of_DK ret# already at the point hold the return value of expr?
16:12hiredman`(let
16:12Lau_of_DKI have that
16:13hiredmanI think yes, but it sort of depends on what you mean by "that point" and the quote
16:13Lau_of_DKI mean, does ~expr = evaluation
16:13hiredmanyes
16:15hiredmanhttp://www.thelastcitadel.com/clojure/time-meta returns a vector with the metadata associated to vector, and the result in the vector
16:15hiredmanif I try it without a vector it throws an error
16:16hiredmanin fact, the same error I get from (with-meta 5 {:x :y})
16:16hiredmanso nums don't get metadata
16:17hiredmanand the function I was testing it on, returns a num
16:17danleijust symbols or collections, afaik
16:18Lau_of_DKhiredman: I dont quite understand your code. You define tim#, but in the map you use :time and :a, which are defined nowhere, what gives?
16:20hiredmanoh
16:20hiredmanI think I made a bug
16:21hiredman:a should be tim#
16:22Lau_of_DKk
16:24Chousukehmmh
16:24Chousukeis there a reliable way to determine whether a symbol is a gensym or not?
16:24hiredmanseems like you almost might as well just have it evaluate to a hash {:time n :result output}
16:24hiredmanif you need a collection to attach metadata to anyway
16:25Chousuke5 can't have metadata, it's a constant :/
16:25hiredmanyeah
16:25hiredmanI figured that out :P
16:28danleimy shot: http://paste.lisp.org/display/70520
16:28Lau_of_DKthanks danlei
16:28danleinp
16:29danleistill gotta lookup things all the time ...
16:29Lau_of_DKIm really starting to like the Clojure-community
16:30Lau_of_DKIn the early days answers were much harder to come by
16:30danleioh
16:30danlei,'s sneaked in ...
16:33danleiLau_of_DK: that's better: http://paste.lisp.org/display/70521
16:33Lau_of_DKthanks alot danlei, its an interesting approach
16:33Lau_of_DKnotice: You can annote your own pastes to keep the history
16:35danleiLau_of_DK: just saw it after i pasted the 2nd one =), thanks
16:40Lau_of_DKdanlei: that fancy (or (and (or (...)))) thing you got going on, thats just to check if its a symbol, if so attach meta, if not, just return it
16:40Lau_of_DK?
16:41danleiLau_of_DK: yes, could've used if, or some other conditional
16:41Lau_of_DKNo no, (or (and (or))) looks good, its original :)
16:42Chousukehmm
16:42Chousukefunctional programmin really is fun :)
16:43ChousukeI wrote a neat little function to return a seq of all the names bound by a destructuring binding form.
16:43Lau_of_DKPaste it!
16:44ChousukeI was fortunate enough to find 'destructure from core.clj so I didn't actually have to write the destructuring myself...
16:47Chousukehttp://paste.lisp.org/display/70524
16:47Chousukemight be useful if you're writing macros.
16:48Chousukethe problem is though that it ignores gensyms for now (because destructure generates gensyms)
16:49Lau_of_DKlooks nice, as concise as can be
16:49Chousukealso I notice there's an error
16:49Chousukeshould be (destructure binding-form), not (destructure bindings)
16:51Chousukethat doesn't necessarily find all gensyms either :/
16:51PupenoHello.
16:52Lau_of_DK Hello MR. Pupeno
17:01pjb3Is this a bug?
17:01pjb3user=> (for [i (range 0 2)] (do (println i) i))
17:01pjb3(0
17:01pjb30 1
17:01pjb31)
17:01pjb3I would expect
17:01pjb3user=> (for [i (range 0 2)] (do (println i) i))
17:01pjb30 1
17:01pjb31)
17:01pjb3oops, not that
17:01pjb3user=> (for [i (range 0 2)] (do (println i) i))
17:01pjb30
17:01pjb31
17:01pjb3(0 1)
17:02pjb3What happens is that somehow the values that are printed are mixed in with the return value
17:03Lau_of_DKIts not a bug, println doesnt return anything, it just mangles the output
17:03Lau_of_DK(for [i (range 2)] (do i))
17:03Lau_of_DK(0 1)
17:03Lau_of_DKThis is the return, and in that, you have printed first 0, then on the next line 1
17:03pjb3Lau_of_DK: so why isn't the result
17:03pjb30
17:03pjb31
17:03pjb3(0 1)
17:04pjb3Shouldn't the first println happen, then the second, then expression is finished evaluating and the REPL prints the return value
17:04pjb3?
17:05rhickeypjb3: for is lazy, use dorun on the result or switch to doseq which now takes all the options of for, but is eager
17:05Chousukehmm
17:06Chousukeapparently destructure only generates gensyms prefixed vec__ and map__... maybe I could use that to filter them out :/
17:06Chousukeugly, though :(
17:07Lau_of_DKRegex is ugly...Perl is regex....I'll stop here :)
17:07pjb3rhickey: both of those print, but return nil
17:09PupenoHow do you quit Slime?
17:09PupenoOther than by manually killing all its buffers?
17:09danleiPupeno: ,sayoonara
17:10Pupenodanlei: cryptic! thanks.
17:10pjb3 (let [x (for [i (range 0 2)] (do (println i) i))] (doall x))
17:10pjb3that works
17:11PupenoAnd when you get errors, is there a way to dismiss them without killing the window?
17:11danleiPupeno: q
17:11pjb3or I guess just (doall (for [i (range 0 2)] (do (println i) i)))
17:11danleiPupeno: if you're in the debutter
17:12danlei*bugger
17:12Pupenodanlei: I used to do that with CL, but that is killing with the window.
17:13danleiPupeno: hm, for me, q works the same with clojure and cl
17:15Pupenodanlei: I don't know about CL as I haven't used it in a long time, all I know is that q kills the (Emacs) window here.
17:16danleihm, i don't think i can help you, works fine here. (ends the debugger, but doesn't kill the buffer)
17:16Pupenook.
17:16Pupenoprobably my unstable emacs playing tricks on me... who knows.
17:17danleiPupeno: but then, i'm not sure if i understand you right. do you mean 1. 2 buffers, 2. error -> debugger -> q 3. only one buffer open?
17:21Pupenodanlei: not buffers, windows. But the answer is probably yes (Emacs terminology is weird).
17:21pjb3wow, duck streams FTW
17:22pjb3(with-open [rdr (reader "http://www.google.com&quot;)] (doseq [l (line-seq rdr)] (println l)))
17:22danleiPupeno: hm. in my case, there is no debugger buffer after q, but the window buffer stays open. (in emacs terminology)
17:22pjb3(with-open [rdr (reader "/etc/passwd")] (doseq [l (line-seq rdr)] (println l)))
17:23pjb3I remember things like that being a major PITA when I was doing a lot of Java programming
17:24Pupenodanlei: in my case, the emacs window gets destroyed, like if I did C-x 0.
17:24danleipup: hm
17:25hiredmanpjb3: word
17:26ChousukeI improved my bound-names function somewhat, but still it could be made more robust. any ideas? http://paste.lisp.org/display/70528
17:26danleiPupeno: then maybe it's your emacs. 2 window stays open here, if there was one, before the debugger popped up
17:27Pupenodanlei: yes, maybe it is.
17:28Chousukeis that binding form even correct :/
17:28Chousukemeh, anyway. you should get the idea :)
17:29PupenoAnyway... anyone working on 1094+ compatibility for compojure?
17:50PupenoOk, done.
17:54meredyddPupeno: Excellent. Does anyone have integration with more recent Jetty versions, too?
17:55meredyddI tried to play around with the Comet stuff a while ago, but the docs are really thin on the ground for the two-iterations-behind version they're using
17:56Pupenomeredydd: you mean jetty 7? not sure.
17:56dthomasI'm a Python programmer learning Clojure. I'm doing a simple little web scraping exercise, and I'm having trouble converting the idea of a generator to something in Clojure. Could anyone point me in the right direction for doing something like http://paste.lisp.org/display/70530 in Clojure?
17:57Pupenomeredydd: you can check the compojure network: http://github.com/weavejester/compojure/network
17:57waltersdthomas: i think the rough equivalent is lazy-cons
17:57meredyddThat's wicked cool.
17:57meredyddI think I need to learn git.
17:58pjb3If you want to find the first element in a seq that meets a predicate, do you have to do (first (filter pred coll)), or is there a different function that does that?
18:02dthomaswalters: That was my first guess. Will returning the results in a lazy sequence mean that all the members of the sequence are going to hang around until the whole sequence becomes eligible for garbage collection?
18:03waltersdthomas: you're talking to a python expert but a total clojure newbie, so we've about exhausted my clojure knowledge =) but my guess is yes
18:03hiredmanin the irc log someone mentions some "agents and refs in use" slides of rhickey's, does anyone know if those are around somewhere?
18:03Chousukedthomas: hmm, no.
18:04hiredmanas long as you don't have onto the head, right?
18:04dthomaswalters: Yeah, my guess too. That led me to think that lazy sequences aren't 100% the right solution.
18:04Chousukedthomas: as long as you don't hold on to the head, previous parts may be freed.
18:07meredyddpjb3: (some pred coll) does the trick
18:07dthomasChousuke: Ah, so (doseq x (lazy-make-a-lot-of-stuff) (prn x)) won't eat up more memory than the biggest item in the lazy sequence (ideally)?
18:08meredydduhh, wait, no
18:08pjb3meredydd: some returns the value of the pred
18:08meredyddoh, rats.
18:09pjb3this does the trick: http://gist.github.com/25589
18:09dthomasChousuke: (Sorry, that's actually not very good phrasing on my part, but I hope my intention was clear.)
18:10meredyddpjb3: Or just (defn find-first [pred coll] (some #(when-let x (pred coll) x) coll)
18:11meredyddOh, what am I talking about? (defn find-first [pred coll] (first (filter pred coll))) is simple, easy and efficient.
18:11pjb3meredydd: oh, filter is lazy?
18:12meredyddof course
18:12pjb3right
18:13rhickeydthomas: if you (lazy-cons first-expr rest-expr) neither expr is evaluated until needed. If rest-expr in turn is lazy, then the result is that the only part of the sequence that exists at any point is the part you are using. Can definitely substitute for generators, albeit with a less imperative approach. You can make infinite sequences etc
18:15pjb3that would be cool if first had a two argument version that let you avoid the filter
18:15dthomasrhickey: Cool, "only part of the sequence that exists at any point is the part you are using" is what I was looking for.
18:15pjb3or maybe that would just be overloading that method name too much
18:15pjb3but (first even? [1 2 3]) makes sense to me
18:16dthomasThanks walters, Chousuke, rhickey.
18:16rhickeydthomas: keep in mind the caveat about holding onto the head though, as doing so will keep all of the realized seq alive
18:16dthomasNow I just have to figure out how to translate that Python to a lazy-cons where I can't rebind page.
18:17dthomasrhickey: Dumb question: by "head" you mean the head of the lazy-cons itself, not the first value in the lazy sequence, right?
18:18rhickeydthomas: right
18:25Chousukemeh. I just can't figure out a reliable way to determine what symbols are generated by 'destructure :/
18:26ChousukeI suppose the only way to determine what symbols it actually binds (other than its own gensyms) would be to write my own 'destructure clone that keeps track of the names. :(
18:26ChousukeSomething that, looking at the implementation of 'destructure, I don't want to do.
18:27gnuvince_Where is it defined that things like Strings and arrays implement seq?
18:28meredydddthomas: I can't get lisppaste.org to work
18:29Chousukegnuvince_: they don't. (seq? "foo") returns false
18:29Chousukemeredydd: don't use the paste-to-channel feature.
18:30Chousukeit seems to be broken
18:30hiredmanseq knows how to make seqs out of strings and arrays
18:30meredyddaha
18:30meredyddIn any case, it's a one-liner:
18:30meredydd(filter result-is-relevant? (reduce concat (pages-from-search query)))
18:30meredyddthen just make (pages-from-search) return a lazy seq of the pages, etc
18:30hiredmanmost functions that operate on seqs call seq on the args first
18:30gnuvince_Chousuke: I meant the Seq interface: you can do (first "hello") and (rest (to-array [1,2,3]))
18:31dthomasmeredydd: I like reduce + concat. But how do you stop the first time result-is-relevant? returns false?
18:32Chousukegnuvince_: as hiredman said, 'first calls 'seq on its argument
18:32Chousukedthomas: that version doesn't doesn't stop.
18:32Chousukedthomas: you'll have to use the find-first defined above
18:32meredydddthomas: change that (filter) into a (take-while)
18:32Chousukeor that. :p
18:33meredyddThat will give you the seq up until the first non-relevant result.
18:33dthomastake-while, awesome. That's exactly what I needed and didn't want to figure out how to write myself.
18:34Chousukeno-one can help me with my problem? :(
18:34meredyddWhat are you trying to do, Chousuke?
18:35Chousukefigure out what names are bound by a binding form
18:35meredyddWhy?
18:35Chousukehttp://paste.lisp.org/display/70528 here is something that "works", but is prone to failure
18:35dthomasOh, OK, take-while's implementation is embarassingly simple.
18:36Chousukemeredydd: it might be useful for macros that create context.
18:36Chousukemeredydd: I'm trying to figure out if I can make with-open support destructuring :)
18:37ChousukeI did it for simple [a b c d] binding forms but full destructuring support is more difficult. :/
18:37meredyddHow so? Give me an example of the fantasy syntax you want to implement.
18:38meredyddAnd does the version you posted there not work? Seems no more ugly than is necessitated by what you're trying to do.
18:39meredyddMy only comment is that this is tripping my "this is a question to which all the answers are ugly; are you sure you're asking the right question?" sense
18:41rottcoddit would be nice if into-array had an optional type arg for cases where coll is potentially empty
18:42hiredmanuh
18:42hiredmanwha?
18:42rhickeyrottcodd: it does now, (doc into-array)
18:43rottcoddah, thanks
18:44Chousukemeredydd: http://paste.lisp.org/display/70528#1
18:45meredyddOh, and rhickey? A belated thank-you-very-very-much for AOT.
18:46Chousukemeredydd: my question is simple: how do I get a list of the names bound by a given binding form?
18:46rhickeymeredydd: you're welcome!
18:46Chousukethe answer, as you can see, is not as simple :(
18:46Chousukeunless there's some magic I'm unaware of.
18:58meredyddChousuke: Well, the simplest way would be to separate a binding list into assignees (first element, third, fifth, etc) and values (second, fourth)
18:58meredyddthen descend into the assignees and pull out everything that's a symbol.
18:59meredyddI think that should work.
18:59meredydd(rather than relying on (destructure), which isn't very official or supported IIRC)
19:05hiredmanhwa
19:06hiredmanmy unicode issues are a reult of using jline
19:06hiredmanresult
19:09Chousukemeredydd: but that would mean rewriting destructure :P
19:09danleihow would one just run a simple function in a thread? i tried things like (.start (Thread. (pr 'hello))), but that won't do
19:09Chousukemeredydd: which is not simple at all
19:09meredyddChousuke: No, it wouldn't. You just ignore the keywords, and pick out *all* the symbols.
19:09danlei+ #
19:10Chousukemeredydd: but what if someone wants to bind a symbol as the value of another symbol? :/
19:11hiredmanlast I checked the printing functions did not work in other threads, I think you need to explicitly bind *out*, or something
19:11meredyddYou just want the bound symbols' names, right? You don't want to actually get their value expressions. So you can safely ignore all the keywords, and the values in map binding expressions, etc
19:11danleihiredman: thanks
19:11Chousukehmm, right.
19:12Chousukebinding always happens in pairs, right?
19:13hiredmandanlei: nm
19:13danleiis there an equivalent to cl's #. ?
19:13hiredmandanlei: forget that about binding *out*
19:13danleior how would i bind *out*?
19:13danleihm
19:13danleiok
19:14hiredman(.start (java.lang.Thread. #(prn :x))) prints :x here
19:14danleinot for me
19:14danleibut i'm is slime, in cl i've got do bind *standard-output* with sharpdot-reader (#.)
19:15danleihow would i do that in clojure/slime?
19:15hiredmandanlei: try prn instead of pr
19:15hiredmanpr doesn't print here
19:15danlei(.start (java.lang.Thread. #(prn :x)))
19:15danleiwill just output nil, prints nothing here
19:16danleii guess it'll work on the blank command line, i'll check
19:16danleiyes, it does
19:17danleiso it boils down to binding clojures equivalent to *standard-output* to slimes
19:17danleiit gets printed in the inferior-lisp buffer
19:18danleiis there a way to access a value at read-time?
19:23rottcodddanlei: I use M-x slime-redirect-inferior-output
19:24danleirottcodd: perfect, thank you!
19:30Chousukehmmh
19:30Chousuke(remove #(or (keyword? %) (= '& %)) (flatten (map #(if (map? %) (seq %) %) (map first (partition 2 form)))))) <- not very clean, but that should leave me with just the symbols in a binding expression.
19:31Chousukeanyone spot anything fishy? :p
20:29ChouserChousuke: does that handle :keys, :syms, :strs ?
21:42scgilardiChousuke: in my patch to allow destructuring in the "binding" form, I distinguished the generated symbols by attaching metadata to them. Of course that required modifying destructure, but I thought I'd mention that the need has come up before. http://tinyurl.com/5uyke5
21:55grkz/part
21:55grkz
22:26jtoyhi guys, im coming from ruby, how do you build larger programs in clojure? I onyl know about oop systems, is there papers/articles i can read that relate this to clojure?
22:38gnuvince_jtoy: with functions and macros and multimethods and the rich data structures.
23:18topooh
23:18topotheres a lot of people in this channel
23:18topohello
23:19Chouserhi
23:30topohello
23:30topo i just download clojure for macosx
23:30topohow can i make it work?
23:30topotheres a .jar archive but nothin happens when i run it
23:30Chouseradd clojure.lang.Repl to your command line
23:30albinohow are you running it?
23:31albinoDoes java -jar /path/to/clojure.jar still work?
23:31albinothat's how I'm used to invoking it
23:31topojust click 2 times in the .jar
23:32toposo i do program in my command line?
23:32topooh
23:32topoi need java?
23:33albinotopo: yes, clojure runs on the java virtual machine
23:33topoalbino do you have macosx?
23:33albinotopo: no, I'm on linux
23:33albinotopo: but java kind of takes the os out of the equation after you figure out how to get it for your specific platform
23:35topoi got this:
23:35topotoppos-computer:live-coding-lisp topo$ java -jar /users/topo/desktop/clojure/clojure.rar
23:35topoUnable to access jarfile /users/topo/desktop/clojure/clojure.rar
23:35topooh jar
23:35topohaha
23:35danleiand capital U
23:36topooh i got user==>
23:36topocool
23:36topowhats that?
23:36topocan i program lisp there?
23:36topolike the repl?
23:36Chousertopo: you're going to have to go read some docs or watch a screencast or something.
23:36danleiit's called a repl, you can type expressions, it will evaluate and print the result
23:36danleitry (+ 1 2)
23:36topooh nice
23:36topoit works
23:36topocool
23:36topoyes
23:37Chousertopo: do you know lisp?
23:37topocan i port my opengl app from common lisp to clojure?
23:37topois that possible?
23:37topoand making java applets?
23:37topois that possible?
23:38topochouser yes i been experimenting with common lisp
23:38Chousertopo: ok, Clojure is not CL. There are many differences, some subtle, some not. Don't expect CL code to just work.
23:39Chouserthere are OpenGL libs for Java, so Clojure can use those easily. That should be possible.
23:39topodoes it have macros?
23:39danleiyes
23:39topocool
23:39topoim gonna read a tutorial
23:39topolooks interesting
23:43danleieverytime i do some sort of (.get (... (.invokeAll pool ...))) threr is a reflection warning. (reference to get ...), can i ignore that? if yes, can i surpress it?
23:44Chouserdanlei: you must be using slime
23:44danleiChouser: yes, i am
23:44ChouserYou can ignore it. The reflection warning indicates a performance hit at runtime.
23:44danleiah, ok
23:45danleican i avoid getting it printed every time?
23:45ChouserI don't have slime, but you can try (set! *warn-on-reflection* false)
23:45danleiah, that did it. thanks, chouser
23:46ChouserI think it's a mistake for slime to have in on by default -- the regular REPL doesn't.
23:46danleiok, thanks
23:46ChouserTo avoid the runtime hit, look into type hints. But don't bother unless you really need the performance -- they're ugle.
23:46Chouserugly
23:47danleiok. i'll just ignore it, for the time being
23:48Chousergood choice. :-)
23:48danlei=)