#clojure log - Feb 19 2011

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

0:01 halgari: can someone help me with an issue with lein?

0:01 rata_: amalloy: sorry, but then how do you know how many groups there are that have a repeated lastname?

0:01 halgari: ask

0:02 halgari: I have a bog-standard project.clj file. When I do lein-deps it says it can't find org.clojure:clojure:jar:1.2.0 and that I need to install it manually

0:02 is that normal? I created the project.clj via lein new.

0:04 rata_: amalloy: it should depend on n, the number of people that have a particular lastname (let's call it m) and the total number of people (let's call it P)

0:05 halgari: I haven't seen that before

0:06 amalloy: rata_: are you sure you have to handle the issue of double names? treat one of them as most-meaningful, or treat them as two separate people, or whatever

0:06 halgari: rata_ yeah, I'm on windows, but I downloaded lein, and did a lein self-install. That ran fine. From there I can't seem to get lein to do a thing

0:08 rata_: amalloy: even with just one name, it should depend on n, m and P

0:09 halgari: could you post the output in a gist?

0:09 scottj: halgari: lein was buggy on windows in the past but I would guess that feature should work

0:10 halgari: I have this question also posted on SO (http://stackoverflow.com/questions/5048911/lein-spitting-out-weird-errors) I was just hoping someone here may have a quick answer. Anyway, the errors are on SO

0:15 rata_: amalloy: because if I have n=3, m=3 and P=5, there are 5 ways over 10 to have a name repeated, but if I have P=6, I have then 7 ways over 20

0:16 amalloy: i've lost track of what m, n, and p are

0:17 rata_: n is the number people that make a group, m is the number of people that have a particular lastname and P is the total population

0:17 amalloy: ^

0:18 amalloy: rata_: p is only interesting at the end, for turning counts into ratios

0:18 for working with n and m, you can use the formula i gave earlier

0:19 rata_: halgari: weird error anyway... you should ask technomancy, but he's not here right now

0:19 halgari: rata_ : okay, thanks

0:29 rata_: amalloy: but p is important to count the number of groups, because a group is considered as positive when the lastname is repeated once, that is, when two of the n people have the same lastname

0:30 (when two at least)

0:31 robink: Is there a Clojure function that takes n arguments at the beginning and then applies them to the result of applying the previous (or first argument) to a list? Like (recurse 1 2 [[1 2 3] [4 5 6] [7 8 9]]) to yield 6?

0:31 * brehaut brain explodes

0:32 robink: Doing ((vec-of-vecs 1) 2) is a bit weird to me.

0:32 amalloy: robink: i think that's a little too vaguely defined

0:32 robink: amalloy: Sorry

0:32 gregh: so something like iterative function application?

0:32 robink: I actually don't want to do anything fancy, I just want C-style addressing of a faux 2d array.

0:32 gregh: That's probably more along the lines of what I want.

0:32 brehaut: ,(get-in [[1 2 3] [4 5 6] [7 8 9]] [1 2])

0:32 clojurebot: 6

0:33 robink: brehaut: Thanks!

0:33 amalloy: that works for nested maps and such; for the more general case you described to begin with i think you mean either reduce or iterate

0:34 shachaf: Hmm, robink.

0:37 robink: amalloy: Gotcha, looks like reduce would be what I'd need in that case.

0:39 amalloy: right. for example, get-in is actually implemented as ##(reduce get [[1 2 3] [4 5 6] [7 8 9]] [1 2])

0:39 sexpbot: ⟹ 6

0:41 robink: Which is probably the most compact form you could put it in.

0:42 amalloy: indeed

0:42 robink: amalloy: Thanks

0:44 pdk: i was wondering if it had that for a while

0:45 i was like "god why isn't there nth and get for nested structures"

0:46 robink: I'm too hung up on C-style indexing and the OO syntax of being able to go array.slice(0).slice(1) to do (get-in [[1 2] [3 4]] [0 1]) to get 2.

0:48 amalloy: robink: there are various mechanisms to do stuff "like that" in clojure as well

0:48 &(-> [[1 2 3] [4 5 6] [7 8 9]] (get 1) (get 1))

0:48 sexpbot: ⟹ 5

0:49 robink: Aha!

0:50 pdk: course yknow

0:51 amalloy: robink: the -> operator is actually a macro that restructures your code: ##(macroexpand-all '(-> [[1 2 3] [4 5 6] [7 8 9]] (get 1) (get 1)))

0:51 sexpbot: ⟹ (get (get [[1 2 3] [4 5 6] [7 8 9]] 1) 1)

0:51 pdk: (-> array (.slice 0) (.slice 1)) = array.slice(0).slice(1) now :p

0:51 when i read the docstrings for -> and ->> they made no sense

0:51 then seeing a code example was like

0:51 robink: Aha!


0:51 robink: heh

0:51 pdk: one of the rubs is that documentation is still spotty

0:52 terse at best in docstrings

0:52 amalloy: $google clojuredocs

0:52 sexpbot: First out of 357 results is: ClojureDocs - Community-Powered Clojure Documentation and Examples

0:52 http://clojuredocs.org/

0:52 pdk: well


0:52 robink: I suppose the best way to notate the fact that you can call a vec as a function (or as though it was one) is just to have a nested eval (([[1 2] [3 4]] 1) 0)

0:53 pdk: ,(-> [[1 2] [3 4]] (get 1) (get 0))

0:53 clojurebot: 3

0:53 pdk: i'd say that's probably a bit more explicit

0:54 robink: pdk: Except you're calling get on the vec and the index is the first argument, rather than calling 1 on the vec and then calling 0 on the resulting vec.

0:55 I'm sorry, the index is the second argument.

0:55 amalloy: i often forget i can treat a vector as a function. like, i know it's true, but i rarely think of using it

0:55 part of this is that i don't deal with indexes very often

0:56 pdk: equivalent result though so

0:56 scottj: and I think you're more likely to get an exception when treating vector as function

0:58 robink: scottj: So there's a special case with a vector, in that there isn't some core identity function associated with the type, but rather something bound to vectors in the interpreter?

0:58 amalloy: robink: that is incorrect

0:58 there is an IFn interface, which any type can implement in order to be treated as a function

0:59 brehaut: ,(ifn? [])

0:59 clojurebot: true

1:00 scottj: all I meant is ([] 1) vs (get [] 1) and (let [a nil] (a 1)) vs (let [a nil] (get a 1))

1:00 robink: amalloy: Gotcha.

1:01 Sorry, should've been amalloy, brehaut: Gotcha.

1:02 amalloy: it's okay, brehaut is used to being upstaged by my immense charisma

1:02 robink: heh

1:05 brehaut: its true

1:06 amalloy also cleans up my messes

1:06 amalloy: and boggles at your haskell

1:07 speaking of which, robink, when you're ready to have your mind really blown, google for rosetta clojure fibonacci

1:07 robink: scottj: Gotcha

1:07 amalloy: OK

1:08 brehaut: amalloy: i dont think the haskelly one is on rosettacode

1:09 amalloy: brehaut: i meant speaking of boggling, not speaking of haskell. not very clear, i suppose

1:09 brehaut: oh right

1:09 robink: The one I'm seeing (on rosettacode.org) has it do a lazy seq.

1:09 Which is really cool.

1:10 amalloy: robink: pretty much everything in clojure is a lazy seq

1:10 brehaut: thats the sensible lazy seq version

1:11 thers also a datarecursive version ;)

1:12 robink: brehaut: Woah

1:15 scottj: I'm so glad rich didn't stop with this: (defn ^:static fib ^long [^long n] (if (>= (long 1) n) (long 1) (+ (fib (dec n)) (fib (- n (long 2))))))

1:16 brehaut: that has some unecessary coercions doesnt it?

1:17 foxupa: hi

1:17 scottj: brehaut: maybe now, but it was written before all the prim work was where it's at now or even merged in 1.3 master

1:17 brehaut: oh right

1:18 foxupa: i'm trying to install clojure to work with emacs but when running M-x slime, I get an error: failed to download clojure jars.

1:18 scottj: foxupa: use lein, run lein swank, run M-x slime-connect in emacs

