#clojure logs

2009-06-27

00:34_hrrld`I tried to post my first message to the google group today (about 4 hours ago) and it doesn't seem to have appeared. Is there often a delay?
00:34_hrrld`Or perhaps was I blocked as spam?
00:34samjrAnyone using JavaFX with clojure yet?
00:35codyKlong delays arent unusual
00:35_hrrld`codyK: Thanks, good to hear.
00:37Chouser_hrrld`: your first post is held until rhickey approves it manually
00:38_hrrld`Oh. I hope he likes it. ;)
00:38codyKsingle moderator? sounds like a lot of work . . .
00:38duck1123_hrrld`: aside from determining if it's spam, he doesn't really judge
00:40ChousercodyK: only for first post per user. no manual intervention after that.
00:40Chouserrhickey has described it as "works well"
00:41_hrrld`Thanks for the insight.\
00:43duck1123the clojure list is busy enough. We don't need the spam.
00:45codyK2,000 messages is more than I'd want to look at, but if it works well for him, that's cool
01:07jjttjjhmm anyone happen to know why every time I use (flush) it screws up my REPL and doesn't work
01:09slashus2jjttjj: What screws up again it?
01:11jjttjjwhenever I use flush followed by read-line, the REPL just keeps giving me blank prompts no matter what I put in
01:12jjttjjlike it just doesn't respond to my input
01:12jjttjjand I'm copying the ported PCL word for word
01:12slashus2Seems to work for me.
01:12jjttjjhmmm
01:13jjttjjwell, on a related note, if the slime REPL just keeps taking input without giving the "user>" prompt, is there a way to break out of that without restarting slime?
01:14slashus2I don't use slime. Maybe your problem is with slime and not clojure with the flush.
01:14jjttjjhmm maybe, i'll check it out
01:19jjttjjok yep it's slime
01:19jjttjjthanks
08:28blbrown_win2anyone here. I want to be able to launch a cloure environment from clojure in a thread. I guess this should be easy to do? and the other thread won't share any of the same namespaces?
09:18yangsxCan anyone help me understand this: (my-fun (first aseq)) gives me correct result, but (map my-fun aseq) gives NullPointerException: clojure.lang.LazySeq.sval(LazySeq.java:47)
09:54rhickeyyangsx: could you paste a reproducing snippet?
10:14yangsxrhickey: thanks, just found my error: it's because my misunderstanding of if-let
10:14rhickeyyangsx: ok
10:21yangsxI still often assume CL's rule that empty sequence is nil/false and thought if-let will choose the other branch. That's a problem for me moving from CL to Clojure.
10:25Jetienhi, i couldn't find in the api how to convert a string to an int
10:25ChousukeUse java for that.
10:26Chousuke,(Integer/parseInt "10")
10:26clojurebot10
10:26Jetienthanks
10:27Chousukethe core lib avoids duplicating java functionality :)
10:28ChousukeBecause of that, it helps to know the java standard library.
10:29Chousukefortunately, it's quite well documented. :P
10:29Jetienmh i understand
10:29Jetienbut what does (num) do then?
10:30Chousuke,(doc num)
10:30clojurebot"([x]); Coerce to Number"
10:30Chousukehmm.
10:30Jetienyes i know, but what does this mean?
10:30Chousuke,(class (num 4))
10:30clojurebotjava.lang.Integer
10:30Chousuke,(class (num "3"))
10:30clojurebotjava.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
10:30Jetienthat's what i tried
10:30Chousukeit's a cast, not a conversion.
10:31Jetienah, okay
10:36lisppaste8danlei pasted "ansi2html" at http://paste.lisp.org/display/82611
10:36danleihm, can someone tell me, why this won't work?
10:39danleiansi-code-to-tag does its job, but ansi-to-html won't close all open tags, if the 0 ansi-code is in the string
10:39danleiin the /same/ sting. it works, if the enclosing tag is in another invocation of a-t-h
10:42danlei(the messed up character in the paste is a literal escape)
11:44jackdempseyhas anyone written up a little something on metadata? it seems so simple....you have a symbol foo, and to get its meta data you can call (meta foo) or ^foo
11:44jackdempseybut then when i get into looking at things like #^ i seem to trip myself up
11:44jackdempseylike there's metadata for objects and metadata for the compiler
11:45jackdempseyoops, heh, "objects"
11:46duck1123jackdempsey: chances are, you might be wanting with-meta if you want to attach metadata to your values
11:46jackdempseyi would expect after #^String foo that ^foo would show {:tag String} but it seems i'm definitely wrong there
11:46jackdempseyduck1123: yep, read over that last night and that seems to be where i trip up
11:46jackdempseyattaching metadata to values vs vars maybe?
11:47jackdempseyi think i also need to review symbols, vars, values, and variables.....maybe sure i get all of it
11:48rhickeyhttp://groups.google.com/group/clojure/msg/919455504c57659e
11:48duck1123it always bothered my that with-meta put the metadata at the end
11:49jackdempseythanks rhickey that looks great, appreciate it
11:51danlucraftis there a fn to find the type of a struct?
11:53duck1123danlucraft: they're all structs, but the type of struct is not recorded
11:53jackdempseyhmm interesting
11:54duck1123I ran into that issue myself
11:54duck1123I wanted to multimethod on struct type
11:54danlucraftduck1123: ah, ok. thanks.
11:54jackdempseycan we set! things with the bot here?
11:55jackdempsey,(set! *warn-on-reflection* true)
11:55clojurebotjava.lang.IllegalStateException: Can't change/establish root binding of: *warn-on-reflection* with set
11:55jackdempseyk
11:55danleiwhat would be idiomatic clojure for something like this: (loop for (a b) on '(a 1 b 2 c 3) by #'cddr collect a collect (* b 2))? that is, processing every other element in a sequence, and returning it afterwards
11:55kotarakdanlucraft: the usual approach is a type tag on the map itself or in the meta data.
11:55jackdempseythe #^ example in that email was interesting....that a reflection warning is shown when just (.length (identity foo))
11:55jackdempseybut not when (.length #^String (identity foo))
11:56kotarakdanlei: (map processor (take-nth 2 stuff))?
11:56danleikotarak: I'll try. the expression i showed would return (a 2 b 4 ...
11:56danlucraftkotarak: well, I don't think metadata would make sense because I want them to be practically different objects
11:57danlucraftso I'll use a :type key I suppose
11:57duck1123,(binding [*warn-on-reflection* true] (.length (identity "foo")))
11:57clojurebot3
11:57kotarak,(mapcat (fn [[a b]] [a (* b 2)]) (partition 2 (list :a 1 :b 2 :c 3)))
11:57clojurebot(:a 2 :b 4 :c 6)
11:58danleikotarak: thanks
11:58kotarak,(let [l (list :a 1 :b 2 :c 3)] (interleave (take-nth 2 l) (map #(* % 2) (take-nth 2 (rest l)))))
11:58clojurebot(:a 2 :b 4 :c 6)
11:58kotarakdanlei: dunno which is better
11:58fffejis anyone looking at the ICFP contest in Clojure? I'm making slow (but steady!) progress here and wondered if anyone wanted to pool efforts!
11:59danleihm, liked the first one better somehow :) ty
11:59danlei(partition was what I should have known ...)
12:19jackdempseyduck1123: thanks....why doesn't that warning surface
12:19jackdempseywhen not passing in #^String
12:19jackdempsey(not even sure what that warning really means, but googling :-) )
12:25Chouserfffej: is it right now??
12:25fffejit's happening now yeah
12:26fffejI have some truly terrible Clojure code that implements the VM that it requires
12:26Chouserhmph. Well, I guess not. I was hoping to have a little time for the contest, but I don't think it'll happen this weekend.
12:33danleiis there a way to use partition like this: (partition 2 '[a 1 b 2 c]) -> ((a 1) (b 2) (c nil)) ?
12:35danleiotherwise, I'll just check, if the sequence's length is un-even, and append nil
12:35Chousukedanlei: not yet :)
12:35danleiChousuke: ok, ty
12:36Chousukedanlei: partition will get padding in 1.1 though. there's an open bug on it.
12:36danleiChousuke: very nice
12:37Chousukebut, *grumble* at google groups
12:37Chousukeit swallowed my reply :(
12:38Chouserpartition with padding is in git master
12:38Chouser(partition 2 2 [nil] '[a 1 b 2 c])
12:45Chousukeokay, what the hell
12:46ChousukeI'm not seeing my posts on the group :(
13:34lisppaste8danlei annotated #82611 "ansi2html" at http://paste.lisp.org/display/82611#1
13:35danleianything unindiomatic in there?
13:36danleiespecially, is an atom the way to go for *closing-tags*?
13:40danleiwell, if nobody critisises
13:41danleiit's either perfect, or such a mess, that no one even tries to comment on it :)
13:48Chousukem
13:48Chousukehm
13:48ChousukeI'm pretty sure you could do away with the atoms
13:48Chousuke-s
13:52danleihow exactly? i tried with vars and set! but that gave me an error
13:54danleilike: can't change the root binding
13:55Chousukewell, I'm thinking of doing a reduce with an accumulator for the closing tags.
13:56Chousukebut I can't quite figure out how to modify the code to do that.
13:56danleihm ... sounds nifty
14:07Lau_of_DKGood evening gentlemen
14:18krumholtHello, can someone make a simple example of the difference between alter and commute?
14:20Lau_of_DKThe difference is that multiple commutes to guarantee that they're executed in the sequence that they were evaluated, alter however protects the order
14:20Lau_of_DKs/to/dont
14:33Chousukedanlei: do you have a test string I could use with that thing=
14:43krumholtthanks
14:45danleiChousuke: sure, for example: (ansi-to-html "[1m[5mfoo[10mbar[0mbaz[37mqux") => "<b><blink>foobar</blink></b></font>baz<font color=white>qux" after that, (a-t-h "0mquux") => "</font>quux"
14:46danleithat is, in emacs, C-q ESC [ <code> m for the ansi-codes
14:52danleihm ... that first </font> shouldn't be there, actually
14:54danleiah, was left from a previous test.
14:56Chousukeokay
14:56Chousukemy version appears to work
14:57danleijust annotate my version, if you will
14:57lisppaste8Chousuke annotated #82611 "stateless" at http://paste.lisp.org/display/82611#2
14:57Chousukeit's not that much more readable but...
15:01Chousukeansi-code-to-tag actually has a misleading name now. it returns a [text-accumulator closing-tags] pair
15:01danleii see. takes a litte for me to grasp it, but It's an educating read
15:03danleiIt'll take me some time, to get used to write in that style.
15:04Chousukethe reduce returns a pair of [text-chunks leftover-closing-tags] which are concatenated and then stringified
15:06danleiI see, and it's something I can learn from. If you saw that code in the wild, which version would be easier for you to read? Where do you see the advantages?
15:06Chousukewell, my version is a pure function
15:07Chousukeit won't have any mishaps with state like your atom-version did when you pasted your examples :)
15:07Chousukeotherwise, neither of them are particularly simple :P
15:07danleiwell, the thing is: I want the function to keep state
15:07danleibecause it is feed with strings from a socket
15:08danlei*fed
15:08Chousukewell, in that case you can remove the (str* ...) part from the ansi-to-html function
15:08Chousukein which case it'll return a [text, closing-tags] accumulator which you can use as a starting value for another reduce
15:09danleiso you'd close over such a text, closing-tags pair?
15:10danleiI'll spend some time with your code to fully grasp it, it really is a good example for me
15:23lisppaste8Chousuke annotated #82611 "chopped up a bit" at http://paste.lisp.org/display/82611#3
15:23Chousukedanlei: ^^
15:24danleiChousuke: :) was just hacking up on it :)
15:24Chousukeactually hm, chunk-string should have the two-argument version arglist reversed so it can be used with reduce
15:25danleiwhat I'm trying to do is have make-ansi-to-html-converter, letting it return a closure which keeps the context and can be fed with strings
15:25Chousukethen you could do (reduce chunk-string [[] '()] ["foo" "morefoo" "evenmorefoo"])
15:26Chousukebut that'll still break if the strings are broken in a way that the regexp fails :/
15:27Chousukebut that was a problem with the original too :)
15:27danleiyes, it is
15:27danleiit's used in a mud client, btw
15:27danleibut, as of now, it's still pretty basic
15:28Chousukeit sounds like you ought to ensure that the full string is received before converting it to html
15:28danleihm ...
15:29Chousukeor at least that it doesn't contain broken ansi sequences
15:29Chousukethat method will likely be simpler than hacking ansi-to-html to support broken sequences :)
15:29danleiyes, I do see the problem, but how should I know, when the string is "finished"?
15:30Chousukethat I suppose is a protocol problem :P
15:30danlei:)
15:31danleianyway, I thank you for the time you spend doing your solution, it really is appreciated
15:31Chousukeno problem. it was fun anyway :)
15:31Chousukefinding functional solutions to stateful problems is always fun
15:31danleiI'll spend some more time with it, and later I'll decide, which version to include. somehow I like the idea of having a converter-maker :)
15:32ChousukeYou should try to avoid state. your program is basically the definition of a function :)
15:32danleiabout the protocol: at least, in most MUDs ansi-sequences are left to the magicians, so, if it fails, I'll know whom to blame :D
15:32Chousukeit gets input, processes it, and produces output
15:32Chousukeno need for state.
15:33danleiwell, the state is there, but it's kept on the stack, isn't it?
15:33Chousukewell, it's "state", but it's not mutable :)
15:34danleiyes
15:34danleione question, that also is important for me: which version will I be able to understand better, say, after two years
15:34Chousukesince you'll be doing IO you will have some mutable state too but you should isolate that from the actual processing logic
15:34danleiwhich is no criticism, but just a practical consideration
15:35ChousukeHeh, well, I'd bet on the functional version.
15:35danlei:)
15:35Chousukemutable state always complicates things
15:35Chousukeyou actually need to care about how a function affects it, instead of what its inputs and outputs are.
15:35danleiare you sure about the "always"?
15:35Chousukeyes. :)
15:36Chousukesometimes you can't avoid it though :/
15:36danleihm, I'm not. but I'm willing to change my opinion over time. In general, I am with you, but always is pretty often, innit? =)
15:36Chousukewell, yeah
15:37danleiat the moment, I'm taking it as a lesson. You provided another view at the problem, which I just solved, as I would have solved it in CL.
15:38danlei(more or less)
15:38Chousukewell, you basically used a mutable stack. I replaced it with an accumulator parameter
15:38danleiyes
15:39Chousukethough since you're doing parsing, you might want to take a look at fnparse
15:40Chousukeit's a third party library for writing functional parsers.
15:40danleithat's what I meant. Your version's state is encapsulated in the function itself, as the arguments of sucessive calls. In my version, state is kept at another place.
15:40danleifnparse?
15:40danleiI'll check up on it
15:40danleity
15:41Chousukedanlei: the problem with your version is that there's no referential transparency. a previous call to your function may affect the following ones; something that you want to avoid
15:42Chousukeif you call your function twice with the same arguments, the results might not be the same.
15:42danleiin general, yes. if I make a make-converter, returning functions which close over the state, I have the re-invocability, and the encapsulation. I guess that would be a nice solution
15:43Chousukeit's not very idiomatic for clojure though :/
15:43danleihm
15:43danleiwhy exactly?
15:43Chousukewell, your functions still encapsulate mutable state.
15:44danleiyes, but in a more encapsulated, "tidier" manner, I'd say
15:44Chousukeif you call make-converter, feed it a string, and then the same string again, the output may still differ, right?
15:44danleilike a little chunk of mess :)
15:44danleiyes, it's not a pure function, I agree
15:44Chousukedanlei: it's a lot like OOP :)
15:44danleiit's OOPs twin :)
15:45danleiwhether the evil, or the good one :)
15:45Chousukeanyway, my general advice is to avoid any mutable state until you truly need it.
15:46Chousukeyou simply won't need to care at all about what a function does if it's pure :)
15:46duck1123which one has the mustache? That's how you can tell
15:46Chousukewhich is not the case if you encapsulate mutable state
15:47danleiyou see, I do agree with you
15:47danleiI'm just not sure, if the generality of the statement applies
15:47danleibut who am I. we can discuss that again, when I'm more familiar with that style,
15:48Chousukeheh
15:48danleiuntil then, I'll have a bias toward things I do already understand well ;)
15:48Chousukehave you read http://clojure.org/state ?
15:48danleiyes, but it's been a while and I'll re-read it
15:48danleibut, for example:
15:49danleiif mutable state was generally wrong, why would rich allow it?
15:49danleithere seem to be situations, where it's just te better solution, don't you agree?
15:49ChousukeI'm sure you'll grow to appreciate functional style a great deal if you stick with Clojure. :)
15:49danlei(don't wanne be heretic)
15:49Chousukedanlei: well, yes. some things are inherently stateful
15:50Chousukeyour ansicode->html transformer however, is inherently a functional problem.
15:50danleipoint taken
15:51danleifor the most part, I already stick with functional solutions
15:52Chousukethe stateful part of your problem is the network IO, I suppose.
15:52danleiI guess it's been the problem at hand, which made me use a known solution ... habits :)
15:52clojurebotPeople have a problem and think "Hey! I'll use a regular expression!". Now they have two problems....
15:52danleiclojurebot: botsnack
15:52clojurebotthanks; that was delicious. (nom nom nom)
15:52Chousukebut if you isolate the transformation from the IO, I think you will have a much more robust program :)
15:52duck1123I don't have much experience with them, but would this be a good job for monads?
15:52Chousukepossibly.
15:53ChousukeI'm still not comfortable with monads though :/
15:53danleiare monads idiomatic style in clojure?
15:53duck1123I wish Programming Clojure had covered monads. Here's hoping for the next book
15:53Chousukedanlei: well, yes.
15:53Chousukedanlei: monads are purely functional after all
15:53Lau_of_DKclojurebot: seen eyeris?
15:53clojureboteyeris was last seen quiting IRC, 1242 minutes ago
15:55danleiI think I haven't even understood the basic principles of them. I know there used to keep side-effects and functional code separate.
15:55danleibut /how/, I don't know
15:55Chousukedanlei: though you don't *have* to use them -- unlike haskell -- because Clojure is impure, and you can separate stateful logic from functional logic simply with discipline
15:55duck1123there was a good series on monads in clojure, but my head started spinning halfway through
15:56danleiat the google group?
15:57duck1123I think it was this one: http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure-programmers-part-1/
15:57duck1123perhaps I should try reading it again.
15:57danleihttp://tinyurl.com/cfr9le
15:57danleiyes, just found it
15:58danleithanks
15:58danleigoing to be a tough read, I guess :)
15:58danleiI'll give it a try
16:01danlei(and have a look at that fnparse thing)
16:02Chousukeusing the state monad you could rewrite the transformation functions so that the state (the accumulator) is encapsulated away, but still functional
16:03Chousukethat is, without resorting to atoms or other mutable state trickery :)
16:12danleithere is to much knowledge missing, right now. I'll have to read up on it ... But one further question: If you're so convinced of /pure/ functional code, what exactly keeps you using clojure, and not some language like haskell? (I, for one, have dabbled a little with it, but found it somehow ... just to "strict" for my taste. A subjective statement, I know ...)
16:14danlei(atm common lisp and clojure are the languages I prefer, and then there's a huge gap ...)
16:30duck1123personally, I don't like languages where indentation is significant
16:30duck1123that was what turned me off to python as well
16:30danleihm .. I think that's optional in haskell
16:32duck1123I've only read a little bit into Haskell. Seems like a decent language, but I'm happy with Clojure for the time being
16:32fffejit's funny how indentation isn't significant in Lisp, but everyone does it the same way anyway
16:32danleiyou mean: emacs does it the same anyway =)
16:32kencauseyyes, no more consistent than in most other languages
16:32duck1123right, I do whatever emacs does for me
16:33Chousukefffej: indentation is very significant in lisp for readability though.
16:33fffejexactly my point
16:34fffej(if indentation turns you off Python, it could turn you off lisp too)
16:34ChousukeI have noticed that instead of looking at the parentheses I get all the needed information from the indentation :P
16:34Chousukethe parentheses kind of disappear
16:34eevarwonder if i'm not missing out on something tho. there has to be a reason for why people use (oca/s)ml and haskell
16:34danleiI agree, lisp in general is great. But now, that there's clojure I find myself missing each others features in both of them :)
16:36eevarthere are too many languages out there, and not enough time :/
16:36duck1123I like that (in clojure-mode at least) I have control over the "shape" of my code by deciding where i put the newlines
16:36kencauseysexps to the rescue
16:38danleiapropos features in cl/clojure ... is something like cl's debugger planned for clojure? that's one of the things I miss. (yes, know about the possibility to attach debuggers, but it's just not the same)
16:38Chousukehmm :/
16:39Chouserdanlei: I don't think rhickey plans to create such a thing, but it seems likely you could.
16:39Chouseruse the JVM debugger api (whatever that is) and just do it.
16:39danleiChouser: I fear, I don't have the skills to tackle such a thing
16:40duck1123I've been wanting to try out cljdb, but I couldn't figure out how to get it working with maven
16:40danleithat'd be a fairly advanced project, I guess
16:40danleinot one of the things I can hack up in a few weeks
16:41danlei(one of the major problems my not really knowing java)
16:42danleibut in general, yes, I'd be willing to offer my work/time for such a project (with someones more knowledgeable by my side)
16:43fffejputting type hints in programs in annoying - would (in theory) it be possible to annotate functions with metadata about types (in Clojure core) and use type inference to insert the necessary casts automatically? It seems like it should from my basic understanding, but before I go off to read more about Hindley–Milner inference, I wondered if there were any holes in that plan?
16:45danleiwould some of you guys be interested in such a project? (cl-like debugger for clojure)
16:47Chouserdanlei: I must admit I've never used a cl-like debugger, so I only have a vague sense of what that means.
16:48danleiChouser: well, you can select stack frames, see local vars, evaluate expressions within a stack-frame, and so on. everything built into the language itself. (you'd just have to fire up clisp or something and have a look)
16:48Chouserfffej: one issue to keep in mind is the dynamic nature of clojure programs. just because (defn foo [] 5) alreays returns an Integer right now does not mean it will throughout the life of the program.
16:48fffejchouser: thanks, that was the dose of reality I needed :)
16:48danleiand, of course, the error messages are a lot more telling than some java-related messages I get sometimes in clojure
16:49danleibut I'm not sure how to do that, without the condition system
16:49danleiyou're offered different restarts (restartable conditions), which you can choose
16:49Chouserfffej: you're alreays (???) welcome.
16:54danleiin general, the debugger is a kind of global handler, which opens up, if a sent (error-)condition is not bound to a restart, or some other code which handles it. so in the debugger, you become somewhat a "human" handler, which can decide, what to do. you always can set up a handler in code, which knows, how to decide and restart the code further down the calls (where the restarts are set up for it)
16:55danleiif a condition is not handled in the code (via handler-bind for example), you'll have to do it "by hand", in the debugger
16:57danleiso the condition system, on top of which de debugger is the "last resort" is kind of a superset of java
16:57danlei*java's exceptions
16:57danlei(as far as I can tell)
17:01danlei. o O (now I've made them all fall asleep :)
17:02ChouserI wonder if the java debugger api (I say that as if I knew it existed) allows you to catch an exception at it's moment of creation such that it could be continued right there.
17:02ChouserI wouldn't be surprised if the answer was "no", in which case the project may be doomed already. :-)
17:02danleiunfortunately, I have no idea (my java knowledge is very basic)
17:04danleibut, as I said, my offer stands: if someone wants to tackle it, I'll be glad to help (don't know how much that's worth though :) )
17:04kotarakMaybe one can modify throw (the Clojure one) to drop into a debugger.
17:07danleithe basic principle (don't think I formulated it well) are: a function which does something generally knows, how to back up in case of an error. let's say a read error: read another file, try reading same file again, enter values manually. then, further up the calls, it's known /how/ to handle best, which of the offered restarts would be best. the handler now chooses a restart, which fits. if there is no handler, which chooses in the
17:07danleicode, you'll drop into the debugger, and choose yourself. (think, that is a better explanation than the one above)
17:08danleiso there are three parts: the condition, the restart, and the handler
17:11Chouserdanlei: much of that (not including the interactive debugger part) has been implemented in contrib.error-kit
17:11duck1123wasn't there a contrib library that was working towards something like this?
17:11danleiChouser: thanks for the pointer
17:11Chouser...though I'm not sure I endorse it anymore.
17:13Chouserit's explicitly an attempt to provide (some of) the features of the CL conditions system, but I think in the process I brought over unnecessary baggage (esp. object-system related cruft).
17:13danlei(now I've collected pretty much stuff, that I'll have to have a look at today :)
17:14danleiwell that's another discussion: If one /wants/ a cl-like condition-system and debugger
17:15danleiI, for one, find it pretty useful
17:17danleibut then, one can't have the cake and eat it too. there is a kinda long list of things, I would love to have in CL from clojure, and vice-versa. (keyword arguments in clojure, more general sequence abstractions in CL for example)
17:18danleieverything is somehow a compromise ...
17:18duck1123doesn't defk try to do the keyword argument thing?
17:19danleifor inclusion in core?
17:19danleithat'd be very nice to have IMHO
17:19duck1123IIRC, c.c.def/defk
17:20duck1123haven't gotten around to using it yet, but I have a few functions where it might fit
17:20danleiyou're not alone ;)
17:20kotarakdefnk.
17:21kotarak(defnk foo [a b c :x default-for-x :y default-for-y] ...) (foo some-a a-b another-c :y 5)
17:23danleiI'd love to see something like this in core ... Things like :from-end-t, :key, etc. are a nice thing to have, imho. you get used to it ;)
17:23duck1123I wonder though if using defnk might be overkill for what i needed
17:23danleilike ... garbage collection is overkill for most c-programmers? ;)
17:24kotarakduck1123: multi-arity also helps sometimes: (defn foo ([x] (foo x some-default-y)) ([x y] ...))
17:24danleithings like that shouldn't be done by hand everytime, I think
17:25danleiit's just sad, that many (if not all) of the discussion at c.l.l are rants, rants and ... more rants
17:25duck1123I did some pseudo-keyword arguments for my fork of clj-record
17:25danleiwhen both languages are actually so nice ...
17:26kotarakdanlei: instead of wasting time with c.l.l one should program in CL or Clojure. That is a much better of the time...
17:27danleiwell, I do, with my mud-client, for example (which is not that much, but some friends do actually use it) as far as c.l.l. goes: you really can learn an awful lot over there, but signal/noise is not that high, unfortunately
17:28duck1123Has anyone else found that since learning clojure they can't read a java book without mentally converting the code samples to clojure?
17:28danleiand the threads about clojure were especially disgusting, IMHO
17:30dmiles_afkdanlei: i am working ona secondlife client that uses Clojure
17:30duck1123dmiles_afk: will it support opensim?
17:30dmiles_afki presently test on OpenSim about 60% of the time
17:31dmiles_afksince there are little nits between them
17:31danleidmiles_afk: very nice, atm, I've enough work with the text thingy (and learn a lot, for example the discussion with chosuke)
17:32dmiles_afkits funny.. i've one arround text and network things like openmemtavere.. it's funny the text one isnt much easier ;P
17:32duck1123dmiles_afk: do you have a public repository anywhere?
17:32danlei:)
17:33dmiles_afkduck1123: http://code.google.com/p/opensim4opencog/
17:33duck1123thanks
17:33dmiles_afkthe clojure stuff: http://code.google.com/p/opensim4opencog/source/browse/trunk/bin/cogbot.lisp
17:34dmiles_afksetj = set, progn = block. i am trying to make the code feel more common lispy.. so been trying to avoid name conflicts
17:35kotarakdanlei: the function or the macro version?
17:36danleianyway, thanks for the discussions, guys. learned a little today. afk
17:36duck1123so do you CL'ers find much use for I think it was called PROGV?
17:36danleikotarak: macro, quick and dirty
17:36duck1123there was a post on the things this guy didn't like about clojure, and the missing progv was one of them
17:37danleiduck1123: for interpreters, I think. haven't actually used it, besides for educational purposes.
17:37duck1123The only way I could think to do it in clojure was to use eval
17:37dmiles_afki use ikvmc.exe to compile clojure.dll .. but for everyday testing i use DotLisp.dll (clojure's predicessor)
17:37kotarakduck1123: If it's the Var/pushThreadBindings thing: yes, I needed that already several times.
17:38dmiles_afkclojure on .NET i am hoping will be able to call events code
17:38dmiles_afkevents are methodlists that you call one method.. but it fires to several methods
17:41dmiles_afkwhat .NET has on the JVM is the ValueTypes which is the deatch of many JVM languages
17:41dmiles_afkyet however everythiong .NET i've used is still much slower than JVM based things :)
17:42dmiles_afkthats not just mono.. its even win64.NET vs Sun
17:43dmiles_afkbut i am not trying to bash one or the otehr.. its just JVMs only 7 valuetypes makes things harder in the long run
18:22jackdempseyjust a general comment, but damn, there really are some practical features in closure
18:22jackdempseycan tell it wasn't designed by committee in an ivory tower.
18:24cgrandquidnunc: haven't had time to check text-node before, it was plain broken. sorry :-(
18:25cgrandquidnunc: (select (html-resource (java.io.StringReader. "<html><b>hello<abbr>wrld")) [:abbr :> text-node]) works now
18:31quidnunccgrand: Thanks
18:34quidnuncI feel a little less stupid for not being able to get it working
18:37durka42is there like a map difference function?
18:38durka42as in, take this map and remove the key/value pairs where the keys are in this other map
18:38durka42that was not very articulate
18:38durka42(map-difference {:a 1 :b 2 :c 3} {:a 42 :c 1}) => {:b 2}
18:39durka42hmm, in writing out that example i realized this isn't the function i'm looking for...
18:40duck11231move along
18:40opqdonut:P
18:44Chousuke,(reduce dissoc {:a 1 :b 2 :c 3} (keys {:a 3 :c 2})); anyway :)
18:44clojurebot{:b 2}
19:12jackdempseyhmm
19:13jackdempseyis there another more union related way ? set algebra? cant' think of the words atm
19:14Chouserrelational
19:14jackdempseyhaha, whew, yes
19:14Chouser:-)
19:15Chouserjackdempsey: for differences?
19:15jackdempseyyep
19:16jackdempseythe dissoc felt more like take this map and remove the elements with these keys
19:16Chouserthere's clojure.set/difference, but that operates on sets
19:16jackdempseygotcha yeah, makes sense there
19:17ChouserI think dissoc is exactly how you get a map with something removed. *shrug*
19:17jackdempseyi'm so used to thinking "hash" and with the function "map", thinking of maps always gets a bit backwards in my head
19:17jackdempseyyep, no that makes sense, with difference for sets
19:53bpattisonI want to "update" a value of a give key in a struct-map, is there a function that will allow me to do and return an updated copy of the original or do I need to reset all the values from the original?
19:54drewr,(doc update-in)
19:54clojurebot"([m [k & ks] f & args]); 'Updates' a value in a nested associative structure, where ks is a sequence of keys and f is a function that will take the old value and any supplied args and return the new value, and returns a new nested structure. If any levels do not exist, hash-maps will be created."
19:55bpattisondrewr: excellent -- thanks
19:56drewr,(update-in {:foo {:bar {:baz 1}}} [:foo :bar :baz] inc)
19:56clojurebot{:foo {:bar {:baz 2}}}
19:57drewr,(update-in {} [:foo :bar :baz] #(or % (inc %)))
19:57clojurebotjava.lang.NullPointerException
19:57duck1123assoc should also work if the value is at the top
19:58Chousukehmm
19:58bpattisonyeah, its just a simple struct-map
19:58Chousuke,(update-in {} [:foo :bar] (fn [] 1))
19:58clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--4429$fn
19:58Chousuke,(update-in {} [:foo :bar] (fn [_] 1))
19:58clojurebot{:foo {:bar 1}}
19:59Chousukeah, right, you should've used and, not or :)
20:01bpattisonI guess I was looking for something like (setter gc :x (inc x 1)) where gc is a struct-map
20:02Chousukethat's not really a "setter"
20:02Chousukesince it doesn't modify anything :)
20:02bpattisonsure -- but something that acts like a setter
20:02Chousukewell, update-in works
20:03Chousukeor just assoc
20:03bpattisonokay, I'll give those a try
20:04bpattisonyep, assoc works perfectly
20:04Chousukestructmaps are just normal maps that you can generate optimised getters for
20:04Chousukethere's usually no reason to use them at all.
20:04Chousukestill for some reason, they're popular
20:05ChousukeI guess the structmap base key definition has documentation value, but... :)
20:06bpattisonwell that's why I used it -- the "struct" has meaning
20:07bpattisonplus, doesn't it provide a defined hash structure that get's defaulted if key values aren't initialized?
20:07Chousukeit's no different from a map
20:07Chousuke(:foo {})
20:07Chousuke,(:foo {})
20:07clojurebotnil
20:07Chousukesame happens with a struct map
20:08ChousukeI suppose the other nice thing about struct maps is that you can create them with (struct foo some vals here)
20:10Chousukebut that may actually be less readable than explicitly specifying the keys
20:10Chousukethough it saves a bit of typing
20:38Mark_Addlemanhi, i've got a question about walking parallel lists using for... suppose i've got two lists, a and b. a=[1 2 3] and b=[a b c]. i want to walk them in parallel (not nested) using a list comprehension. something like (for [x a, y b] (x y)) -> (1 a 2 b 3 c)
20:39Mark_Addlemani don't know how to construct the binding to do anything other than nesting. i thought about a function to interpose elements of a with b, but i couldn't find a core/contrib function to do that
20:39Chousukeinterleave
20:39durka42,(map list [1 2 3] '[a b c])
20:39clojurebot((1 a) (2 b) (3 c))
20:39Chousukefor can't do parallel walking
20:39Chousuke(doc interleave)
20:39clojurebot"([& colls]); Returns a lazy seq of the first item in each coll, then the second etc."
20:40Mark_Addlemanah, that's perfect. thanks!
20:57durka42,(with-out-str (.write *out* 65) (.write *out* 0) (.write *out* 66))
20:57clojurebot"A
20:57durka42^ is this a bug?
21:01kyle_burtonquestion re: serializatino of object graphs with both clojure and java data types in them - I'm sure there is logic behind it, does anyone know the ratinoale for keywords (:foo) not being serializable?
21:02Chouserdurka42: I think that's an encoding thing
21:03Chousercharacter encoding
21:03durka42but why did it never print the closing quote?
21:06Chouserdurka42: I'm not sure yet, but the \0 code must be telling it somehow that the " should not be printed. The final \n as well, in my tests.
21:07Chouserno, I'm wrong.
21:07Chouser,"a\000bcdefghijkl"
21:07clojurebot"a
21:48dreishThat prints as "a^@b" in my Aquamacs.
21:49Chouserdreish: that sounds better than what I see
21:49dreishWhat are you using to run your repl?
21:50dreishI've got Aquamacs, a fairly recent 1.1.0 alpha, and Java 1.6.
21:51Chouserah, rlwrap changes things
21:51dreishAnd I'm using Inferior Lisp.
21:52durka42grumble grumble
21:53durka42why doesn't dataoutputstream use overloading
21:54Chouserjust java on a linux command-line...
21:55Chouser(print "a\000bcdef\000ghi") ==> abcdefghinil
21:55Chouseroh, the nil is the return value
21:55Chouserso the nil chars are just ignored
21:55dreishWell, they're non-printing.
21:55Chouserindeed
21:55dreishSame with any other language.
21:56Chouser(prn "a\000bcdefghij") ==> "abcdefghij"
21:56durka42i guess somewhere between sockets, nailgun, vim and vimclojure somebody stops on nulls
21:57dreishperl -e 'print "a\x00b\n"' => ab
21:58Chouseradding rlwrap causes it to stop after at the null char
22:06Chouserit would be nice if null string printed an escaped form, line \newline does
22:07dreishSame with the various other non-printing chars, like 1, 2, etc.
22:08Chouseryeah. there are a few, but more would be better
22:08dreish,(char 2)
22:08clojurebot\
22:08Chouser,(pr-str (char 12))
22:08clojurebot"\\formfeed"
22:10Chouser"\f"
22:10Chouser,"\f"
22:10clojurebot"\f"
22:10Chouser,(nth "\f" 0)
22:10clojurebot\formfeed
22:48Mark_Addlemanhi, i've got a question using destructuring in a for macro. (for [[a b c] [1 2 3]] nil) -> "java.lang.UnsupportedOperationException: nth not supported on this type: Integer"
22:48Mark_Addlemani'm trying to get a binding of 1->a, 2->b, 3->c. it seems to work in let, but not for
22:49Chouserright, because for destructures each item in the seq
22:49Chousernot the whole seq
22:50Chouser,(for [[a b c] [[1 2 3] [4 5 6]]] b)
22:50clojurebot(2 5)
22:50Mark_Addlemani'm struggling to understand what that means... does that imply (for [[a b c] [[1 2 3]...) ?
22:50Mark_Addlemanah, i think i got it
22:57Mark_Addlemanok, this is coming to me slowly (sometimes agonizingly!). i have two lists: a list of database tables and another,parallel list, of primary keys. i want to walk the lists in parallel so i get a pairing of table & primary key. how can i do this?
22:58Mark_Addleman,(for [[t pkey] [[:t1-table :t2-table] [:t1-pkey :t2-pkey]]] [t pkey])
22:58clojurebot([:t1-table :t2-table] [:t1-pkey :t2-pkey])
22:58Mark_Addlemani want ([:t1-table :t1-pkey] [:t2-table :t2-pkey])
23:04Chouser'for' can't do it by itself
23:06Mark_Addlemani'm not wedded to for :) is there a parallel list walking function in the core library or in contrib? I couldn't find one. i found "walk" but that doesn't seem to do what i want either
23:06Chousermap
23:06Chouser,(for [[a b] (map vector [1 2 3 4] [5 6 7 8])] {:a a, :b b})
23:06clojurebot({:a 1, :b 5} {:a 2, :b 6} {:a 3, :b 7} {:a 4, :b 8})
23:08Chouser,(map + [1 2 3 4] [5 6 7 8])
23:08clojurebot(6 8 10 12)
23:09Mark_Addlemanok. i get it. it would have taken me a long time to come up with that on my own. thanks
23:10Mark_Addlemani'm at the neophyte stage: i understand the little bits but not how to put them together in interesting ways yet
23:10Mark_Addlemananyway, thanks for the pointer
23:10Chousernot a problem
23:10Chouserit's fun stage but won't last long. :-)
23:13Mark_Addlemani hope not! right now, i'm pushing myself through the frustration. the examples on the forum as well as this channel have been enormously helpful
23:38agchello