#clojure log - May 09 2009

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

0:42 replaca: danlarkin: are you still hanging out?

3:01 cads: is it hard to write a custom m-expression syntax for a lisp?

3:03 eww gross, I've used a m-exp language before, mathematica

3:04 though the array slicing was nice

3:04 but eeew, I don't want to program in mathematica

3:05 p_l: cads: so far, any m-exp system died...

8:01 rhickey: http://www.javaworld.com/javaworld/jw-05-2009/jw-05-clojure.html

8:06 wlr: rhickey: congrats on the mainstream attention ^^

8:07 rhickey: wlr: thanks - hopefully Java One will help broaden awareness as well

8:09 wlr: rhickey: if folks put aside irrational bias against lispy things and listen to what you say, it will

8:29 nakyss: how do i register here??

8:30 eee: ,(doc cond)

8:30 clojurebot: "([& clauses]); Takes a set of test/expr pairs. It evaluates each test one at a time. If a test returns logical true, cond evaluates and returns the value of the corresponding expr and doesn't evaluate any of the other tests or exprs. (cond) returns nil."

8:31 eee: are there any other special keys besides :else?

8:31 kensanata: nakyss: /msg nickserv help

8:31 eee: it appears cond is behaving more like "finally" for me maybe?

8:35 nakyss: +r

8:37 Hello all

8:37 I'm try to solve this prblem

8:37 eee: hi

8:38 me too