1:19 foxupa: how do i run lein swank? (i'm sorta new to emacs)

1:19 scottj: foxupa: do you have lein?

1:19 foxupa: nope

1:19 scottj: https://github.com/technomancy/leiningen

1:21 foxupa: so install lein, then lein plugin install swank-clojure "1.3.0-SNAPSHOT", then run lein new projectname ; cd projectname ; lein swank then go to emacs and M-x slime-connect

1:22 amalloy: scottj: isn't it just "lein install", ie no plugin? i think technomancy gave the same wrong instructions the other day then corrected himself

1:23 scottj: btw if you just want to try out clojure eclipse may be better option, you'll also have to make sure you're NOT running latest slime

1:23 amalloy: not sure, always install manually was just going based on README, maybe outdated.

1:24 foxupa: ok i got the git code but I can't get it to install with lein self-install (complains about not being able to download the jar file)

1:24 scottj: I'd guess install is for installing the current project in maven and plugin install is for installing it in lein's plugin dir

1:24 amalloy: and i use cake

1:25 but you'ore right, it certainly seems like install must do what you say :P

1:25 foxupa: i can't get lein to install... it complains that it can't find clojure.main

1:25 i already have clojure installed via aptitude from ubuntu

1:26 scottj: foxupa: git code? did you clone? I don't think you need to

1:26 another option is to just use inferior-lisp mode in emacs, what's your goal, to use clojure or slime?

1:27 foxupa: use clojure

1:27 i guess i don't need anythign fancy, i just want to be able to work with clojure in emacs they way i work with scheme

1:28 scottj: well, have you run clojure from command line?

1:28 foxupa: yes

1:28 scottj: (setq inferior-lisp-program "whatevercommand you run") M-x inferior-lisp

1:28 maybe

1:29 sorry if I'm leading you down a wrong path :)

1:30 amalloy: foxupa: throw away the aptitude version of clojure, it could conceivably be getting in the way and certainly isn't helping

1:30 scottj: I would double check that you followed the lein install instructions correctly bc it is nice to have when using other clojure projects

1:31 or you could give cake a try

1:32 foxupa: nm I think I will stick to my current setup

1:32 amalloy: foxupa: you might find http://blog.raynes.me/?p=48 useful

1:32 foxupa: i use eclipse with clojure plugin and then use emacs+

1:33 but thanks for the help, and that blog seems liek a good rea

1:33 read*

1:45 seancorfield_: am i a heretic for not liking emacs?

1:46 amalloy: seancorfield_: depends. how hard have you tried?

1:46 slyrus: yes

1:46 yes

1:47 seancorfield_: i used it years and years ago - it was amazing back then... but it feels the same today and other options have advanced dramatically

1:47 i think it was the mid-80's when i first used emacs

1:48 scottj: well it's definitely not the same today as it was in mid 80s :)

1:49 seancorfield_: really scottj? how has it changed? seriously... i installed it recently and it felt just the same as it did 25 years ago

1:49 amalloy: seancorfield_: i wrote a blog post about this too, since you were bugging me to blog

1:49 dnolen: seancorfield: one of the main reasons I still use it now is that it supports developing in many different programming languages *very* well: SML, Prolog, Haskell, Racket. Can't say that about many text editors.

1:50 amalloy: http://hubpages.com/hub/Why-old-text-editors-are-still-great

1:50 scottj: seancorfield_: well the basic idea is still the same, but most of the popular packages did not exist back then: magit, slime, ido, tramp, hippie, anything, org, etags, anything-complete

1:50 seancorfield_: dnolen: that's as maybe but other language support is actually irrelevant :)

1:51 dnolen: seancorfield_: it's certainly makes it easier to work through Rich Hickey's bookshelf.

1:51 seancorfield_: :) ok

1:51 dnolen: which may or may not be irrelevant

1:52 seancorfield_: i guess i've gotten very used to eclipse now

1:52 it supports every language i use and it feels more integrated

1:52 amalloy: seancorfield_: eclipse is fab for java

1:52 seancorfield_: it runs servers and understands the jee / jvm stack

1:52 well, yeah, and so is clojure :)

1:52 amalloy: and rates about the same "tolerable" as emacs does for php

1:53 but for lisps, emacs will always win

1:53 rata_: seancorfield: what do you have in eclipse that's not in emacs? (beside the general slowness of eclipse)

1:53 seancorfield_: i think that holds lisp languages back

1:53 one of the biggest complaints i see about lisp is emacs

1:54 if we want clojure to be accepted by the mainstream, it means embracing mainstream IDEs, regardless of what you think of them

1:54 scottj: rata_: well eclipse has a nicer debugging interface, and a more normal ui

1:54 dnolen: seancorfield_: I'm certainly not advocating that people use Emacs in order to learn Clojure.

1:54 seancorfield_: you won't get java devs to use emacs

1:54 scottj: clojure has always done a good job of embracing the big IDEs

1:55 I mean, clojure's eclipse plugin is arguably as good as scala's

1:55 amalloy: yeah, clojure has ccw, emacs, and textmate

1:55 scottj: in my experience better

1:55 amalloy: what's not to like

1:55 rata_: scottj: but the more normal ui is very expensive to use (in terms of time)

1:55 scottj: and from like year 1 it supported netbeans

1:55 seancorfield_: my main project is a mix of three languages - which all run on the jvm

1:56 the reality is that it's very, very hard to get people to switch IDEs

1:57 rata_: seancorfield: yes, but a clojure plugin is available in (almost?) any java IDE

1:57 scottj: clojure ppl generally aren't trying to, and for other lisps, it's probably important to recognize many of them predate the popular ides

1:58 rata_: intellij, netbeans and eclipse

1:58 scottj: and some of them have powerful ide's of their own

1:59 seancorfield_: i know, i'm just saying that pushing emacs is very off-putting for people outside the clojure/lisp community

1:59 luckily we do have a solution for "every" IDE

1:59 but the constant pushing of swank / emacs has a tendency to derail clojure newbies

2:00 instead, we should focus on offering them clojure in whatever IDE they already use

2:00 scottj: I think most ppl agree with you on that and have structured the getting started pages accordingly

2:01 rata_: yes, I think so too

2:02 scottj: re eclipse v emacs, since I think that's a more interesting topic, intellisense or whatever it's called is cool and all, but does it even work with clojure code, like in the repl?

2:03 (. foo aTAB/ctrl-space/whatever-it-is)?

2:04 seancorfield_: scottj: im not sure that even matters? it's really about welcoming n00bs and saying sure, use your favorite IDE, rather than waxing lyrical about emacs / swank every time

2:05 i guess i've just been reading too many essays about why lisp has never become really mainstream :(

2:05 amalloy: seancorfield_: of course it matters. if IDE features didn't matter, we'd all use notepad

2:05 scottj: seancorfield_: oh yeah, I'm not arguing that point, I'm interested in discussing your advanced alternatives

2:05 seancorfield_: amalloy: no, it's really about what ppl are used to

2:06 scottj: I wouldn't rate emacs very high on as a reason lisp didn't take off since emacs itself has taken off

2:06 seancorfield_: if someone uses notepad (really?) then they should be welcomed that they can use notepad to write clojure

2:06 scottj: i never said they were advanced - i don't think eclipse is better than emacs (or vice versa)

2:07 scottj: other than ppl not writing blog posts about how awesome notepad+clojure is, I don't see how they aren't being welcomed

2:07 seancorfield_: it's just the attitude

2:07 scottj: no, really, emacs has _not_ taken off

2:07 i don't know anyone outside the lisp community who uses emacs

2:08 dnolen: seancorfield_: Scala, Haskell ?

2:08 scottj: there are lots of ppl in here who use vim/eclipse, are they unwelcome?

2:08 seancorfield_: are you kidding me? I know tons of programmers/sysadmins/whatever outside lisp who use it

2:08 tons of scientists/math peeps

2:09 seancorfield_: that's not mainstream

2:09 dnolen: seancorfield_: Clojure is never going to be more popular then Java. Perhaps it can eventually get to Ruby levels of success.

2:09 scottj: on linux I'd say emacs is mainstream

2:10 seancorfield_: scottj: that may have been true five years ago... not now

2:10 dnolen: you may be right but i'd _love_ to see clojure do more than that

2:13 Adamant: dnolen: now or in 5-10 years

2:14 Java is on the way down

2:14 seancorfield_: Adamant: true, but other JVM languages will most likely fill that space...

2:15 Adamant: seancorfield_: like what? Scala and Clojure are the only real long-term contenders

2:16 seancorfield_: IF they are approachable

2:16 Adamant: even the guy who wrote Groovy said he wouldn't do it again now that those two are out

2:16 dnolen: It took Ruby and Python 15-20 years to get to where they are now. As awesome as Clojure is, these things take time. How many people out there even know what Functional Programming is,

2:16 http://research.microsoft.com/apps/pubs/default.aspx?id=141506

2:16 Adamant: seancorfield_: true, but there's more or less a formula for that at this point

2:16 dnolen: november 2010 ^

2:17 seancorfield_: i agree, but that doesn't mean folks will flock to scala/clojure... and frankly scala is way more approachable to java devs even tho' clojure is a MUCH better language IMO

2:18 scottj: what's cool about clojure is it has a very vibrant community/library despite having an insignificant market share. I suspect that will continue.

2:18 seancorfield_: ruby only got where it is because of rails... and python really doesn't stand alone... the applications drive that...

2:19 scottj: i agree clojure has a great community but we have to be careful to avoid the lisp syndrome :)

2:20 Adamant: avoiding Lisp syndrome is good, modeling good behavior in other communities is even better

2:21 everyone trying to promote a new language should look at the way the Haskell community operates and behaves, IMO

2:21 whatever your opinion on Haskell the language

2:22 scottj: explain how you think they operate

2:24 Adamant: avoid assuming negative intent from new contributors until proven otherwise. hit trolls with patient explanations instead of fury. be nice to all newbies, even their questions aren't the best. have room for a very broad spectrum in the community. tinker with how the community works now and then.

2:26 have a social expectation of reasonable behavior from everyone involved, from top to bottom, mod/compiler hacker to noob, and stick with it.

2:29 rata_: Adamant: I think the clojure community does a very good job regarding that as well, with some few exceptions

2:29 Adamant: rata_: yes, I certainly wouldn't accuse the Clojure community of being bad at any of those

2:29 I probably wouldn't be here if it was

2:30 rata_: me too

2:31 I started (in lisp) with CL but run away from the language mainly because of the community

2:31 seancorfield_: i think the clojure community is way more welcoming than the haskell community (and i like haskell)

2:31 Adamant: I use Haskell as an example because they seemed to be doing it very early on, have done it consistently well, and it's made a huge impact in their long-term viability

2:31 seancorfield_: the first real community i got involved with was the c++ community

2:31 Adamant: seancorfield_: possible. I like Haskell too but they aren't perfect, none of us are.

2:31 seancorfield_: haskell is relatively new

2:31 :)

2:31 Adamant: well, early 1990's

2:32 but the language was reborn with monads

2:32 that was 2000-sh

2:32 *ish

2:32 seancorfield_: my first exposure to FP was back in the early/mid 80's

2:32 Adamant: ah, what language

2:33 mine was SICP

2:33 seancorfield_: sasl and miranda were 'hot' then... i created SURE as part of my research work... prof turner (miranda) later said he wished i'd written it up :)

2:33 Adamant: nice!

2:34 never heard of SURE, will need to look it up

2:34 seancorfield_: i built a lispkit interpreter based on henderson's book, and then built SURE on top of that

2:34 my university used it as their teaching language for five or so years

2:36 rata_: amalloy: may I come back to the combinatorics topic? there are some things I didn't understand

2:46 dnolen: heh, https://docs.google.com/present/view?id=0AS8emH3-FLt3ZGRtbWJyOGdfMTFmcDZkcTk2cw&hl=en

2:46 nice to see we're not the only one that struggle to optimize our code. many of the same issues.

2:46 from the Northeast Scala Conf

2:52 brehaut: there are some amazing gotchas in there

3:04 Null-A: Does clojure support lazy strings?

3:04 I have a lazy seq of chars, and I want to pass it to re-seq, as a string, to get a new lazy seq

3:09 chouser: Null-A: If you implement CharSequence on top of that lazy seq of chars, you may be able to get what you want.

3:10 Null-A: chouser: hm i'll take a look

3:12 chouser: the Java regex stuff works on CharSequence, iirc, which is an interface you can implement using reify

3:12 Null-A: chouser: *nods* testing now :)

3:12 this seems like something that should be in clojure api

3:15 chouser: looks like you'll have to lie about the length in order to avoid realizing the entire lazy seq up front

3:15 Null-A: chouser: yah I was just thinking about that

3:16 infinite it is :-/

3:17 chouser: I bought your book btw, a couple months ago

3:17 i'm friends with nathan marz

3:18 chouser: Null-A: thanks! Excellent fellow, that Marz.

3:18 Null-A: :) he's having a workshop this saturday

3:18 on cascalog

3:21 chouser: well, this seems to work as long as your input sequence really is infinite

3:21 (defn charseq [s] (reify java.lang.CharSequence (charAt [_ i] (or (first (drop i s)) \0)) (length [_] Integer/MAX_VALUE) (subSequence [_ a b] (charseq (take (- b a) (drop a s)))) (toString [_] (apply str s))))

3:22 but something gets messed up if you walk past the end of a non-inf seq

3:22 and I should go to bed rather than figure it out. So, good luck!

3:28 Null-A: k thanks

3:28 I tried coding something but got classcast exception, i'll try yours

4:38 chouser: re-seq 's implementation is O(F(charsequenc.length)) :( When you run it on the charseq CPU goes to 100%

4:39 chouser: My re-seq was just tokenizing, so I reimplemented it with partition-by

5:32 chris780: Hi, I'm pretty new to clojure and I'm having a problem with Leiningen, is this an OK place to ask for a little help :)

5:33 raek: chris780: go ahead :)

5:35 chris780: Excellent, thanks. I'm trying to initialise a project with appengine-magic. I've used lein new to create the structure and added [appengine-magic "0.3.3"] to the dependencies, when I use lein deps it doenloads them. However, despite downloading them and putting them in the classpath, it doesn't see the new lein tasks provided. Is there something I can do to get more debug out of this or is there anything else I need to do?

5:37 mids: chris780: did you add them to :dev-dependencies?

5:37 chris780: ah, no, only to my :dependencies

5:38 now I see my mistake

5:38 thanks a lot!

5:39 brilliant that worked. Silly noob, arn't I :)

9:14 mids: what pattern do you use to name your test functions?

10:24 gfrlog: ,(take 5 (repeatedly (partial swap! (atom 0) inc)))

10:24 clojurebot: (1 2 3 4 5)

10:25 gfrlog: so if I find myself wanting to call (send) but then also block until the function is finished executing, that means I'm probably doing something wrong, right?

10:28 it all started when I was using side effects inside swap!...

10:37 schaf__: can someone point me to a download link for the emacs refcard?

10:37 pdk: gfrlog you may want to consider iterate in that case as well

10:37 schaf__: its metioned here, http://www.gnu.org/software/emacs/ but i'd like topost a direct link

10:37 pdk: ,(take 5 (iterate inc 0))

10:37 clojurebot: (0 1 2 3 4)

10:38 gfrlog: pdk: I agree. I was just trying to be clever actually.

10:38 In my code the (partial swap! (atom 0) inc) part came in quite handy

10:38 pdk: last time i posted a code sample with an atom and doseq in it here

10:38 amalloy beat me with a switch!

10:39 TimMc: ,(defn foo [^Flibber e] 5)

10:39 clojurebot: DENIED

10:39 TimMc: ^ Anyway, it's interesting that I can use nonexistent types for hinting (when you aren't dealing with a surly bot.)

10:41 gfrlog: ,(let [foo (fn [^Flibber e] 5)] (foo "tomas"))

10:41 clojurebot: 5

10:41 gfrlog: TimMc: it just won't let you def stuff

10:41 TimMc: ,(let [foo (fn [^Flibber e] (.nothing 5))] (foo "tomas"))

10:42 clojurebot: java.lang.IllegalArgumentException: No matching field found: nothing for class java.lang.Integer

10:42 TimMc: ,(let [foo (fn [^Flibber e] (.nothing e))] (foo "tomas"))

10:42 clojurebot: java.lang.IllegalArgumentException: Unable to resolve classname: Flibber

10:42 gfrlog: ah ha

10:42 TimMc: It's only when you try to call methods on a bad hint that it yells at you.

10:42 gfrlog: ,(let [foo (fn [^Flibber e] (.substring e 2))] (foo "tomas"))

10:42 clojurebot: java.lang.IllegalArgumentException: Unable to resolve classname: Flibber

10:42 gfrlog: ,(.substring "tomas" 2)

10:43 clojurebot: "mas"