8:38 :(

8:38 in my case cond seems to find a condition AND execute the else

8:38 nakyss: I can't get a hold of an interface

8:39 (def sourceDataLine (AudioSystem/getSourceDataLine audioFormat))

8:39 (. sourceDataLine open audioFormat)

8:39 eee: which is the object

8:39 nakyss: and i get : java.lang.IllegalArgumentException: No matching method found: open for class com.sun.media.sound.DirectAudioDevice$DirectSDL

8:39 eee: and which is the method

8:39 and which is the param

8:41 open the method you want?

8:42 nakyss: the sourceDataLine var is supposed to be an SourceDataLine interface, it has nithing to do with com.sun.media.sound.DirectAudioDevice$DirectSDL...

8:45 eee: did cond have a bug in some version that I have?

8:45 nakyss: what's your problem eee?

8:47 eee: when I do a (cond), one of the cases works

8:47 but it still seems to do the else

8:47 in addition

8:47 i use :else

8:47 nakyss: paste your code maybe

8:48 eee: i'll group pertinent stuff together

8:50 lisppaste8: eee pasted "cond question" at http://paste.lisp.org/display/79928

8:50 eee: it's printing "got here" "got here2"

8:51 also, it prints the empty vector even though I tried to cull it out

8:53 Lau_of_DK: Good afternoon gentlemen

8:53 eee: can you try (.open sourceDataLine audioFormat)?

8:53 hi Lau_of_DK

8:53 nakyss: yes it does thtet same error

8:54 your cond form seems to end before all the conditions

8:54 eee: well well

8:54 you found it

8:55 now I know where lisp got that acronym!

8:55 "infernal parens"

8:55 thanks

8:56 nakyss: yr welcom

8:56 eee: that's a huge lesson to remember to check

8:57 nakyss: use an editor with paran matching

8:57 eee: funny thing is, I do

8:57 but i should have gone back line by line

8:57 once you mentioned that

8:57 i just ran the cursor up the right side

8:58 now I can move on the the next thing that has had me perplexed for a day

8:58 which is that when I use 100 for that special spot, everything works

8:58 but when I use 99 or below it doesn't

9:01 nakyss: Does anyone have any idea?

9:01 (def sourceDataLine (AudioSystem/getSourceDataLine audioFormat))

9:01 (println "sourceDataLine :" sourceDataLine)

9:01 prints java.lang.IllegalArgumentException: No matching method found: open for class com.sun.media.sound.DirectAudioDevice$DirectSDL

9:02 eee: you are saying that sun.media thing isn't what you are working with?

9:02 nakyss: even though getSourceDataLine return a SourceDataLine interface

9:02 yeap

9:02 eee: so fully qualify

9:03 nakyss: it does the same :(

9:04 eee: seems like in some java file the ide imported the wrong thing

9:04 go look in the java code for a bogus import

9:04 nakyss: i have a java version of the codde which work greats so...

9:05 eee: then your clojure class path has things in a different order than your java version?

9:08 nakyss: well it's possiblebut package name should be unique so that shouldn't interfere

9:08 eee: i agree

9:09 there might be a way to unimport something in clojure

9:09 i'm pretty sure

9:09 seems like a hack

9:09 but if it works

9:09 it will tell you something

9:10 unimport that bogus stuff

9:11 nakyss: whether it's a bug in clojure or i'm doing somthing wrong, the former is very unlikely

9:12 should i use proxy to deal with interface?

9:13 eee: i wish I knew more to help

9:13 i'm not too competent in clj

9:13 nakyss: thx anyway me neither as you can see

9:14 eee: i'd try unimporting that bugus package

9:14 nakyss: not very active irc channel here?

9:14 eee: sometimes you get 2 or three talkers

9:16 nakyss: i'll go post on clojure google group then

9:16 eee: that will work

9:19 lisppaste8: eee pasted "works with 100 fails with 99, why" at http://paste.lisp.org/display/79930

9:19 eee: i don't know why it matters what blank string I use

9:20 for the stupid scorer, the values should be arbitrary

9:21 it works with a letter, too

9:21 just not a string that represents a number less than 100

9:21 sooooo confusing

9:21 acieroid: hmm

9:22 how can i eval code from a string ? something like (foo "(* 6 7)") -> 42

9:23 eee: i've seen that in the discussion posts

9:24 acieroid: where are those discussions posts ?

9:26 eee: http://groups.google.com/group/clojure

9:26 acieroid: 'k

9:26 thanks

9:27 ok great

9:27 (eval (read-string "(* 6 7)"))

9:28 so simple :D

9:28 eee: how'd you find it so fast?

9:28 acieroid: by searching in the group

9:28 "eval string"

9:28 eee: cool

9:28 acieroid: a bit of luck \o/

9:29 eee: i have no approach for solving this prob

9:29 perhaps I'll post the whole thing to the group soon

9:43 Cark: the article is not 100% acurate, but all in all it gives a good overview

10:55 acieroid: hmm

10:56 how can I do smth like (re-seq #(str "foo" "\w+") foo)

10:56 I mean, building regex at eval time, from concatened string or others functions

10:57 hum, with re-pattern i think

11:26 replaca: acieroid: use re-pattern

11:26 oops, not yet enough coffee for reading comprehension!

11:28 danlarkin: replaca: you rang last night?

11:34 unlink: Does any .NET language have a decent REPL on Linux?

11:55 acieroid: replaca: :D

11:55 thanks anyway

11:56 :w

11:56 oops

12:04 dreish: unlink: I think there are various projects to put Clojure on .NET, and there's rhickey's old project DotLisp. (That's the extent of my knowledge on the subject, though.)

12:06 unlink: I've tried fsi, ironpython, and booish, and they're all nearly unusable

12:20 dreish: What's wrong with them?

12:21 Without knowing much about it, I would have guessed ironpython would be handy, for example.

12:52 acieroid: does anyone have an exemple of using threads with clojure ?

12:53 dreish: ,(.run (Thread. #(println "hello threads")))

12:53 clojurebot: hello threads

12:53 acieroid: oh, so simple

12:54 dreish: Make that .start to actually run in a different thread.

12:54 (I'm assuming that wouldn't work so well with clojurebot.)

12:54 ,(.start (Thread. #(println "hello threads")))

12:54 clojurebot: nil

12:54 slashus2: dreish: You don't call .start?

12:54 dreish: Yeah, output goes off to nowhere.

12:54 slashus2: yeah

12:54 dreish: slashus2: You do. Just doesn't work with cjbot.

12:55 hiredman probably has "hello threads" somewhere at his repl now.

12:55 nakyss: can we import java class with the cjbot

12:56 durka42: ,(import '[java.io File])

12:56 clojurebot: nil

12:56 dreish: acieroid: agents are maybe the more idiomatic way to do things in a different thread.

12:56 acieroid: agents ?

12:56 I'll look at that

12:57 dreish: http://clojure.org/agents

12:57 nakyss: ,(import '(javax.sound.sampled AudioFormat AudioInputStream AudioSystem LineUnavailableException SourceDataLine))

12:57 clojurebot: nil

12:57 durka42: ,(binding [*out* *out*] (.start (Thread. #(println "hello threads"))))

12:57 clojurebot: nil

12:58 acieroid: but you know dreish, I just want that a call to a function don't block the repl

12:58 nakyss: (def sourceDataLine (AudioSystem/getSourceDataLine audioFormat))

12:58 oops

12:59 ,(def sourceDataLine (AudioSystem/getSourceDataLine audioFormat))

12:59 clojurebot: DENIED

12:59 durka42: acieroid: then you want an agent

12:59 acieroid: ok

12:59 durka42: nakyss: no def

12:59 nakyss: no def :(

13:03 sorry for the noise just testing some stuff

13:03 ,(.open (AudioSystem/getSourceDataLine (new AudioFormat 44100 16 1 true true)) (new AudioFormat 44100 16 1 true true))

13:03 clojurebot: java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, big-endian is supported.

13:03 nakyss: does anyone know why this happened

13:06 no just ignore that

13:44 slashus2: How do you access a static class inside of an interface like DataLine.Info in javax.sound.sampled?

13:47 liebke: slashus2: javax.sound.sampled.DataLine$Info

13:48 slashus2: Oh, I thought I tried that.

13:48 That seems to work.

13:48 I think

13:48 alright, than kyou

14:28 cultureulterior: I'm new to clojure and lisp-like languages- what's the equivalent to python's star operator?

14:29 slashus2: multiply or in argument lists?

14:29 cultureulterior: argument lists

14:30 slashus2: (defn testfn [firstargument secondargument & containstherest])

14:33 cultureulterior: I must be asking wrong. I mean for when calling functions...

14:34 slashus2: cultureulterior: Can you show a python example of what you are trying to find the equivalence of?

14:35 cultureulterior: thefunction(*theargs)

14:36 where theargs is a tuple or vector

14:38 slashus2: (apply function argumentlist)

14:40 cultureulterior: Thank you

14:46 stuhood: clojurebot: reduce?

14:46 clojurebot: I don't understand.

14:47 stuhood: clojurebot: reduce

14:47 clojurebot: No entiendo

14:47 stuhood: shoot... what is his quip about reduce not being lazy?

14:48 ~braindump

14:48 clojurebot: Titim gan �ir� ort.

14:50 durka42: ~brain dump

14:50 clojurebot: brain dump is http://clj.thelastcitadel.com/clojurebot

15:28 nakyss: hi all

15:28 how to get the string name of a symbol

15:29 (def test nil)

15:29 I want to print test

15:30 slashus2: ,(str 'test)

15:30 clojurebot: "test"

15:30 Cark: (name 'test)

15:30 ,(name 'test)

15:30 clojurebot: "test"

15:31 nakyss: thx

15:34 it turns out it's not quite what I wanted

15:34 I want to define such a fuction

15:34 (defn debug [x]

15:34 (println 'x ":" x))

15:34 that would print the name of the var

15:34 Cark: mhh

15:34 nakyss: like (debug test) -> "test : nil"

15:35 slashus2: (var test)

15:36 nakyss: ,(defn debug [x] (println (var x) ":" x))

15:36 clojurebot: DENIED

15:37 nakyss: it fails: Unable to resolve var: x in this context

15:37 slashus2: nakyss: You probably need to create a macro.

15:37 nakyss: any suggestions? plz

15:38 slashus2: nakyss: search for clojure debug macro into google and go to the first result.

15:38 eee: hiyas

15:40 Cark: (defmacro d [name] `(println '~name "=" ~name))

15:40 that should do it

15:40 usage : (d *my-var*)

15:41 hello eee

15:41 then you can do fun stuff like : (d (+ 1 3))

15:42 and refactor the macro to return the result

15:42 eee: i;m still stuck i've been really stuck for days

15:42 nakyss: ok great thx

15:43 eee: nakyss you got that problem fixed now?

15:43 what was it?

15:43 AWizzArd: Cark: maybe you can embed the println in the macro inside a do

15:43 rhickey: eee: stuck on what?

15:43 nakyss: eee do you earlier today or just now

15:44 > eee do you mean earlier today or just now

15:44 AWizzArd: Cark: or in a let, if you don't want to compute the result twice. Example: (defmacro d [name] `(let [result# ~name] (println '~name "=" result#) result#))

15:44 eee: now I gotta figure out how to put it back the way it was

15:44 i have a 15-puzzle

15:44 where it shouldn;t matter what strings I use

15:44 i define one to be the blank

15:44 that moves around

15:45 Cark: AWizzArd : sure

15:45 eee: when I make it a letter

15:45 it works fine

15:45 when I make it a number string less than 100

15:45 it doesn't work

15:45 but my heuristic doesn't care about numbers

15:45 just equality

15:45 Cark: AWizzArd : though you might want to define a prog1 macro first for easier reading

15:45 or a returning function =)

15:45 eee: cause I didn't switch to the manhatten heuristic yet that does care about numbers

15:46 i've pasted the code before

15:46 but let me get it back to that state if I can

15:46 made a generic a-star search with the heap

15:46 trying to show some examples in clojure

15:48 nakyss: keep it concise eee. here isn't really a place to post go to google group :)

15:49 eee: this might have ben one prob:

15:49 ,(= [] nil)

15:49 clojurebot: false

15:50 eee: which I seemed to remember from lisp

15:55 lisppaste8: eee pasted "works with 100 fails with 99, why" at http://paste.lisp.org/display/79939

15:55 eee: probably pretty wacky code ... i'd built it up from smaller things

15:59 it runs forever if you use "99" for the blank

16:00 or "98"

16:00 must be something low-level I don't get

16:01 rhickey: eee: right, (= [] nil) is bad, what are the possible values of goal-s ?

16:01 are you using [] as a 'done' sentinel?

16:02 eee: no, trying to throw those out

16:02 because they are bad transitions

16:02 rhickey: if so, then (if (seq goal-s) ...

16:02 eee: if the blank is in the cornet or on the side

16:02 corner

16:03 ok

16:03 so i thought with "next" that worked the way it is

16:03 with rest I need seq

16:03 as tested before

16:03 will make the change tho

16:03 no change

16:04 runs forwever with "99" solves with "100" or "B" for the blank

16:04 but what I use for my string should be arbitrary in my mind ... for score-state-stupid

16:06 lisppaste8: eee annotated #79939 "made emptyVec? predicate" at http://paste.lisp.org/display/79939#1

16:07 rhickey: eee: are you comparing strings somewhere?

16:07 eee: in case I didn't answer the question, '(["1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15" "99"])

16:07 that is the goal

16:07 yes

16:08 comparing strings in 'score-state-stupid

16:08 well comparing list of strings

16:08 element by element

16:09 rhickey: eee: you are saying it behaves differently if you replace the 2 "99"s in the call with "100"s?

16:09 eee: yes

16:10 it completes right away

16:10 well no

16:10 one other place too

16:10 rhickey: 3 places to change

16:10 eee: yes

16:14 rhickey, I really appreciate you looking ... I feel bad now that I have to take off in a minute or two

16:15 rhickey: if the strings are treated completely like symbols, this is hard to believe - you never do math with them ?

16:15 eee: not that I know of

16:15 I can check it all in like this

16:16 and it's in my heap project

16:16 i was about to do math in the new heuristic

16:16 which is why I found the problem

16:17 http://code.google.com/p/jc-pheap/source/checkout ... if this is interesting

16:17 i hope it's not something too dumb

16:18 gotta go, will leave my notebook open in case there's more on the subject. Thanks again

16:20 cultureulterior: What version of java should I be running for an an optimal clojure experience? I'm referring here to GC and such

16:20 AWizzArd: ,(* 0.4 150 1.5)

16:20 clojurebot: 90.0

16:21 AWizzArd: ,(* 1.5 0.4 150)

16:21 clojurebot: 90.00000000000001

16:21 AWizzArd: rhickey: do you see that?

16:21 gnuvince_: AWizzArd: in Python:

16:21 >>> 0.4 * 150 * 1.5

16:21 90.0

16:21 >>> 1.5 * 0.4 * 150

16:21 90.000000000000014

16:22 rhickey: AWizzArd: I see floating point doing what it always does

16:23 ,(* 4/10 150 15/10)

16:23 clojurebot: 90

16:23 rhickey: ,(* 15/10 4/10 150)

16:23 clojurebot: 90

16:26 AWizzArd: I tried clisp. For both forms it returned 90.0

16:27 gnuvince_: AWizzArd: try C, C++, Java, Python, Ruby, Haskell, etc. they'll all give the same answer as Clojure I bet.

16:28 AWizzArd: I just tried Ruby. Got 2x the 90.0

16:28 svdm: ,(apply * (map bigdec [1.5 0.4 150]))

16:28 clojurebot: 90.00M

16:28 AWizzArd: In C, C++, Java I won't be surprised

16:29 there I expect that floats do what every computer scientist knows

16:29 gnuvince_: AWizzArd: Haskell, Python and OCaml gave me the same answer as Clojure.

16:29 Don't have Ruby installed.

16:29 hiredman: well, clojure floats are java floats, so ...?

16:30 gnuvince_: I don't see the problem either since Clojure can just use BigDecimals or Rationals.

16:30 AWizzArd: Should it not default to correct results? We should ask for speed if correctness is not preferred.

16:30 hiredman: it is correct

16:31 it follows the spec for floating point math

16:31 if you don't want floating point math, don't use floats

16:31 AWizzArd: it is clear that it must give these outputs of the FPU is used, but the results are mathmatically not correct

16:31 of the FPU ==> if the FPU

16:32 hiredman: they are correct for floating point math

16:32 which is what happens when you use floats

16:33 AWizzArd: Why are floats used as default and not only when one explicitly askes for them?

16:33 hiredman: ,(class 1)

16:33 clojurebot: java.lang.Integer

16:33 AWizzArd: that would match the behaviour for integers

16:33 hiredman: ,(class 0.1)

16:33 clojurebot: java.lang.Double

16:33 AWizzArd: (+ 999999999999999999999999999999999999999999 99999999999999999999999999999999999999999999999999999999)

16:33 ,(+ 999999999999999999999999999999999999999999 99999999999999999999999999999999999999999999999999999999)

16:33 clojurebot: 100000000000000999999999999999999999999999999999999999998

16:33 AWizzArd: no overflow

16:33 why correct behaviour here but not for floats?

16:34 slashus2: I guess that is the behavior that most people expect.

16:34 hiredman: because the bahviour is correct for floats, by definition

16:34 rhickey: floating point is an inexact representation, as you perform successive operations you accumulate error - there are some numbers it simply can't represent

16:35 AWizzArd: right, it can represent nearly none of the real numbers

16:36 I did not expect 90.000000000000014 when I tried 1.5 * 0.4 * 150 in Ruby or clisp

16:36 uhm, that last one was for slashus2 :)

16:37 gnuvince_: AWizzArd: and should Clojure do the right thing when (+ 1 "2") obviously meant (+ 1 2)?

16:38 AWizzArd: I can see a difference between (+ 1 "2") and (* 1.5 0.4 150)

16:38 Why are those numbers floats or doubles and not BigDecimals?

16:38 hiredman: well, obviously, I meant I wanted to concat the toString of 1 to "2"

16:39 gnuvince_: AWizzArd: just write a patch

16:39 But I don't think you'll get much traction.

16:39 AWizzArd: Can that be written in Clojure or does it require Java knowledge?

16:39 hiredman: I don't think java does the auto-promotion stuff with bd

16:40 so you would have to cast every single time you pass a number to a java method

16:40 AWizzArd: ,(+ 1.5M 0.4M 150)

16:40 clojurebot: 151.9M

16:40 AWizzArd: ,(* 1.5M 0.4M 150)

16:40 clojurebot: 90.00M

16:40 hiredman: ,(.charAt "foo" 1M)

16:40 clojurebot: \o

16:40 AWizzArd: Maybe the M should be implicit, while floats or doubles require a F or a D

16:40 hiredman: huh

16:40 go figure

16:41 gnuvince_: And break backwards compatibility?

16:41 Rich and Stu are gonna love you :)

16:41 AWizzArd: Would it break backwards compatibility if the M will still be supported?

16:41 gnuvince_: I think defaulting to Double is a fine choice

16:42 eee: your questions helped me figure it hour rhickey

16:42 gnuvince_: It's what the Java people expect.

16:43 AWizzArd: gnuvince_: and would getting overflows for multiplying big numbers also be a good choice then?

16:43 eee: drove back to tell you not to waste the cycles:

16:43 :)

16:43 AWizzArd: I think a good choice would be: correctness first, speed when people ask for it

16:44 I think the typical Java programmer is intelligent enough to live with mathematically correct results. It won't reduce their productivity very much I guess.

16:44 chrizel: for most applications floating point math is enough

16:44 AWizzArd: I am not against the use of the FPU

16:45 one could just simply ask for floats

16:45 for most applications correct math would also be enough

16:45 chrizel: no because its slower

16:45 eee: rhickey: the answer is that the heap breaks ties using the hash code of the object. so 99 has a different hash than 100 ... thus in the course of A-star . . . the order of pop can be different if different states have the same score

16:46 AWizzArd: chrizel: Does that mean you don't like Clojures behaviour in not letting integer operations overflow?

16:46 What Clojure is now doing is slower. It could simply use ints and longs under the hood und overflow for more speed.

16:46 eee: ok see yah again

16:47 AWizzArd: And if someone cares for speed: why not specify it? (float 1.5) or 1.5F

16:47 In nearly all aspects Clojure has the motto: let us do the correct thing by default.

16:47 slashus2: AWizzArd: It would be a unique direction to go. Would be pretty neat, but would be at odds with the behavior of most programming languages.

16:48 Clojure is pretty unique anyway.

16:48 AWizzArd: I just wanted to say that ;)

16:48 people who don't come from the Lisp world will see 80% of new stuff

16:48 imo it's a minor issue to live with mathematically correct results

16:49 gnuvince_: Not if every time you want to send x to a Java method, you need to cast it back to a double

16:50 The thing with the Integer/BigInteger promotion is that it happens only when needed. Otherwise, it stays an Integer.

16:50 So you can say (.foo bar (* x y)) without having to cast that down to Integer

16:51 AWizzArd: What if (* x y) results in a number of 600 digits?

16:52 gnuvince_: AWizzArd: then you couldn't pass it to that method anyway

16:52 As it would expect an Integer parameter.

16:52 AWizzArd: Can't Clojure do this casting back to float/double under the hood

16:52 ?

16:53 chrizel: How would you determine whether a float is "too big" or would be incorrect? (are there any languages doing this?)

16:53 AWizzArd: You mean a language implementation?

16:54 gnuvince_: AWizzArd: it could, but if you have a BigDecimal holding an unrepresentable Double value, the result would be changed during the conversion, so the result would be off.

16:54 Let's say there's a trivial method called addOne. (.addOne myBigDecimal)

16:54 AWizzArd: yes

16:55 gnuvince_: You'd expect an answer that's exactly one larger than myBigDecimal.

16:55 However, because of the inherent imprecision of doubles, that could not be case.

16:55 AWizzArd: does addOne expect a float, a double or a BigDecimal object?

16:55 If it expects a float or double I would not expect a correct result

16:56 gnuvince_: I assume here it's expecting a Double, sicne we're talking about implicit conversion from BigDecimal to Double

16:56 since*

16:56 AWizzArd: then I would not expect that the number is exactly one more than my input

16:57 It could mean that the program must stop or do something else.

16:57 gnuvince_: Why not

16:57 "Clojure has correct floating point mathematics"

16:57 AWizzArd: The potential problem is only data that comes into the program during execution

16:58 for all data that is a consequence of my program I can find out if there are problems by just running my code

16:58 If new data enters a program each good programmer will let it only go deeper if it meets the requirements

16:59 If you read a big double and add one it could overflow and become a very big negative number

16:59 or not?

16:59 maybe it can become infinite instead, not sure

17:00 so, I must check if my input to which I later plan to add one will meet the requirements at the time the data flows into my program

17:00 If it can pass my tests then the conversion from BigDecimal to double would not cause problems and I get my number+1

17:01 slashus2: ,(Math/pow 50000 50000)

17:01 clojurebot: Infinity

17:01 AWizzArd: exactly

17:01 acieroid: hmm, i'd like to do something like (take 100 foo), with a string foo, but it returns me a list of char. How can I have a string ?

17:02 AWizzArd: Each good programmer will check input data. If the input is so big that adding one will cause that Infinity problem, the program must not accept the data.

17:02 gnuvince_: AWizzArd: how long do you think it would take to compute the real answer?

17:02 chrizel: acieroid, (apply str (take 100 foo))

17:03 AWizzArd: does it have to do with why (* 1.5 0.4 150) should result in 90.000000000000014?

17:03 acieroid: thanks :o

17:03 slashus2: Has anyone completed a pow and sqrt clojure implementation that does correct math?

17:03 gnuvince_: Whatever

17:04 This discussion is going nowhere, I'm walking out. If you truly care about it, put your code where you mouth is and submit a patch that we can actually play with instead of mentally jerk off over.

17:05 AWizzArd: slashus2: for only a very small set of real numbers there exists a result that can be algorithmically expressed

17:05 for calculating roots and so on

17:06 gnuvince_: do you see it is legitimate to report bugs and discuss about things that one percieves as bugs without providing a patch?

17:08 slashus2: The BigDecimal pow function only takes in integer, which isn't the best way to go. I don't think.

17:08 integers*

17:09 AWizzArd: agreed

17:09 slashus2: It is crippled compared to Python's Decimal package

17:10 AWizzArd: yes, seems that way

17:10 maybe this will become better when Sun .. hmm.. Oracle wants to push Fortress a bit more?

17:10 (if they want to do so at all)

17:12 gnuvince_: ,(let [v [1 2 3 4]] (time (dotimes [_ 1e6] (first v))))

17:12 clojurebot: "Elapsed time: 239.412 msecs"

17:12 slashus2: I think Python's decimal suffers from the same thing, in that you can't raise a Decimal to a non-integer power. It does support sqrt though.

17:12 gnuvince_: ,(let [v [1 2 3 4]] (time (dotimes [_ 1e6] (v 0))))

17:12 clojurebot: "Elapsed time: 102.065 msecs"

17:13 AWizzArd: There is this gnu calculator program, don't remember its name right now.. can that do 1.2345^6.757 ?

17:16 clisp can :)

17:16 gnuvince_: bc

17:16 AWizzArd: ah right, bc, thx

17:16 slashus2: What is special about 1.2345 to the 6.757?

17:17 AWizzArd: uh nothing, just typed some digits

17:17 slashus2: ,(Math/pow 1.2345 6.757)

17:17 clojurebot: 4.151502692911114

17:18 AWizzArd: ,(Math/pow 1.2345M 6.757)

17:18 clojurebot: 4.151502692911114

17:18 AWizzArd: so here it worked for a BigDecimal?

17:18 (.pow 1.2345M 6.757)

17:18 slashus2: I don't think so

17:19 AWizzArd: ,(.pow 1.2345M 6.757)

17:19 clojurebot: 3.539537889086624823140625M

17:19 slashus2: That didn't work like you think it did. It changed 6.757 to 6

17:19 AWizzArd: ,(.pow 1.2345M 6)

17:19 clojurebot: 3.539537889086624823140625M

17:19 AWizzArd: this is as you said right? The BigDecimal class has no pow method for doing what I wanted

17:19 slashus2: right

17:20 It doesn't even have a sqrt

17:20 :-(

17:20 AWizzArd: What surprised me is that after nearly 15 years of Java there still is no class for complex numbers

17:21 ,(* 1.5 0.4 150)

17:21 clojurebot: 90.00000000000001

17:21 AWizzArd: ,(* 1.5 0.4 150.0)

17:21 clojurebot: 90.00000000000001

17:22 AWizzArd: gnuvince_: can you try in Haskell: 1.5 * 0.4 * 150 vs 1.5 * 0.4 * 150.0 ?

17:22 gnuvince_: Same as in Clojure, already told you.

17:23 AWizzArd: now I changed something: the 150 became 150.0 (point zero added)

17:23 gnuvince_: ghci> 1.5 * 0.4 * 150

17:23 90.00000000000001

17:23 ghci> 1.5 * 0.4 * 150.0

17:23 90.00000000000001

17:23 AWizzArd: k

17:26 gnuvince_: It wouldn't change anything

17:26 because there are Double in the expression, the 150 is infered to be a Double as well.

17:27 AWizzArd: makes sense

17:32 btw, does .net have complex numbers and an equivalent to BigDecimal?

17:37 gnuvince_: ~seen Cark

17:37 clojurebot: Cark was last seen in #clojure, 111 minutes ago saying: or a returning function =)

17:42 gnuvince_: Cark: if you look at my clj-starcraft project, I've made a change that gave me ~12% speed improvement over before; I replaced some destructuring bindings with explicit vector indexing.

17:43 slashus2: I wouldn't that that destructuring would be that inefficient.

17:43 think*

17:45 AWizzArd: gnuvince_: can you please say a bit more about it?

17:45 gnuvince_: "it"?

17:46 AWizzArd: the speed improvement

17:47 gnuvince_: I had a program that took 80s to parse 1,050 files. In some deeply nested loops, I replaced things like (let [[a b c] v] ...) with (let [a (v 0) b (v 1) c (v 2)] ...) and now the execution time is down to ~70s

17:47 My goal is to get within 50% of Java's performance without sacrificing too much of the Clojure feel.

17:47 (Java takes 12 seconds for the same 1,050 files)

17:47 AWizzArd: surprising

17:50 gnuvince_: Not unexpected though; the vector -> seq conversion can really start to make a difference when it's done roughly 3.5M times.

17:51 The two largest bottlenecks in my code at the moment are calls to first and calls to aset-int

17:54 AWizzArd: what profiler do you use?

18:05 Btw, an interesting video about self-improving AI which also deals with nano technology. It's the official Stanford University youtube channel, and they also mention that in about 10-15 years we may have processors with a billion cores :)

18:05 http://www.youtube.com/watch?v=omsuTsOmvsc&fmt=18

18:55 chrizel: Should the function docstring be before or after the parameter list? I saw different styles, there seem to be no strict convention.

18:55 cmvkk: the docstring has to come before the parameter list.

18:57 hiredman: after the param list is a bug

18:58 cmvkk: technically it wouldn't cause an error, I guess

18:58 but it wouldn't be a docstring

18:58 hiredman: it would not, but it would not give you a docstring either

19:00 chrizel: most clojure code seems to do this -- after a grep through clojure-contrib there are at least in monads.clj some funktions with the other style...

19:01 hiredman: I cannot speak for contrib, core definetly has the docstrings before the params list

19:01 chrizel: ok i see, the other style is not a real docstring because it's not saved in the meta data

19:01 thank you, now it makes sense

19:06 ironically this docstring inconsistency is even in the ants.clj example by rich himself - that's what confused me too

19:08 cmvkk: haha, you're right.

19:09 to be honest, it's not very intuitive that the docstring is in that particular location. but that's how it has to be.

19:11 liebke: cmvkk: it makes more sense when you have a function with multiple arities

19:11 cmvkk: yep. that's why it's necessary.

19:13 cads: hey, I'd like to see if a set a is a subset of set b, should I just (defn subset? [a b] (= (clojure.set/union a b) b)) somewhere?

19:20 edgar: hello

19:20 i have see the web site of clojure

19:20 and i see is a language for jvm

19:21 is there plans to make it a language such as ruby or python? independent of the JVM

19:21 liebke: cads: that should work, you can also do (empty? (difference a b))

19:22 ataggart: edgar: one of the points of being on the JVM is to benefit from the many libraries available in java

19:22 though I think there is a project to try and get clojure running on dot net

19:25 edgar: well, on dot net may be great

19:28 ataggart: why?

19:30 what deficiency do you see by running on the JVM?

19:30 unlink: Running on the JVM is supposed to be a strength -- you can leverage a huge body of existing libraries.

19:31 ataggart: plus the JVM itself is badass

19:31 unlink: Though I'm not sure I'm a fan of creating a separate class for every function.

19:31 ataggart: I think (though may be completely off the mark) that that might be addressed with the addition of invokedynamic

19:33 unlink: What is that? A planned JVM feature?

19:33 dnolen: has anybody messed around with protecting java primitive arrays with the Clojure reference types? Is this a good approach?

19:33 ataggart: new opcode for the jvm in JSE 7

19:34 unlink: OK.

19:34 Interesting.

19:37 In my mind the only big thing really lacking from Clojure is static typing.

19:38 ataggart: funny, I thought the lack thereof was supposed to be a feature ;)

19:38 unlink: It seems to have been omitted by design, but once you've used ML, it seems like there's no excuse to leave it out.

19:39 Algebraic types and type inferencing make static typing useful, usable and powerful.

19:39 ataggart: example?

19:40 unlink: type tree = Null | Leaf of int | Node of tree * tree

19:41 Haskell has an even more powerful type system, but some find it overwhelming.

19:42 ataggart: I should say, what are you not able to do as easily, usefully, and powerfully without the static typing?

19:42 dnolen: in Haskell, is it possible to have a List of things that are not of the same type? Just curious... I've been meaning to investigate it.

19:43 unlink: You can't in SML, but I find that a feature. I have never wanted a heterogeneous list. Every time I have created one, it was in error. (except in Lisp, of course, I'm referring to using data as data, not as code).

19:44 got to run...

19:44 hiredman: that is an interesting point

19:44 ataggart: which brings its own philosophical issue

19:44 hiredman: the issue of homoiconicity

19:44 unlink: Is static typing irreconcilable with homoiconicity? discuss.

19:44 :)

19:45 ataggart: lol

19:46 I do like strong typing when it comes to what my IDE can do for me.

19:46 not having all those nifty features was one of the things that made me hesitant to start with dyanamic languages

19:47 I recall with my brief foray into ruby, asking a fellow developer how I can find where a function was defined and who was using it. His reply: search the code base.

19:48 I went back to java the next day

19:48 AWizzArd: in principle it could be possible that one can put an optional type system on top of dynamic languages

19:48 ataggart: and clojure sort of has that

19:48 with meta data

19:49 AWizzArd: meta data could be a place where to store those type information

19:49 ataggart: yup, and multimethods can trigger off of it

19:49 AWizzArd: it can go even deeper

19:50 http://groups.google.com/group/clojure/browse_frm/thread/7a48f48e4b197a15/47389c2a78e82b38

19:50 hiredman: well, metadata cannot be attached to everything

19:51 ataggart: java strings and primitives iirc, right?

19:51 hiredman: java objects in general

19:51 ataggart: mm ya

19:51 AWizzArd: those already carry type information I guess.. don't know if that information still exists in the bytecode

19:51 hiredman: ,^(with-meta (Object.) {:foo 1})

19:51 clojurebot: java.lang.ClassCastException: java.lang.Object cannot be cast to clojure.lang.IObj

19:51 hiredman: ,^(with-meta [] {:foo 1})

19:51 clojurebot: {:foo 1}

19:52 ataggart: a not altogether unreasonable cost for switching to using java stuff directly

19:52 hiredman: AWizzArd: if that was sufficient, why are type hints needed to prevent reflection?

19:52 ataggart: though I can imagine it hurts when common clojure value types (e.g., strings) have that limitation

19:52 AWizzArd: I think rhickey once mentioned that type information still exists in the byte code. So for optional static typing support this should not be a problem

19:53 hiredman: I don't know enough about the internal. I just think that reflection is needed when Clojure comes into play

19:54 (defn foo [a b] (a b)) <-- here it is not clear (from that code snippet alone) what a and b will be at run time

19:54 With gradual typing however this can be found out before compilation

19:54 hiredman: yet (defn a [x] (.toString x)) seems very clear

19:55 but unless you type hint x, you will get a reflection waring

19:55 AWizzArd: yes, for you and me it is clear

19:55 the clojure compiler however does not make use of that information

19:55 that is the dynamism about the language

19:56 only at runtime it will be clear what type the object x has

19:56 hiredman: AWizzArd: but you are calling a java method, if the java objects (which all clojure things are anyway) are carryng type information, what do we need reflection for?

19:56 AWizzArd: because Clojure is dynamically typed. Can you tell what class x will have?

19:57 there are thousands of .toString methods. Which should be called?

19:57 currently Clojure uses type information only for speedups. That is great. I think ataggarts point is that this information could also (and I step in and add "optionally") be used to make compile time checks

19:58 In a java program variables have a type. In Clojure those are untyped, but objects (at runtime) have a type.

19:58 ataggart: actually, I'm not sure I have a point. :)

19:58 I'm on my 4th beer

19:58 AWizzArd: A java program can always look up when you say x.toString() what type x must have

20:00 uh, it is late.. a java program can of course not look up anything, as that is just a string. I mean: javac can extract the information what type x has out of the java program file(s)

20:01 ataggart: yes, which carries over into the IDE issue, namely, with the strong/static typing everything that exists is known to exist ex ante

20:01 with dynamic languages you can't know ex ante what's what

20:01 AWizzArd: in principle you can.. it just is not very easy

20:01 ataggart: well, yeah, you just have to run the code

20:02 AWizzArd: you can, if you add a static type system on top of the dynamic language

20:02 ataggart: well yes

20:02 AWizzArd: that type system could even sit completely in your editor

20:02 ataggart: I think I'm okay with allow us to make ad hoc type systems

20:03 AWizzArd: so the compiler won't know anything about the types

20:03 the compiler could be the same. Only your Clojure editor knows about the types.

20:03 When you say (def x 10) it can tell you that it thinks that x should be of type "byte".

20:03 ataggart: it'd be nice to get an editor to do that

20:04 AWizzArd: when you later do a (count x) it looks up that count expects a collection, not a byte

20:05 all type hints could be put into metadata or comments, and the editor can use code folding to hide them by default

20:07 ataggart: if you have some time click the link I gave you 15 minutes ago. In that posting there is a video linked (I think in Meikels post)

20:07 ataggart: k

20:07 I'm reading the thread

20:09 watching...

20:09 AWizzArd: hiredman: btw, how do you turn on the reflection warnings? Via a binding before you compile?

20:22 slashus2: (set! *warn-on-reflection* true)

20:23 gnuvince: AWizzArd: both -Xprof and -Xrunhprof:cpu=samples report roughly the same numbers.

20:25 slashus2: If clojure ever uses involkdynamic in its implementation, will it improve performance? I guess this will be a while since involkdynamic would be incompatible with JVM 5 and 6.

20:34 AWizzArd: slashus2: ah good thank. I tried alter-var-root ^^

20:34 gnuvince: didn't know about those options, thanks

20:40 slashus2: No one has any idea about the implications of invokedynamic?

20:53 I guess that it could only use the invokedynamic technique when invokedynamic exists, and the current way when not.

20:54 cmvkk: yeah, a separate version of the compiler for a new java version

20:54 there are a few good articles out there about exactly what invokedynamic will do for languages like clojure

20:54 but i don't know what they are offhand

20:56 eee: i thjought this thing would keep the full history

20:56 dern it

20:56 now i don't know what rhickey said

20:57 hiredman: ~logs

20:57 clojurebot: logs is http://clojure-log.n01se.net/

20:57 eee: is the log saved some

20:57 er

20:57 thanks

20:57 :)

21:02 i iguess not much of today in the logs yet

21:02 clojurebot: everyday is Rich Hickey Appreciation Day

21:03 slashus2: I think he said that invokedynamic wouldn't do much for clojure.

21:04 hiredman: ~google dynamic languages and invokedynamic

21:04 clojurebot: First, out of 1840 results is:

21:04 Invoke dynamic languages dynamically, Part 1: Introducing the Java ...

21:04 http://www.ibm.com/developerworks/java/library/j-javascripting1/

21:04 hiredman: :(

21:07 * Raynes huggles gnuvince_

21:09 * Raynes thinks about trying irssi again now that he's on Linux.

21:11 eee: is the way to go from "3" to '3 to use javas Integer/parseInt

21:11 ?

21:12 or is there something in clojure?

21:14 hiredman: ,(symbol "3")

21:14 clojurebot: 3

21:14 hiredman: ,'3

21:14 clojurebot: 3

21:15 cmvkk: interesting.

21:15 hiredman: ,(= (symbol "3") '3)

21:15 clojurebot: false

21:15 Raynes: ,(read-string "3")

21:15 clojurebot: 3

21:15 hiredman: ,(class '3)

21:15 clojurebot: java.lang.Integer

21:15 Raynes: Mines better.

21:15 :)

21:15 eee: ok

21:16 cmvkk: your actually works.

21:16 ,(+ (symbol "3") 4)

21:16 clojurebot: java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.lang.Number

21:16 eee: (read-string ("println \"Hello\""))

21:16 ,(read-string ("println \"Hello\""))

21:16 clojurebot: java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn

21:16 Raynes: ,(read-string "2.3")

21:16 clojurebot: 2.3

21:16 hiredman: anyway, it depends what you mean by '3

21:17 eee: ,(read-string "(println \"Hello\""))

21:17 clojurebot: java.lang.RuntimeException: java.lang.Exception: EOF while reading

21:17 eee: ,(read-string "(println \"Hello\")")

21:17 hiredman: 'foo general means the symbol foo

21:17 clojurebot: (println "Hello")

21:17 eee: cool

21:17 Raynes: I remember read-string because I was pissed off after writing my own function to do that for decimals and finding it.

21:17 eee: read-string is god

21:17 hiredman: if '3 means the symbol 3

21:17 (symbol "3")

21:17 eee: ,(read-string "(println \"Look at it go\")")

21:17 clojurebot: (println "Look at it go")

21:17 cmvkk: hmm...it hadn't occurred to me before this that '3 could be both a symbol and a number.

21:17 eee: clever colution!

21:18 cmvkk: i don't think '3 should be a valid symbol.

21:18 i can't think of a situation in which that would be useful...

21:19 eee: well, it's just a matter of not making an exception

21:19 stuff can start with numbers

21:19 start with means "followed by n >= 0 stuff"

21:20 replaca: is stuart sierra around these parts anywhere?

21:20 cmvkk: i guess it would mostly never come up, since (symbol "3") is the only way to make that symbol.

21:20 since '3 just becomes the number 3.

21:22 * Raynes reads 'Programming in Scala' to himself in agony.

21:23 slashus2: agony?

21:24 Raynes: slashus2: I have very little experience in languages that aren't totally wrapped in parentheses. After using Clojure, looking at anything else hurts my eyes. I suppose this will pass soon.

21:33 * eee appreciates clojure but thinks about scala more so some of his errors might be caught by the compiler ... with a nice arrow pointing to his problem

21:36 hiredman: *snort*

21:36 eee: are you in #scala?

21:36 eee: no

21:36 are you?

21:36 hiredman: yeah

21:36 everyday someone bitching about compiler bugs

21:36 eee: i'm just aying the thought crossed my mind

21:36 that's all

21:36 (ducking)

21:37 hiredman: #scala does not sell scala at all

21:37 eee: do you use that lang, too?

21:37 hiredman: nope

21:37 just curious

21:38 eee: i understand they inheritted clojures cool persistent datastructures

21:38 or some of them

21:38 hiredman: they definetly have their share of problems

21:38 unlink1: ataggart: no, clojure absolutely does not have an optional type system.

21:38 (static) type system

21:38 hiredman: eee: apparently the guy who wrote the research papers rhickey based them on is in the scala camp

21:39 bagwell?

21:39 eee: i see

21:39 i'm writing one

21:39 hiredman: but clojure got them first :P

21:39 eee: you may know

21:40 here's a little math riddle. probably easy for ya'll

21:41 maybe i need a simple if-check that say's if, zero than 4. But what's a more elegant way to make mod 4 return values, 1 2 3 . . .. like normal, but 4 instead of zero

21:42 hiredman: ,(- (mod 10 5) 1)

21:42 clojurebot: -1

21:42 hiredman: hmm

21:42 eee: it's funny what I can just believe in my head . . .. vice what I can program sucincly

21:42 hiredman: ,(- (mod 10 4) 1)

21:42 clojurebot: 1

21:42 hiredman: ,(+ (- (mod 10 5) 1) 5)

21:42 clojurebot: 4

21:42 eee: ,(mod 10 4)

21:42 clojurebot: 2

21:43 eee: still needs to be 2

21:43 i thought I had it .. .. but doesn't work for 1 2 or 3

21:43 here's 15 mod 4

21:43 hiredman: ,(* (mod 10 8) 2)

21:43 clojurebot: 4

21:43 eee: ,(int (mod 15/4 8))

21:43 clojurebot: 3

21:43 hiredman: ,(mod 10 8)

21:43 clojurebot: 2

21:44 eee: correct

21:44 (int (mod 10/4 8))

21:44 ,(int (mod 10/4 8))

21:44 clojurebot: 2

21:44 eee: ,(int (mod 12/4 8))

21:44 clojurebot: 3

21:44 eee: ay

21:44 should have been 4

21:44 ,(int (mod 12/4 16))

21:45 clojurebot: 3

21:45 eee: i'm dumb

21:45 i'll just do the if

22:02 yahoooo clojure is the coolest!

22:02 i.e. i found my problem

22:02 :)

22:03 dynamic typing is the way to go again

22:09 unlink1: nah nah

22:22 gcv: is it just me, or is slime-compile-defun flaky with resolving classes imported earlier in (ns ... (:import ...)) forms? slime-compile-and-load-file seems to work fine, which suggests some kind of namespace matching problem. I used slime-repl-set-package, though... and it seemed to work fine until I restarted the repl a minute ago

22:37 defn: user=> user=> java.lang.Exception: Unable to resolve symbol: lazy-cons in this context (core.clj:70)

22:38 I get this when starting slime/clojure repl using swank

22:39 nevermind it fixed itself when i updated the repo

22:40 cmvkk: yeah lazy-cons is no more

23:07 gcv: slime-compile-defun definitely has trouble with namespace resolution. I just saw a function compile fail in a file, then succeed when I saved that file under a different name and tried again

23:32 * ice_four finally got JOGL working

23:55 gcv: definite flakiness with current package tracking in swank-clojure

23:56 it picks up a nil package sometimes, which the code translates to the user namespace, which wouldn't have necessary imports for a particular file except by accident

23:56 still trying to figure out where the nil namespace comes from

Logging service provided by n01se.net