10:43 gfrlog: even if the method exists on the real object

10:44 TimMc: I ran into this in my own code. I had an empty (pending) function that had the hint ^MouseMoveEvent in its argument list, and I only noticed today that there is no such class.

10:44 gfrlog: not yet

10:46 TimMc: heh

10:48 gfrlog: ,(let [MouseMoveEvent String, foo (fn [^MouseMoveEvent e] (.substring e 2))] (foo "tomas"))

10:48 clojurebot: java.lang.IllegalArgumentException: Unable to resolve classname: MouseMoveEvent

10:48 gfrlog: dang

10:48 I wonder if Ruby lets you do that

10:48 TimMc: No such luck.

10:48 raek: you can turn (set! *warn-on-reflection* true) if you want the compiler to notify you when it can't resolve the method call to a direct one (and would need a type hint to do so).

10:48 TimMc: You're stuck with the existing classnames.

10:49 raek: In this case, it's not even trying to resolve a classname.

10:50 I wouldn't call it a bug, just... surprising.

10:50 gfrlog: ,(let [rich-hickey clojure.core] (rich-hickey/+))

10:50 clojurebot: java.lang.ClassNotFoundException: clojure.core

10:50 TimMc: heh

10:51 raek: (my idea was that you can use *warn-on-reflection* to tell when the compiler actually needs the type hints)

10:51 gfrlog: does clojure gain anything by abstracting null to nil? Is there any abstraction or is it just a renaming?

10:52 raek: it's just a renaming

10:52 gfrlog: raek: any idea what the thought process is there? seems needlessly confusing

10:53 maybe he didn't want to imply the JVM implementation...

10:55 lucian: gfrlog: nil is more lispy

10:55 gfrlog: lucian: I can accept that.

10:55 lucian: it's also one letter shorter

10:56 gfrlog: I wonder how many keystrokes it has saved me

10:56 lucian: although looking at first and last (which btw i love), i don't think it was a major concern

10:56 raek: gfrlog: I would suspect that it's a traditional name (but does Scheme use null for this?)

10:56 gfrlog: first and last like the functions?

10:56 ,(doc second)

10:56 clojurebot: "([x]); Same as (first (next x))"

10:57 gfrlog: ,(doc second-to-last)

10:57 clojurebot: Huh?

10:57 gfrlog: oh well

10:57 pdk: you could do (last (drop n x))

10:57 say (last (drop 1 x)) = (second-to-last x)

10:58 (doc drop-last)

10:58 clojurebot: "([s] [n s]); Return a lazy sequence of all but the last n (default 1) items in coll"

10:58 pdk: correction

10:58 (last (drop-last 1 x))

10:58 or skip the 1 and just use x as an argument

10:58 lucian: raek: scheme has no null in the same sense as java. it has '()

10:59 gfrlog: ,(= nil '())

10:59 clojurebot: false

10:59 gfrlog: ,(vector nil '() false [] #{} {})

10:59 clojurebot: [nil () false [] #{} {}]

10:59 gfrlog: so much nothingness

10:59 ,(vector nil '() false [] #{} {} "")

10:59 clojurebot: [nil () false [] #{} {} ""]

11:00 pdk: (map true? [nil '() false [] #{} {}])

11:00 ,(map true? [nil '() false [] #{} {}])

11:00 clojurebot: (false false false false false false)

11:00 gfrlog: ,(keyword "")

11:00 clojurebot: :

11:00 gfrlog: ,(symbol "")

11:00 pdk: also note you don't need to quote a list with nothing in it

11:00 gfrlog: pdk: fascinating

11:00 pdk: so () and '() behave the same

11:00 gfrlog: did clojurebot just break on the empty symbol?

11:00 pdk: and just return themselves

11:01 gfrlog: ,(println "I'm still here")

11:01 clojurebot: I'm still here

11:01 pdk: it sandboxes stuff each time you send a code line i think

11:01 gfrlog: ,(str "Happy" (symbol "") "okay")

11:01 clojurebot: "Happyokay"

11:01 gfrlog: ,(class (symbol ""))

11:01 clojurebot: clojure.lang.Symbol

11:01 gfrlog: ,(vector nil '() false [] #{} {} "" (keyword "") (symbol ""))

11:01 clojurebot: [nil () false [] #{} {} "" : ]

11:02 pdk: trying (symbol "") in a local repl just prints a blank line

11:02 gfrlog: so there's an empty symbol at the end of that vector, it's just really skinny

11:02 pdk: so it probably said nothing since the response line was empty

11:02 gfrlog: rig7ht

11:02 right*

11:02 ,(println "")

11:02 interesting

11:03 ,(fn [])

11:03 clojurebot: #<sandbox$eval1527$fn__1528 sandbox$eval1527$fn__1528@1303a7a>

11:04 pdk: it never prints out the code of a fn or whatever literally unless you ask, just a reference to it and its internal symbol

11:04 gfrlog: yeah

11:05 does a function carry its source code in the metadata or something?

11:05 raek: no

11:06 pdk: if i recall cl at least has a macro to print the code to a given function

11:06 dunno about clojure

11:06 clojure does have macroexpand and macroexpand-1 at any rate

11:06 raek: but a var does contain metadata for source file and line number

11:06 gfrlog: I wrote a persistent memoization function once. Used a macro to extract the name of the function, but had to clear the database manually whenever I changed the code

11:07 could have also examined the src with the macro I suppose

11:07 then use that in the database

11:07 pdk: clojure has a macro out of the box to memoize a fn

11:07 gfrlog: you just mean (memoize), right?

11:07 ,(doc memoize)

11:07 pdk: p much

11:07 clojurebot: "([f]); Returns a memoized version of a referentially transparent function. The memoized version of the function keeps a cache of the mapping from arguments to results and, when calls with the same a...

11:07 pdk: there's also defn-memo somewhere in contrib

11:07 gfrlog: I wanted persistence

11:07 pdk: granted

11:08 gfrlog: so I did (defmacro defn-memoized...)

11:08 raek: function objects do not have names, but vars do

11:08 gfrlog: right

11:14 TimMc: So (some f xs) will get me the first true output of f... what if I want the first input for which f returns true?

11:14 Ach, first filter

11:20 gfrlog: what was I going to ask?

11:20 oh right

11:20 ,(doc update-in)

11:20 clojurebot: "([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...

11:20 gfrlog: is there a function that does this but for just one level?

11:20 (defn update [m k f & args] (update-in m [k] f & args))

11:20 like that

11:21 sexpbot: help

11:21 sexpbot: You're going to need to tell me what you want help with.

11:22 gfrlog: sexpbot: what can you do?

11:22 sexpbot: It's AWWWW RIGHT!

11:22 gfrlog: sexpbot: help commands

11:22 sexpbot: gfrlog: http://github.com/Raynes/sexpbot/wiki/Commands

11:22 gfrlog: sexpbot: awesome thanks

11:28 TimMc: gfrlog: You don't like the extra set of square brackets?

11:29 gfrlog: TimMc nosir

11:29 nor the extra hyphen, "i", and "n"

11:30 TimMc: heh

11:32 (assoc m k (apply f args))?

11:34 gfrlog: TimMc: no I think you'd have to (assoc m k (apply f (m k) args))

11:34 TimMc: Oh! Right.

11:34 gfrlog: which is more repetition than I'd like

11:35 I don't like specifying the map and key twice; so I'd use update-in first

11:35 TimMc: I guess you'll just have to def'ine it.

11:36 gfrlog: yeah; it's a hassle to maintain your own utils though.

11:36 TimMc: Really?

11:36 gfrlog: across projects...

11:36 TimMc: ah

11:36 gfrlog: another one I'm a fan of is map-from-fn

11:37 TimMc: Hm?

11:37 simard: is it possible to have a (for..) that updates each variable at every iteration ? ie.. not a nested for

11:37 gfrlog: (fn [ks f] (into {} (map (juxt identity f) ks)))

11:38 simard: do you have an example of what you're trying to do?

11:38 TimMc: simard: loop?

11:38 wait, nvm

11:39 simard: loop could do but I like the way for collects automatically elements

11:39 raek: simard: making you own lazy sequence (the recursive call would "update" the variables)

11:39 simard: gfrlog: I want to access to elements of a grid diagonally

11:40 so I made an (at-xy [x y g]) function

11:40 TimMc: simard: You want to walk through multiple seqs at the same time?

11:40 simard: and now I want to return a diagonal

11:40 raek: (but this is equivalent to the loop approach mentioned by TimMc, modulo laziness)

11:40 TimMc: (for [[x y] (map vector (range ...) (range ...))] ...)

11:41 (does that make sense?)

11:41 simard: not quite yet hehe

11:41 gfrlog: there's gotta be an easier way to do the diagonal thing

11:41 simard: wait yes it does..

11:41 gfrlog: simard: this is a 2d vector?

11:41 raek: simard: (for [i (range ..)] (at-xy i i g)) ?

11:41 simard: gfrlog: it's a 2d list

11:42 gfrlog: raek's idea is what I was thinking of

11:42 simard: raek: that's what I'm doing, but actually instead of i i I need to calculate x and y from one of the two, say x

11:42 raek: or maybe (for [i (range ...)] (-> g (nth i) (nth i)))

11:42 simard: I wasn't clear enough

11:42 I didn't mean only the main diagonal

11:43 ANY diagonal

11:43 in any direction

11:43 that's why I need to do the for on two variables at the same time

11:43 TimMc: your solution might well be what I want

11:44 raek: I'm thinking of something like (for [i (range ..), :let [[x y] (coord-fn i)]] (at-xy x y g))

11:44 gfrlog: I think you could use for with x and compute the y based on what diagonal you want

11:44 simard: gfrlog: I'm doing that already, but it's harder to understand

11:45 raek: where coord-fn is a function that returns a [x y] coordinate pair from an index

11:45 simard: ie, understand what does on with the other coordinate by reading the code

11:45 gfrlog: I wonder if there's a way to define a function on pairs

11:45 simard: s/does/goes/

11:45 sexpbot: <simard> ie, understand what goes on with the other coordinate by reading the code

11:45 gfrlog: like applying [inc dec] to [x y]

11:45 simard: gfrlog: that would be even neither

11:45 neater

11:46 gfrlog: (defn diagonal-step [[f1 f2] [x y]] [(f1 x) (f2 y)])

11:46 raek: I think (for [[x y] (map vector (range ...) (range ...))] ...) is equivalent to (map (fn [[x y]] ...) (range ...) (range ...))

11:46 gfrlog: then you could use iterate and take-while

11:47 as in (take-while coordinate-valid? (iterate (partial diagonal-step [inc dec]) [x y])))

11:48 raek: neat.

11:48 gfrlog: thx

11:49 simard: you could even name is planar-step instead of diagonal now ;)

11:49 s/is/it/

11:49 sexpbot: <simard> you could even name it planar-step instead of diagonal now ;)

11:49 simard: hum I'm have a hard time with spelling today

11:49 wow

11:49 gfrlog: sexpbot is amazing

11:49 simard: again..

11:49 gfrlog: s/sexpbot/clojurebot/

11:49 sexpbot: <gfrlog> clojurebot is amazing

11:49 gfrlog: sexpbot: you said it

11:50 TimMc: Can I get = like in Java?

11:50 I want actual object identity.

11:50 gfrlog: ,(doc identical?)

11:50 clojurebot: "([x y]); Tests if 2 arguments are the same object"

11:50 TimMc: nice

11:50 gfrlog: ,(identical? 8 (+ 4 4))

11:50 clojurebot: true

11:50 gfrlog: ,8M

11:50 clojurebot: 8M

11:51 gfrlog: ,(identical? 8M (+ 4M 4M))

11:51 clojurebot: false

11:51 gfrlog: cool

11:51 I feel like identical is a weird name for that...

11:51 though it does sound etymologically like "identity" so maybe I'm just wrong

11:54 maybe it's because of phrases like "identical twins"

12:06 edoloughlin: Is there a less expensive way of adding to the start of a vector than (vec (cons :a [1 2 3])) ?

12:10 raek: edoloughlin: no. do you happen to need to add at one end and remove from the other?

12:12 gfrlog: finger trees?

12:13 edoloughlin: raek: No, just add to the start.

12:13 raek: Thanks.

12:15 gfrlog: edoloughlin: maybe assemble it backwards or use lists instead?

12:15 depends on what you have to do with it...

12:15 edoloughlin: gfrlog: Backwards. That's an idea!

12:28 simard: if I need a function to have access to a local variable of the caller without passing it explicitly as an argument, my best bet is using letfn ?

12:28 (ie, do a closure ?)

12:32 khaliG: i called filter on a map and wound up with a sequence of [key val] vectors. Whats the best way to turn this back into a map?

12:36 Chousuke: khaliG: (into {} yourseq)

12:37 khaliG: chouser, pretty. thanks!

12:39 raek: simard: yes. a function of some kind (anonymous, let'ed, partial application) is fine

12:40 khaliG: incidentally is my use of filter as good as it can be, (filter (fn [[k v]] v) map) for non-nils?

12:40 Chousuke: simard: the function won't have access to any locals in the caller's scope unless the function was also generated in the caller's scope though.

12:41 khaliG: use val instead

12:41 ie. (filter val ...) :P

12:41 khaliG: lets see

12:41 Chousuke: your function basically does that

12:41 khaliG: that's magic

12:43 simard: Chousuke: so that means there's no way to write the body of that function outside the called, ie.: I think it would be cleaner (ie more readable) if that body was elsewhere)

12:44 s/called/caller/

12:44 sexpbot: <simard> Chousuke: so that means there's no way to write the body of that function outside the caller, ie.: I think it would be cleaner (ie more readable) if that body was elsewhere)

12:44 Chousuke: simard: the you'll need to pass the things as a parameter

12:44 bmh: Is there an efficient way to partition matrices in incanter?

12:44 Chousuke: simard: you can of course make a function that makes a function and then just do (let [whatever (make-fn thething)] (whatev

12:45 er, oops

12:45 pressed enter by accident but you get the idea

12:45 simard: yeah, so passing the argument only at function creation..

12:45 khaliG: how does val do the same thing, (val [:b 2]) is invalid :/

12:45 simard: makes sense !

12:46 Chousuke: khaliG: val works on map entries

12:46 khaliG: which is what you have when you filter a map

12:46 they just happen to look like vectors :)

12:46 khaliG: oh wow, i see

12:46 so much to learn

12:46 :)

12:46 Chousuke: second works too

12:47 on both vectors and map entries

12:47 khaliG: ok i use filter another place, same thing except its (not v), can val be used here too?

12:47 Chousuke: you can use (complement val) I guess

12:48 or remove instead of filter.

12:48 khaliG: oh yea, remove makes sense

12:48 Chousuke: choices, choices...

12:49 khaliG: actually i see a better way to write both, using group-by and val

13:33 simard: I want to do (f '((1 2 3) (4 5 6))) -> (1 2 3 4 5 6), what function should I use ?

13:34 hum apply concat

13:34 ejackson: simard: or flatten

13:42 khaliG: ugh, sometimes i really miss mutation :(

13:43 ive managed to avoid it by rebinding the same var inside sometimes etc, but now i really need it, i think

13:49 dnolen: Notes on Continuation-Passing Style in Clojure, http://dosync.posterous.com/continuation-passing-style-in-clojure

13:50 khaliG: this might be a stupid question, but can you write inline java code somehow?

13:53 TimMc: khaliG: Why would you want to?

13:53 I find Clojure to be the best way to write Java, personally.

13:54 Anyway, you can always write some .java files and talk with them from Clojure.

13:54 khaliG: TimMc, because i cant write this purely functionally, i have six variables that i need to reason with and assign the correct value

13:55 TimMc: Well, you *can* still use mutation -- use (do ...) and the -> and .. macros liberally.

13:55 That seems to work just fine for mutation-oriented computation.

13:56 khaliG: hm is there a place i can read an example? sorry i'm lost :/

13:58 TimMc: khaliG: Here is a very small example of using Java GUI libs: https://github.com/timmc/CS4300-HW3/blob/master/src/timmcHW3/gui.clj#L90

14:00 Is there an idiom for replacing or updating the last element of a vector?

14:01 nvm, I need to do more than that.

14:02 khaliG: TimMc, i guess i'm looking for a SET! method

14:02 TimMc: There are refs.

14:02 khaliG: i dont see how do or -> helps that need

14:02 TimMc: Are you trying to mutate Java objects or modify Clojure variables?

14:02 khaliG: clojure ones

14:03 TimMc: http://clojure.org/refs or maybe atoms.

14:03 scottj: or often a big let with "reassignment" is used

14:05 TimMc: Oh yeah, I've used that too.

14:05 khaliG: yea same, but its limited

14:05 scottj: khaliG: but there's nothign wrong with writing part of your app in java

14:06 you write it in a separate java class file and then put it where your build tool expects it

14:07 khaliG: we're talking about a single function here though :/

14:07 TimMc: khaliG: Can you give more info about what you are writing?

14:07 khaliG: TimMc, let me write it up and paste, one minute please

14:09 TimMc: As for my own problem... I have a vector of vectors, and I want to add a value to the last inner vector. If the outer vector is empty, I want to make a new inner one to conj onto the end.

14:09 One approach I was going to take was to do a combo of peek and pop, alter the peek'd value, and conj it back on to the result of pop.

14:10 The problem with this approach is that pop throws an exception with the empty vector instead of returning nil or something.

14:10 So, any suggestions?

14:11 scottj: there's only two levels of vectors right?

14:12 khaliG: http://clojure.pastebin.com/mrzLLDMT

14:12 TimMc: scottj: Right.

14:13 I could write (defn pop-lax [v] (if (seq v) (pop v) [])) but was wondering about alternatives.

14:15 tomoj: how do new inner vectors get there after the first?

14:16 simard: is it possible to do something like that ? (let [fibs (lazy-cat [1 2] (map + fibs (rest fibs)))])

14:16 ie.. define fibs only for the scope of the let

14:19 ihodes: simard: look at let-fn

14:19 make that letfn

14:19 TimMc: tomoj: Here's what I have written: https://gist.github.com/835284

14:20 ihodes: simard: equivalently, you could (let [my-fn (fn [x] x)] body)

14:20 TimMc: Each call to append-vertex! should add a point to the last inner vector, or if the outer vector is empty, conj on a new inner vector just containing the new point.

14:21 scottj: ihodes: I think he's wondering if there are issues with lazy seqs getting gced

14:22 ihodes: scottj: just noticed he wrote fibs and not fns, sigh. haha

14:22 tomoj: TimMc: ok, but how do you ever have more than one inner vector? just curious

14:22 simard: scottj: yes, that's indeed the initial reason why I'm trying a let, but the problem right now is not being able to reference fibs from within the definition of fibs :S

14:22 ihodes: simard: in that case, yes, that works. but letfn will solve the reference issues :)

14:22 TimMc: tomoj: Repeated calls to append-vertex!.

14:23 simard: ihodes: thanks :)

14:23 tomoj: but if append-vertex! always conjs to the last inner vector..

14:23 won't it create the one inner vector and then just conj onto it forever?

14:23 ihodes: simard: sorry, i'm being confusing. what i said with letfn should solve your issue *goes off to not talk anymore*

14:23 TimMc: Oh! Sorry. There are other functions for that.

14:24 Or rather, will be.

14:25 tomoj: "userdata" seems like a strange name to me

14:26 TimMc: tomoj: I have a several global refs, one of which contains the user's data -- the values of that ref get shoved into undo and redo buffers.

14:27 Program state and view state are kept in other data structures.

15:12 markskilbeck: How can I get the index at which an element appears in a collection?

15:15 Scriptor: markskilbeck: check out http://groups.google.com/group/clojure/browse_thread/thread/3f23f91ed6eb57c5

15:16 stuartsierra: markskilbeck: `map-indexed` and `some`

15:16 Scriptor: doesn't `some` only return true/nil?

15:17 DespiteItAll: some returns the value found

15:17 markskilbeck: ,(doc some)

15:17 clojurebot: "([pred coll]); Returns the first logical true value of (pred x) for any x in coll, else nil. One common idiom is to use a set as pred, for example this will return :fred if :fred is in the sequence,...

15:18 Scriptor: it seems to just reutrn the result of the predicate call

15:19 markskilbeck: Hm, yeah

15:19 khaliG: erm, contains? always returns false on a list? :s

15:20 brehaut: khaliG: contains? tells you if a given key exists in a collection

15:20 lists arent keyed

15:20 and vectors are keyed by their index

15:20 ,(contains? [:a :b :c] 1)

15:20 clojurebot: true

15:20 brehaut: ,(contains? [:a :b :c] :a)

15:20 khaliG: that's pretty useless :/

15:20 clojurebot: false

15:21 brehaut: khaliG: no, its just not the function you are looking for

15:22 khaliG: there isn't such a function is there? i've read .contains might work

15:22 brehaut: ,(.contains [:a :b :c] :a)

15:22 clojurebot: true

15:22 markskilbeck: stuartsierra: not quite sure how that would look.

15:23 brehaut: khaliG: if you are used to other dynamic languages, clojure might seem a bit weird because its core functions are much more precise in their meaning ussually

15:23 khaliG: brehaut, just the names are counterintuitive

15:24 Patrick-DC: Which library do you guys think is the best for building GUIs in Clojure?

15:24 brehaut: khaliG: the doc functions is always close by ;)

15:24 khaliG: Patrick-DC, i'm using mig-layout and swing, works pretty good

15:25 Patrick-DC: Thanks!

15:25 How do the windows look?

15:25 Like, you know how Tk looks awful in Gnome?

15:26 But GTK+ looks awesome

15:26 stuartsierra: markskilbeck: (some identity (map-indexed (fn [i x] (when (pred x) i)) the-sequence))

15:26 khaliG: Patrick-DC, they look ok, depending on the look-and-feel, you can choose one you like.

15:26 Patrick-DC: While Tk looks okay in Windows

15:26 Sweet

15:26 brehaut: Patrick-DC: swing does have a native gtk look and feel

15:27 Patrick-DC: Awesome, thank you very much for your advice

15:27 Is it easy to tune the look and feel for different platforms?

15:27 khaliG: yep, check out nimbus which looks nice on windows and linux

15:27 brehaut: Patrick-DC: it defaults to platform native

15:28 Patrick-DC: Thanks brehaut

15:28 brehaut: Patrick-DC: like all cross platform toolkits you have your work cut out actually making it look good on all the platforms

15:28 (one platform is easy)

15:28 Patrick-DC: haha

15:28 khaliG: why would you want it to look good? motif all the way!

15:28 Patrick-DC: (haha '(one platform is easy))

15:29 (? (look-good (in (motif) (windows))))

15:30 khaliG: it looks like motif, i wouldn't say good, but i like it

15:30 if you're into that retro look :)

15:31 Patrick-DC: which (motif or swing) would you surmise has better facilities for alpha compositing?

15:31 Like transparency of layered windows and stuff

15:31 khaliG: no you misunderstood, motif is one particular look and feel that is available, that's all

15:32 Patrick-DC: ahh, okay

15:32 so can it do compiz, too?

15:33 brehaut: Patrick-DC: i dont know what it looks like in linux but https://github.com/mattdw/space-clock

15:35 although i notice that it has no project stuff at all. it might be a clj 1.0 project

15:36 Patrick-DC: i'm using using ubuntu with gnome and compiz, and the clock is awesome except it has no window border

15:36 sorta minimalistic

15:36 brehaut: ok i thought it might have had a window border

15:36 as a bug in linux

15:37 Patrick-DC: its really old code; dont use it as a guide! but it shows you that you can easily do compoisited stuff in linux with swing

15:37 Patrick-DC: haha thanks! how can you compile the clock to an applet and make it run in a browser?

15:37 brehaut: i have no idea

15:38 Patrick-DC: I just started learning clojure, but I've been learning common lisp for a few months

15:38 hmmmm, I'm going to find out how

15:58 rata_: hi

16:09 khaliG: http://clojure.pastebin.com/wwpArn6K

16:09 if someone can see how to write this functionally please give me a hint

16:13 tomoj: I think you're probably going to have to do a better job than your code at explaining what you're doing

16:14 rata_: how do you divide a j.m.BigInteger?

16:15 khaliG: tomoj, it would be much clearer in C or java :/

16:15 bobo: rata_: http://download.oracle.com/javase/1.5.0/docs/api/java/math/BigInteger.html#divide(java.math.BigInteger)

16:16 rata_: khaliG: what are you trying to do?

16:16 that code seems like you're trying to write C in clojure

16:16 khaliG: i'm trying to solve for an unknown value

16:17 tomoj: khaliG: that implementation would be much clearer, sure

16:17 rata_: khaliG: you're trying to solve what?

16:18 tomoj: your code still wouldn't say anything about what you're actually doing, I predict :)

16:20 khaliG: i start with a map of values, solve the unknowns (nils) using the knowns, and then return a map with the unknowns filled in, if possible

16:20 rata_: khaliG: how do you compute the unknowns?

16:20 khaliG: i have an equation

16:21 arithmetic one, its very simple

16:21 see the paste before that (column on the left side of the page)

16:22 yes it took me 2 hours to do this.. would have taken 2 minutes in a non-functional language :/

16:23 rata_: bobo: .divide returns a BigInteger, which is not exact... also I don't know if the number I want to divide is a BigInteger or not, so I'd have to put an (if (instance? ...) ...) there, which seems a bit dirty

16:23 bobo: oh :-/

16:26 rata_: khaliG: why do you have those numbers in a map instead of a vector?

16:27 khaliG: rata_, no particular reason, just what i'm used to

16:27 rata_: ok

16:27 khaliG: but that might help, i guess?

16:35 TimMc: khaliG: I think I see what to do...

16:36 khaliG: TimMc, lets hear it

16:36 TimMc: Let me get a better picture of what this function does.

16:36 khaliG: sure thing

16:36 TimMc: Each if statement is checking if certain keys are set

16:37 rata_: khaliG: http://clojure.pastebin.com/WxrEi1fR

16:37 TimMc: and then if so, computing the value for a dependent key.

16:37 khaliG: rata_, ooh, damn, that is good

16:38 TimMc, see rata's paste, its much clearer

16:38 TimMc: Ah! It is an over-specified set of values.

16:39 khaliG: not quite because this will fail if at least 2 are not knowns

16:39 you'd have to catch that somehow

16:39 TimMc: You can e.g. compute the value of any of A B or C if the other 2 are known.

16:39 khaliG: correct

16:39 rata_: khaliG: I supposed there are not two unknows for each formula

16:40 khaliG: rata_, fair enough, im getting these values from user input so they might not have provided them

16:40 rata_: mmmm... that doesn't make sense

16:40 tomoj: so it's an equation solver?

16:40 khaliG: tomoj, yep

16:41 rata_: how do you compute two unknows from one known?

16:41 I used the info in the comments

16:41 khaliG: you dont, you just dont do anything

16:41 rata_: ah ok

16:42 TimMc: khaliG: Wrap the cond in a check to see if exactly one is nil, otherwise return all the values unchanged.

16:42 rata_: then (if (= (count (filter nil? [lbm bw bf])) 1) (I lbm bw bf) (do-nothing))

16:42 khaliG: that makes sense

16:42 rata_: probably (do-nothing) is [lbm bw bf]

16:43 khaliG: but please, for something that doesn't require mutability, don't use mutability

16:44 khaliG: rata_, i totally agree, i just couldnt see a way to do it without mutation

16:44 but now i can, that's much better

16:45 rata_: ;)

16:45 tomoj: will the equations ever change?

16:45 is it safe to assume that each variable only appears once in an equation?

16:46 khaliG: they wont change, and yes safe to assume so

16:46 rata_: even when there's probably a better way to write that, as I hardcoded the formula for each quantity... I imagine there's a way to do some symbolic computation from the original formula to get the other two formulae

16:46 khaliG: rata_, i would like that very much, would be nicer. i think you can do it in Qi using pattern matching, for example

16:47 (but i haven't tried, and dont know the language just know it has that facility)

16:50 rata_: khaliG: I don't see how pattern matching would do it

16:50 khaliG: not just pattern matching, i think it does unification too

16:50 but i'm not 100% sure on it

16:52 pdk: needs more prolog semantics

17:04 joshua__: Is Clojure going to be participating in the Google Summer of Code?

17:17 Dranik: hi all

17:18 how to test whether the item is a kind of list/sequence or just a single value?

17:18 gregh: ,(list? '(1))

17:19 clojurebot: true

17:19 Dranik: ,(list? 1)

17:19 clojurebot: false

17:19 Dranik: gregh, thanks!

17:20 rata_: Dranik: seq? is for sequences

17:29 dsantiago: What does an InvocationTargetException mean? I'm getting one from like 30 lines deeper than my code and I'm not sure what I should be looking for.

17:38 gregh: see http://download.oracle.com/javase/1.5.0/docs/api/java/lang/reflect/InvocationTargetException.html - it's an exception that wraps another exception, so look for an exception thrown by whatever you're trying to call

17:46 Cozey: Hello. I try to use multimethods to write some db-specific code. To do this I have specific.clj with defmultis, and postgresql.clj, etc with defmethods. from postgresql.clj et al. i :use 'specific' namespace. Then I'd like to be able to 'use' or 'require' these methods from other namespaces. how should i ccomplish this?

17:47 if I (require 'specific), will the defmthods in 'postgresql namespace be loaded and available?

17:47 if I try to require all of the depenencies, i get some AssertionError in reload.clj

18:32 dsantiago: Thanks gregh

19:10 Cozey: Good morning

19:11 Can one spread multimethods between different namespaces, like here: https://gist.github.com/835525 ?

19:12 guille_: hi

19:13 which slime version is appropiate to use swank? I can't get it to work with HEAD, do I need a patched one?

19:14 scottj: guille_: 605f930

19:15 guille_: scottj: is that rev from the repo at common-lisp.net or boinkor.net?

19:16 scottj: guille_: url = http://github.com/technomancy/slime.git

19:17 guille_: ok, thanks

19:17 kencausey: guille_: recommended: http://groups.google.com/group/clojure/browse_thread/thread/c178bed30fd9d704/7d2aa20a38ad18a1?lnk=gst&q=new+installation#7d2aa20a38ad18a1

19:17 dnolen: Cozey: yes, but you need to get rid of your circular dependency.

19:18 Cozey: dnolen: Ok, say I remove (:require a) from m.clj

19:18 but then a.clj's defmethods will not be loaded into scope and hence will not work

19:18 guille_: those of you using CL too, how do you deal with the different versions of slime when you're using both environments?

19:19 scottj: guille_: I use the same version of slime with cl and clj

19:20 dnolen: Cozey: it will not work in m.clj no. But why is that an issue?

19:21 Cozey: well I'd have to write (use 'm 'a)

19:21 and if I add another implementation file b.clj (with defmethods for :b) I'll have to change it to

19:21 (use 'm 'a 'b) in all files which use them

19:22 dnolen: Cozey: such is life. sorting out circular dependencies is much much worse that such little inconveniences.

19:22 Cozey: ;-))

19:22 this is a kind of a zen answer ya know

19:23 guille_: nice. g'night

19:23 dnolen: Cozey: my experience with circular deps in C and Python has been horrible enough to be happy with Clojure's behavior.

19:24 Cozey: I know what You mean, but I'm not sure if I get the usefulness of multimethods, if you must keep them in one namespace

19:24 dnolen: Cozey: you do not need to keep them in one name space.

19:24 Cozey: (or more, but still you have to enumerate them when requiring, so it's the same)

19:25 but perhaps the kind of dynamism I'm thinking of would destroy the functional nature of clojure..

19:27 scottj: what if you use defmethod m/foo ?

19:28 dnolen: Cozey: adding a few here and there seems fairly common - print-method for example.

19:30 Cozey: but still I need to require the adding namespaces before using my print extension

19:30 what if I did a defmethod in an in-ns of namespace which holds the demultis?

19:35 dnolen: Cozey: of course you need to add the namespace. multimethods are functions. What you're talking about is action at a distance. require the namespace and get on with it I say :)

19:36 Cozey: Ok, You persuaded me! Now I need to figure out how to run cake with (use :verbose)

19:36 so I can figure out where this pesky cycle is (i guess i created another one while trying to solve this)

19:56 simard: could someone explain me how this works, ie. it seems like seq is defined recursively with itself, is that correct ? (def seq (fn seq [coll] (. clojure.lang.RT (seq coll))))

20:18 dnolen: simard: defn isn't defined at that point, that's why it's defined that way.

20:19 rata_: dnolen: I think simard talks about the immediately recursive (seq coll)

20:21 dnolen: rata_: that's a method call.

20:21 rata_: then shouldn't it be (.seq coll)?

20:21 dnolen: rata_: it's calling the seq method on clojure.lang.RT

20:25 rata_: aha! I didn't know that way of calling a method http://clojure.org/java_interop#dot

21:58 joshua__: Anyone know whether or not Clojure is going to be a participating organization or used in Google Summer of Code? I'm thinking of applying.

21:59 dnolen: joshua__: LispNYC is trying to be a GSoC org again, and they clearly seem interested in hearing Clojure projects.

22:02 joshua__: dnolen: Thanks, looking into that now.

22:09 * joshua__ tries to think of a good Clojure project for GSoC ;p any ideas?

22:12 brehaut: joshua__: find some area of rails, django etc that doesnt have a suitable equivlant in ring and build that?

22:12 joshua__: brehaut, good idea, I'll look into that.

22:13 brehaut: joshua__: start with the ring wiki, it'll give you a good idea of whats covered

22:14 joshua__: This one? https://github.com/mmcgrana/ring/wiki

22:14 brehaut: thats the one

22:14 https://github.com/mmcgrana/ring/wiki/Libraries has a bunch of 3rd party features

22:15 you could also ask on the ring-clojure mailing list

22:15 dnolen: joshua__: last time LispNYC + GSoC came up, rhickey was hoping that someone would tackle either Datalog or Predicate Dispatch.

22:16 joshua__: Can you give me some links to read about either of those?

22:16 Or both.

22:17 dnolen: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=

22:18 http://people.cis.ksu.edu/~xou/formalmethodsnetworking/datalog.pdf

22:18 there's a Datalog in contrib, but I think it could a optimization pass or a different approach entirely.

22:19 Predicate Dispatch could fall out of fast Datalog.

22:19 joshua__: might be useful to ask on the dev list for ideas as well if you're on that.

22:20 joshua__: dnolen, I'm not, but I suppose I should join it

22:20 brehaut: joshua__: have you signed a contributer agreement?

22:20 joshua__: No.

22:20 brehaut: you'll want to do that as well then

22:20 joshua__: I'm willing to though.

22:21 Yea.

22:21 brehaut: i dont think you can joing the dev ML unless you have

22:21 which reminds me i need to try to resubscribe now that my CA has been receieved

22:23 qed: Anyone have any thoughts on refactoring a function-map with a nested condp so that both can be updated via a ref or an atom? https://gist.github.com/835627

22:31 joshua__: dnolen: Looking at the datalog paper feels a little like looking at a brick wall. They are talking about mathematical systems I haven't actually heard of. Do you think I'd stand a chance of implementing it properly if I was persistent?

22:31 brehaut: joshua__: my experience with summer internships is that you can do a surprising amount that you would never have believed before you did it

22:33 joshua__: brehaut, Have you done a GSoC?

22:34 brehaut: joshua__: not a google one; i did an NZ government funded one for a small buisness

22:35 joshua__: brehaut, nice

22:38 simard: joshua__: with proper supervision from a more experienced person, I agree with what brehaut said, it can be surprisingly productive

22:38 if left on your own though it might feel as your are stuck sometimes, which you are :)

22:38 joshua__: Alright. I'm definitely willing to give it a shot.

22:38 brehaut: that being said, if you are very weak at logical stuff, then perhaps be careful of biting of datalog ;)

22:39 joshua__: I've never done anything in prolog or anything like that.

22:39 simard: joshua__: this is what an intership is about hehe

22:39 and don't you fall into that trap of always thinking "I never did that before"

22:39 brehaut: joshua__: ive never done anything in the domain of any of my day jobs before i started at those jobs either

22:40 simard: brehaut: right on :)

22:40 joshua__: interships are also about building confidence

22:41 joshua__: Alright. I'm trying to find where Rich mentions his being interested in Datalog right now.

22:42 I'll be reading through that paper in my free time at school trying to get a handle on this...

22:49 Apparently one way I could go about this is by making a wrapper fir IRIS Reasoner.

22:53 DespiteItAll: Isn't there a way in leiningen dependencies to say you just want the newest version, whatever it is?

22:55 qed: I did GSoC for Plan9 (Inferno OS) in 2007

22:56 joshua__: dnolen, Are you sure that Rich isn't satisfied with the Datalog in contrib?

22:56 qed: It was a little weird; my advisor (forgetting the terminology they use) was largely absent, didn't provide much in the way of guidance, etc.

22:57 joshua__: ive heard talk about leveraging datalog in clojure from several people who seemed to be familiar with something rich had been asking about or pondering w/r/t datalog

22:57 i dont know if it's that he's not satisfied, per se

22:58 id ask chouser about it if i were you

23:00 joshua__: qed: kk will do

23:14 simard: how do I make a function that can be 'Indexed' ?

23:14 I'd like a way to do (nth my-func 5).. not sure if that's a good idea in itself though :)

23:14 where my-func is a function of n, as in a mathematical expression returning a number from its position

23:15 (say, the triangle numbers sequence)

23:15 spewn: simard: Why can't you do (my-func 5)?

23:16 brehaut: simard: perhaps explain why you want this indirect function calling operation?

23:17 DespiteItAll: map the function to (range), then call nth, damn the performance

23:17 simard: I don't have a "good reason", really just that I'd like a mathematical sequence to feel as a sequence..

23:18 or some kind of blurry vague reason :)

23:18 brehaut: simard: if you want to make it feel like a sequence, perhaps return a sequence?

23:18 simard: I'm unclear how to do that, because the sequence does not depend only on the last number in the sequence, but also on the position

23:19 ie it's not definable recursively, I think

23:19 or is it

23:20 oh well it appears it is: (def triangle-nums (map #(/ (* % (+ % 1)) 2) (iterate inc 1)))

23:29 pdk: when writing a multimethod do i have to actually add a case to catch and return :default in the dispatch fn

23:29 or is it implicit that any return value of the dispatch fn will be caught by a :default method if it isn't by any other of the defined methods

23:29 brehaut: its implicit

23:30 pdk: okay

23:33 spewn: Why does (def foo "bar" :baz) fail with "Too many arguments to def" on 1.2.0?

23:35 brehaut: spewn: because in spite of what the docs say, def in 1.2 doesnt accept a doc string without meta

23:37 spewn: What about the code I saw in Compiler.java? Added after 1.2 was released?

23:37 brehaut: i dont, but i guess so

23:38 scottj: what does :baz part of that def mean?

23:39 brehaut: scottj: its just a value to bind foo too

23:40 scottj: oh I didn't realize "bar" was a docstring

23:41 spewn: brehaut: It looks like the code for docstrings in def was written on April 14, 2010, but not committed to master until October 12, 2010, with 1.2 being released in August 2010.

23:41 anthony__: There isn't any inherent issue with using Clojure with Java 7, is there?

23:41 I'm getting this error: Cannot cast java.nio.file.StandardWatchEventKind$StdWatchEventKind to [Ljava.nio.file.WatchEvent$Kind;

23:42 But StandardWatchEventKind has: private static class StdWatchEventKind<T> implements WatchEvent.Kind<T>

23:42 Am I missing something simple?

23:48 ekoontz: what emacs do people use with clojure

23:48 carbon emacs is version 22

23:49 apparently you need 24?

23:49 per http://www.assembla.com/wiki/show/clojure/Getting_Started_with_Emacs

23:49 trying https://github.com/technomancy/emacs-starter-kit

23:49 brehaut: ekoontz: i used technomancy's emacs starter kit

23:49 ekoontz: cool thx brehaut

23:50 brehaut: and i used exactly the versions of things it suggested (and removed my cromulent .emacs config to make doubly certain)

23:50 ekoontz: cromulent lol

23:50 brehaut: may it embiggen your vocabulary

23:50 ekoontz: hehe

23:51 anthony__: Ignore my last question...it's because the Java method is variadic. ugh

23:55 ekoontz: brehaut: what emacs do you use if i may ask?

23:55 brehaut: ekoontz: the one recommended by emacs-starter-kit

23:55 TeXnomancy: ekoontz: 23 is recommended; http://emacsformacosx.com

23:55 carbon is pretty old

23:56 ekoontz: thanks TeXnomancy :)

23:56 brehaut: yeah im using 23.2.1

23:56 ekoontz: i like the web site sticker : "no extras! no nonsense"

23:57 brehaut: that doesnt explain M-x butterfly

23:57 simard: what's the difference if any between (def triangles (concat [0] (map + triangles (iterate inc 1)))) and (def triangles (lazy-cat [0] (map + triangles (iterate inc 1))))

23:57 the lazy-cat doesn't seem necessary as (iterate) already makes it lazy, right ?

Logging service provided by n01se.net