#clojure logs

2009-05-09

00:42replacadanlarkin: are you still hanging out?
03:01cadsis it hard to write a custom m-expression syntax for a lisp?
03:03cadseww gross, I've used a m-exp language before, mathematica
03:04cadsthough the array slicing was nice
03:04cadsbut eeew, I don't want to program in mathematica
03:05p_lcads: so far, any m-exp system died...
08:01rhickeyhttp://www.javaworld.com/javaworld/jw-05-2009/jw-05-clojure.html
08:06wlrrhickey: congrats on the mainstream attention ^^
08:07rhickeywlr: thanks - hopefully Java One will help broaden awareness as well
08:09wlrrhickey: if folks put aside irrational bias against lispy things and listen to what you say, it will
08:29nakysshow do i register here??
08:30eee,(doc cond)
08:30clojurebot"([& 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."
08:31eeeare there any other special keys besides :else?
08:31kensanatanakyss: /msg nickserv help
08:31eeeit appears cond is behaving more like "finally" for me maybe?
08:35nakyss+r
08:37nakyssHello all
08:37nakyssI'm try to solve this prblem
08:37eeehi
08:38eeeme too
08:38eee:(
08:38eeein my case cond seems to find a condition AND execute the else
08:38nakyssI can't get a hold of an interface
08:39nakyss(def sourceDataLine (AudioSystem/getSourceDataLine audioFormat))
08:39nakyss(. sourceDataLine open audioFormat)
08:39eeewhich is the object
08:39nakyssand i get : java.lang.IllegalArgumentException: No matching method found: open for class com.sun.media.sound.DirectAudioDevice$DirectSDL
08:39eeeand which is the method
08:39eeeand which is the param
08:41eeeopen the method you want?
08:42nakyssthe sourceDataLine var is supposed to be an SourceDataLine interface, it has nithing to do with com.sun.media.sound.DirectAudioDevice$DirectSDL...
08:45eeedid cond have a bug in some version that I have?
08:45nakysswhat's your problem eee?
08:47eeewhen I do a (cond), one of the cases works
08:47eeebut it still seems to do the else
08:47eeein addition
08:47eeei use :else
08:47nakysspaste your code maybe
08:48eeei'll group pertinent stuff together
08:50lisppaste8eee pasted "cond question" at http://paste.lisp.org/display/79928
08:50eeeit's printing "got here" "got here2"
08:51eeealso, it prints the empty vector even though I tried to cull it out
08:53Lau_of_DKGood afternoon gentlemen
08:53eeecan you try (.open sourceDataLine audioFormat)?
08:53eeehi Lau_of_DK
08:53nakyssyes it does thtet same error
08:54nakyssyour cond form seems to end before all the conditions
08:54eeewell well
08:54eeeyou found it
08:55eeenow I know where lisp got that acronym!
08:55eee"infernal parens"
08:55eeethanks
08:56nakyssyr welcom
08:56eeethat's a huge lesson to remember to check
08:57nakyssuse an editor with paran matching
08:57eeefunny thing is, I do
08:57eeebut i should have gone back line by line
08:57eeeonce you mentioned that
08:57eeei just ran the cursor up the right side
08:58eeenow I can move on the the next thing that has had me perplexed for a day
08:58eeewhich is that when I use 100 for that special spot, everything works
08:58eeebut when I use 99 or below it doesn't
09:01nakyssDoes anyone have any idea?
09:01nakyss(def sourceDataLine (AudioSystem/getSourceDataLine audioFormat))
09:01nakyss(println "sourceDataLine :" sourceDataLine)
09:01nakyssprints java.lang.IllegalArgumentException: No matching method found: open for class com.sun.media.sound.DirectAudioDevice$DirectSDL
09:02eeeyou are saying that sun.media thing isn't what you are working with?
09:02nakysseven though getSourceDataLine return a SourceDataLine interface
09:02nakyssyeap
09:02eeeso fully qualify
09:03nakyssit does the same :(
09:04eeeseems like in some java file the ide imported the wrong thing
09:04eeego look in the java code for a bogus import
09:04nakyssi have a java version of the codde which work greats so...
09:05eeethen your clojure class path has things in a different order than your java version?
09:08nakysswell it's possiblebut package name should be unique so that shouldn't interfere
09:08eeei agree
09:09eeethere might be a way to unimport something in clojure
09:09eeei'm pretty sure
09:09eeeseems like a hack
09:09eeebut if it works
09:09eeeit will tell you something
09:10eeeunimport that bogus stuff
09:11nakysswhether it's a bug in clojure or i'm doing somthing wrong, the former is very unlikely
09:12nakyssshould i use proxy to deal with interface?
09:13eeei wish I knew more to help
09:13eeei'm not too competent in clj
09:13nakyssthx anyway me neither as you can see
09:14eeei'd try unimporting that bugus package
09:14nakyssnot very active irc channel here?
09:14eeesometimes you get 2 or three talkers
09:16nakyssi'll go post on clojure google group then
09:16eeethat will work
09:19lisppaste8eee pasted "works with 100 fails with 99, why" at http://paste.lisp.org/display/79930
09:19eeei don't know why it matters what blank string I use
09:20eeefor the stupid scorer, the values should be arbitrary
09:21eeeit works with a letter, too
09:21eeejust not a string that represents a number less than 100
09:21eeesooooo confusing
09:21acieroidhmm
09:22acieroidhow can i eval code from a string ? something like (foo "(* 6 7)") -> 42
09:23eeei've seen that in the discussion posts
09:24acieroidwhere are those discussions posts ?
09:26eeehttp://groups.google.com/group/clojure
09:26acieroid'k
09:26acieroidthanks
09:27acieroidok great
09:27acieroid(eval (read-string "(* 6 7)"))
09:28acieroidso simple :D
09:28eeehow'd you find it so fast?
09:28acieroidby searching in the group
09:28acieroid"eval string"
09:28eeecool
09:28acieroida bit of luck \o/
09:29eeei have no approach for solving this prob
09:29eeeperhaps I'll post the whole thing to the group soon
09:43Carkthe article is not 100% acurate, but all in all it gives a good overview
10:55acieroidhmm
10:56acieroidhow can I do smth like (re-seq #(str "foo" "\w+") foo)
10:56acieroidI mean, building regex at eval time, from concatened string or others functions
10:57acieroidhum, with re-pattern i think
11:26replacaacieroid: use re-pattern
11:26replacaoops, not yet enough coffee for reading comprehension!
11:28danlarkinreplaca: you rang last night?
11:34unlinkDoes any .NET language have a decent REPL on Linux?
11:55acieroidreplaca: :D
11:55acieroidthanks anyway
11:56acieroid:w
11:56acieroidoops
12:04dreishunlink: 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:06unlinkI've tried fsi, ironpython, and booish, and they're all nearly unusable
12:20dreishWhat's wrong with them?
12:21dreishWithout knowing much about it, I would have guessed ironpython would be handy, for example.
12:52acieroiddoes anyone have an exemple of using threads with clojure ?
12:53dreish,(.run (Thread. #(println "hello threads")))
12:53clojurebothello threads
12:53acieroidoh, so simple
12:54dreishMake that .start to actually run in a different thread.
12:54dreish(I'm assuming that wouldn't work so well with clojurebot.)
12:54dreish,(.start (Thread. #(println "hello threads")))
12:54clojurebotnil
12:54slashus2dreish: You don't call .start?
12:54dreishYeah, output goes off to nowhere.
12:54slashus2yeah
12:54dreishslashus2: You do. Just doesn't work with cjbot.
12:55dreishhiredman probably has "hello threads" somewhere at his repl now.
12:55nakysscan we import java class with the cjbot
12:56durka42,(import '[java.io File])
12:56clojurebotnil
12:56dreishacieroid: agents are maybe the more idiomatic way to do things in a different thread.
12:56acieroidagents ?
12:56acieroidI'll look at that
12:57dreishhttp://clojure.org/agents
12:57nakyss,(import '(javax.sound.sampled AudioFormat AudioInputStream AudioSystem LineUnavailableException SourceDataLine))
12:57clojurebotnil
12:57durka42,(binding [*out* *out*] (.start (Thread. #(println "hello threads"))))
12:57clojurebotnil
12:58acieroidbut you know dreish, I just want that a call to a function don't block the repl
12:58nakyss(def sourceDataLine (AudioSystem/getSourceDataLine audioFormat))
12:58nakyssoops
12:59nakyss,(def sourceDataLine (AudioSystem/getSourceDataLine audioFormat))
12:59clojurebotDENIED
12:59durka42acieroid: then you want an agent
12:59acieroidok
12:59durka42nakyss: no def
12:59nakyssno def :(
13:03nakysssorry for the noise just testing some stuff
13:03nakyss,(.open (AudioSystem/getSourceDataLine (new AudioFormat 44100 16 1 true true)) (new AudioFormat 44100 16 1 true true))
13:03clojurebotjava.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:03nakyssdoes anyone know why this happened
13:06nakyssno just ignore that
13:44slashus2How do you access a static class inside of an interface like DataLine.Info in javax.sound.sampled?
13:47liebkeslashus2: javax.sound.sampled.DataLine$Info
13:48slashus2Oh, I thought I tried that.
13:48slashus2That seems to work.
13:48slashus2I think
13:48slashus2alright, than kyou
14:28cultureulteriorI'm new to clojure and lisp-like languages- what's the equivalent to python's star operator?
14:29slashus2multiply or in argument lists?
14:29cultureulteriorargument lists
14:30slashus2(defn testfn [firstargument secondargument & containstherest])
14:33cultureulteriorI must be asking wrong. I mean for when calling functions...
14:34slashus2cultureulterior: Can you show a python example of what you are trying to find the equivalence of?
14:35cultureulteriorthefunction(*theargs)
14:36cultureulteriorwhere theargs is a tuple or vector
14:38slashus2(apply function argumentlist)
14:40cultureulteriorThank you
14:46stuhoodclojurebot: reduce?
14:46clojurebotI don't understand.
14:47stuhoodclojurebot: reduce
14:47clojurebotNo entiendo
14:47stuhoodshoot... what is his quip about reduce not being lazy?
14:48stuhood~braindump
14:48clojurebotTitim gan �ir� ort.
14:50durka42~brain dump
14:50clojurebotbrain dump is http://clj.thelastcitadel.com/clojurebot
15:28nakysshi all
15:28nakysshow to get the string name of a symbol
15:29nakyss(def test nil)
15:29nakyssI want to print test
15:30slashus2,(str 'test)
15:30clojurebot"test"
15:30Cark(name 'test)
15:30Cark,(name 'test)
15:30clojurebot"test"
15:31nakyssthx
15:34nakyssit turns out it's not quite what I wanted
15:34nakyssI want to define such a fuction
15:34nakyss(defn debug [x]
15:34nakyss (println 'x ":" x))
15:34nakyssthat would print the name of the var
15:34Carkmhh
15:34nakysslike (debug test) -> "test : nil"
15:35slashus2(var test)
15:36nakyss,(defn debug [x] (println (var x) ":" x))
15:36clojurebotDENIED
15:37nakyssit fails: Unable to resolve var: x in this context
15:37slashus2nakyss: You probably need to create a macro.
15:37nakyssany suggestions? plz
15:38slashus2nakyss: search for clojure debug macro into google and go to the first result.
15:38eeehiyas
15:40Cark(defmacro d [name] `(println '~name "=" ~name))
15:40Carkthat should do it
15:40Carkusage : (d *my-var*)
15:41Carkhello eee
15:41Carkthen you can do fun stuff like : (d (+ 1 3))
15:42Carkand refactor the macro to return the result
15:42eeei;m still stuck i've been really stuck for days
15:42nakyssok great thx
15:43eeenakyss you got that problem fixed now?
15:43eeewhat was it?
15:43AWizzArdCark: maybe you can embed the println in the macro inside a do
15:43rhickeyeee: stuck on what?
15:43nakysseee do you earlier today or just now
15:44nakyss> eee do you mean earlier today or just now
15:44AWizzArdCark: 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:44eeenow I gotta figure out how to put it back the way it was
15:44eeei have a 15-puzzle
15:44eeewhere it shouldn;t matter what strings I use
15:44eeei define one to be the blank
15:44eeethat moves around
15:45CarkAWizzArd : sure
15:45eeewhen I make it a letter
15:45eeeit works fine
15:45eeewhen I make it a number string less than 100
15:45eeeit doesn't work
15:45eeebut my heuristic doesn't care about numbers
15:45eeejust equality
15:45CarkAWizzArd : though you might want to define a prog1 macro first for easier reading
15:45Carkor a returning function =)
15:45eeecause I didn't switch to the manhatten heuristic yet that does care about numbers
15:46eeei've pasted the code before
15:46eeebut let me get it back to that state if I can
15:46eeemade a generic a-star search with the heap
15:46eeetrying to show some examples in clojure
15:48nakysskeep it concise eee. here isn't really a place to post go to google group :)
15:49eeethis might have ben one prob:
15:49eee,(= [] nil)
15:49clojurebotfalse
15:50eeewhich I seemed to remember from lisp
15:55lisppaste8eee pasted "works with 100 fails with 99, why" at http://paste.lisp.org/display/79939
15:55eeeprobably pretty wacky code ... i'd built it up from smaller things
15:59eeeit runs forever if you use "99" for the blank
16:00eeeor "98"
16:00eeemust be something low-level I don't get
16:01rhickeyeee: right, (= [] nil) is bad, what are the possible values of goal-s ?
16:01rhickeyare you using [] as a 'done' sentinel?
16:02eeeno, trying to throw those out
16:02eeebecause they are bad transitions
16:02rhickeyif so, then (if (seq goal-s) ...
16:02eeeif the blank is in the cornet or on the side
16:02eeecorner
16:03eeeok
16:03eeeso i thought with "next" that worked the way it is
16:03eeewith rest I need seq
16:03eeeas tested before
16:03eeewill make the change tho
16:03eeeno change
16:04eeeruns forwever with "99" solves with "100" or "B" for the blank
16:04eeebut what I use for my string should be arbitrary in my mind ... for score-state-stupid
16:06lisppaste8eee annotated #79939 "made emptyVec? predicate" at http://paste.lisp.org/display/79939#1
16:07rhickeyeee: are you comparing strings somewhere?
16:07eeein case I didn't answer the question, '(["1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15" "99"])
16:07eeethat is the goal
16:07eeeyes
16:08eeecomparing strings in 'score-state-stupid
16:08eeewell comparing list of strings
16:08eeeelement by element
16:09rhickeyeee: you are saying it behaves differently if you replace the 2 "99"s in the call with "100"s?
16:09eeeyes
16:10eeeit completes right away
16:10eeewell no
16:10eeeone other place too
16:10rhickey3 places to change
16:10eeeyes
16:14eeerhickey, I really appreciate you looking ... I feel bad now that I have to take off in a minute or two
16:15rhickeyif the strings are treated completely like symbols, this is hard to believe - you never do math with them ?
16:15eeenot that I know of
16:15eeeI can check it all in like this
16:16eeeand it's in my heap project
16:16eeei was about to do math in the new heuristic
16:16eeewhich is why I found the problem
16:17eeehttp://code.google.com/p/jc-pheap/source/checkout ... if this is interesting
16:17eeei hope it's not something too dumb
16:18eeegotta go, will leave my notebook open in case there's more on the subject. Thanks again
16:20cultureulteriorWhat version of java should I be running for an an optimal clojure experience? I'm referring here to GC and such
16:20AWizzArd,(* 0.4 150 1.5)
16:20clojurebot90.0
16:21AWizzArd,(* 1.5 0.4 150)
16:21clojurebot90.00000000000001
16:21AWizzArdrhickey: do you see that?
16:21gnuvince_AWizzArd: in Python:
16:21gnuvince_>>> 0.4 * 150 * 1.5
16:21gnuvince_90.0
16:21gnuvince_>>> 1.5 * 0.4 * 150
16:21gnuvince_90.000000000000014
16:22rhickeyAWizzArd: I see floating point doing what it always does
16:23rhickey,(* 4/10 150 15/10)
16:23clojurebot90
16:23rhickey,(* 15/10 4/10 150)
16:23clojurebot90
16:26AWizzArdI tried clisp. For both forms it returned 90.0
16:27gnuvince_AWizzArd: try C, C++, Java, Python, Ruby, Haskell, etc. they'll all give the same answer as Clojure I bet.
16:28AWizzArdI just tried Ruby. Got 2x the 90.0
16:28svdm,(apply * (map bigdec [1.5 0.4 150]))
16:28clojurebot90.00M
16:28AWizzArdIn C, C++, Java I won't be surprised
16:29AWizzArdthere I expect that floats do what every computer scientist knows
16:29gnuvince_AWizzArd: Haskell, Python and OCaml gave me the same answer as Clojure.
16:29gnuvince_Don't have Ruby installed.
16:29hiredmanwell, clojure floats are java floats, so ...?
16:30gnuvince_I don't see the problem either since Clojure can just use BigDecimals or Rationals.
16:30AWizzArdShould it not default to correct results? We should ask for speed if correctness is not preferred.
16:30hiredmanit is correct
16:31hiredmanit follows the spec for floating point math
16:31hiredmanif you don't want floating point math, don't use floats
16:31AWizzArdit is clear that it must give these outputs of the FPU is used, but the results are mathmatically not correct
16:31AWizzArdof the FPU ==> if the FPU
16:32hiredmanthey are correct for floating point math
16:32hiredmanwhich is what happens when you use floats
16:33AWizzArdWhy are floats used as default and not only when one explicitly askes for them?
16:33hiredman,(class 1)
16:33clojurebotjava.lang.Integer
16:33AWizzArdthat would match the behaviour for integers
16:33hiredman,(class 0.1)
16:33clojurebotjava.lang.Double
16:33AWizzArd(+ 999999999999999999999999999999999999999999 99999999999999999999999999999999999999999999999999999999)
16:33AWizzArd,(+ 999999999999999999999999999999999999999999 99999999999999999999999999999999999999999999999999999999)
16:33clojurebot100000000000000999999999999999999999999999999999999999998
16:33AWizzArdno overflow
16:33AWizzArdwhy correct behaviour here but not for floats?
16:34slashus2I guess that is the behavior that most people expect.
16:34hiredmanbecause the bahviour is correct for floats, by definition
16:34rhickeyfloating point is an inexact representation, as you perform successive operations you accumulate error - there are some numbers it simply can't represent
16:35AWizzArdright, it can represent nearly none of the real numbers
16:36AWizzArdI did not expect 90.000000000000014 when I tried 1.5 * 0.4 * 150 in Ruby or clisp
16:36AWizzArduhm, that last one was for slashus2 :)
16:37gnuvince_AWizzArd: and should Clojure do the right thing when (+ 1 "2") obviously meant (+ 1 2)?
16:38AWizzArdI can see a difference between (+ 1 "2") and (* 1.5 0.4 150)
16:38AWizzArdWhy are those numbers floats or doubles and not BigDecimals?
16:38hiredmanwell, obviously, I meant I wanted to concat the toString of 1 to "2"
16:39gnuvince_AWizzArd: just write a patch
16:39gnuvince_But I don't think you'll get much traction.
16:39AWizzArdCan that be written in Clojure or does it require Java knowledge?
16:39hiredmanI don't think java does the auto-promotion stuff with bd
16:40hiredmanso you would have to cast every single time you pass a number to a java method
16:40AWizzArd,(+ 1.5M 0.4M 150)
16:40clojurebot151.9M
16:40AWizzArd,(* 1.5M 0.4M 150)
16:40clojurebot90.00M
16:40hiredman,(.charAt "foo" 1M)
16:40clojurebot\o
16:40AWizzArdMaybe the M should be implicit, while floats or doubles require a F or a D
16:40hiredmanhuh
16:40hiredmango figure
16:41gnuvince_And break backwards compatibility?
16:41gnuvince_Rich and Stu are gonna love you :)
16:41AWizzArdWould it break backwards compatibility if the M will still be supported?
16:41gnuvince_I think defaulting to Double is a fine choice
16:42eeeyour questions helped me figure it hour rhickey
16:42gnuvince_It's what the Java people expect.
16:43AWizzArdgnuvince_: and would getting overflows for multiplying big numbers also be a good choice then?
16:43eeedrove back to tell you not to waste the cycles:
16:43eee:)
16:43AWizzArdI think a good choice would be: correctness first, speed when people ask for it
16:44AWizzArdI 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:44chrizelfor most applications floating point math is enough
16:44AWizzArdI am not against the use of the FPU
16:45AWizzArdone could just simply ask for floats
16:45AWizzArdfor most applications correct math would also be enough
16:45chrizelno because its slower
16:45eeerhickey: 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:46AWizzArdchrizel: Does that mean you don't like Clojures behaviour in not letting integer operations overflow?
16:46AWizzArdWhat Clojure is now doing is slower. It could simply use ints and longs under the hood und overflow for more speed.
16:46eeeok see yah again
16:47AWizzArdAnd if someone cares for speed: why not specify it? (float 1.5) or 1.5F
16:47AWizzArdIn nearly all aspects Clojure has the motto: let us do the correct thing by default.
16:47slashus2AWizzArd: 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:48slashus2Clojure is pretty unique anyway.
16:48AWizzArdI just wanted to say that ;)
16:48AWizzArdpeople who don't come from the Lisp world will see 80% of new stuff
16:48AWizzArdimo it's a minor issue to live with mathematically correct results
16:49gnuvince_Not if every time you want to send x to a Java method, you need to cast it back to a double
16:50gnuvince_The thing with the Integer/BigInteger promotion is that it happens only when needed. Otherwise, it stays an Integer.
16:50gnuvince_So you can say (.foo bar (* x y)) without having to cast that down to Integer
16:51AWizzArdWhat if (* x y) results in a number of 600 digits?
16:52gnuvince_AWizzArd: then you couldn't pass it to that method anyway
16:52gnuvince_As it would expect an Integer parameter.
16:52AWizzArdCan't Clojure do this casting back to float/double under the hood
16:52AWizzArd?
16:53chrizelHow would you determine whether a float is "too big" or would be incorrect? (are there any languages doing this?)
16:53AWizzArdYou mean a language implementation?
16:54gnuvince_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:54gnuvince_Let's say there's a trivial method called addOne. (.addOne myBigDecimal)
16:54AWizzArdyes
16:55gnuvince_You'd expect an answer that's exactly one larger than myBigDecimal.
16:55gnuvince_However, because of the inherent imprecision of doubles, that could not be case.
16:55AWizzArddoes addOne expect a float, a double or a BigDecimal object?
16:55AWizzArdIf it expects a float or double I would not expect a correct result
16:56gnuvince_I assume here it's expecting a Double, sicne we're talking about implicit conversion from BigDecimal to Double
16:56gnuvince_since*
16:56AWizzArdthen I would not expect that the number is exactly one more than my input
16:57AWizzArdIt could mean that the program must stop or do something else.
16:57gnuvince_Why not
16:57gnuvince_"Clojure has correct floating point mathematics"
16:57AWizzArdThe potential problem is only data that comes into the program during execution
16:58AWizzArdfor all data that is a consequence of my program I can find out if there are problems by just running my code
16:58AWizzArdIf new data enters a program each good programmer will let it only go deeper if it meets the requirements
16:59AWizzArdIf you read a big double and add one it could overflow and become a very big negative number
16:59AWizzArdor not?
16:59AWizzArdmaybe it can become infinite instead, not sure
17:00AWizzArdso, 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:00AWizzArdIf it can pass my tests then the conversion from BigDecimal to double would not cause problems and I get my number+1
17:01slashus2,(Math/pow 50000 50000)
17:01clojurebotInfinity
17:01AWizzArdexactly
17:01acieroidhmm, 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:02AWizzArdEach 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:02gnuvince_AWizzArd: how long do you think it would take to compute the real answer?
17:02chrizelacieroid, (apply str (take 100 foo))
17:03AWizzArddoes it have to do with why (* 1.5 0.4 150) should result in 90.000000000000014?
17:03acieroidthanks :o
17:03slashus2Has anyone completed a pow and sqrt clojure implementation that does correct math?
17:03gnuvince_Whatever
17:04gnuvince_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:05AWizzArdslashus2: for only a very small set of real numbers there exists a result that can be algorithmically expressed
17:05AWizzArdfor calculating roots and so on
17:06AWizzArdgnuvince_: do you see it is legitimate to report bugs and discuss about things that one percieves as bugs without providing a patch?
17:08slashus2The BigDecimal pow function only takes in integer, which isn't the best way to go. I don't think.
17:08slashus2integers*
17:09AWizzArdagreed
17:09slashus2It is crippled compared to Python's Decimal package
17:10AWizzArdyes, seems that way
17:10AWizzArdmaybe this will become better when Sun .. hmm.. Oracle wants to push Fortress a bit more?
17:10AWizzArd(if they want to do so at all)
17:12gnuvince_,(let [v [1 2 3 4]] (time (dotimes [_ 1e6] (first v))))
17:12clojurebot"Elapsed time: 239.412 msecs"
17:12slashus2I 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:12gnuvince_,(let [v [1 2 3 4]] (time (dotimes [_ 1e6] (v 0))))
17:12clojurebot"Elapsed time: 102.065 msecs"
17:13AWizzArdThere is this gnu calculator program, don't remember its name right now.. can that do 1.2345^6.757 ?
17:16AWizzArdclisp can :)
17:16gnuvince_bc
17:16AWizzArdah right, bc, thx
17:16slashus2What is special about 1.2345 to the 6.757?
17:17AWizzArduh nothing, just typed some digits
17:17slashus2,(Math/pow 1.2345 6.757)
17:17clojurebot4.151502692911114
17:18AWizzArd,(Math/pow 1.2345M 6.757)
17:18clojurebot4.151502692911114
17:18AWizzArdso here it worked for a BigDecimal?
17:18AWizzArd(.pow 1.2345M 6.757)
17:18slashus2I don't think so
17:19AWizzArd,(.pow 1.2345M 6.757)
17:19clojurebot3.539537889086624823140625M
17:19slashus2That didn't work like you think it did. It changed 6.757 to 6
17:19AWizzArd,(.pow 1.2345M 6)
17:19clojurebot3.539537889086624823140625M
17:19AWizzArdthis is as you said right? The BigDecimal class has no pow method for doing what I wanted
17:19slashus2right
17:20slashus2It doesn't even have a sqrt
17:20slashus2:-(
17:20AWizzArdWhat surprised me is that after nearly 15 years of Java there still is no class for complex numbers
17:21AWizzArd,(* 1.5 0.4 150)
17:21clojurebot90.00000000000001
17:21AWizzArd,(* 1.5 0.4 150.0)
17:21clojurebot90.00000000000001
17:22AWizzArdgnuvince_: can you try in Haskell: 1.5 * 0.4 * 150 vs 1.5 * 0.4 * 150.0 ?
17:22gnuvince_Same as in Clojure, already told you.
17:23AWizzArdnow I changed something: the 150 became 150.0 (point zero added)
17:23gnuvince_ghci> 1.5 * 0.4 * 150
17:23gnuvince_90.00000000000001
17:23gnuvince_ghci> 1.5 * 0.4 * 150.0
17:23gnuvince_90.00000000000001
17:23AWizzArdk
17:26gnuvince_It wouldn't change anything
17:26gnuvince_because there are Double in the expression, the 150 is infered to be a Double as well.
17:27AWizzArdmakes sense
17:32AWizzArdbtw, does .net have complex numbers and an equivalent to BigDecimal?
17:37gnuvince_~seen Cark
17:37clojurebotCark was last seen in #clojure, 111 minutes ago saying: or a returning function =)
17:42gnuvince_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:43slashus2I wouldn't that that destructuring would be that inefficient.
17:43slashus2think*
17:45AWizzArdgnuvince_: can you please say a bit more about it?
17:45gnuvince_"it"?
17:46AWizzArdthe speed improvement
17:47gnuvince_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:47gnuvince_My goal is to get within 50% of Java's performance without sacrificing too much of the Clojure feel.
17:47gnuvince_(Java takes 12 seconds for the same 1,050 files)
17:47AWizzArdsurprising
17:50gnuvince_Not unexpected though; the vector -> seq conversion can really start to make a difference when it's done roughly 3.5M times.
17:51gnuvince_The two largest bottlenecks in my code at the moment are calls to first and calls to aset-int
17:54AWizzArdwhat profiler do you use?
18:05AWizzArdBtw, 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:05AWizzArdhttp://www.youtube.com/watch?v=omsuTsOmvsc&fmt=18
18:55chrizelShould the function docstring be before or after the parameter list? I saw different styles, there seem to be no strict convention.
18:55cmvkkthe docstring has to come before the parameter list.
18:57hiredmanafter the param list is a bug
18:58cmvkktechnically it wouldn't cause an error, I guess
18:58cmvkkbut it wouldn't be a docstring
18:58hiredmanit would not, but it would not give you a docstring either
19:00chrizelmost 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:01hiredmanI cannot speak for contrib, core definetly has the docstrings before the params list
19:01chrizelok i see, the other style is not a real docstring because it's not saved in the meta data
19:01chrizelthank you, now it makes sense
19:06chrizelironically this docstring inconsistency is even in the ants.clj example by rich himself - that's what confused me too
19:08cmvkkhaha, you're right.
19:09cmvkkto be honest, it's not very intuitive that the docstring is in that particular location. but that's how it has to be.
19:11liebkecmvkk: it makes more sense when you have a function with multiple arities
19:11cmvkkyep. that's why it's necessary.
19:13cadshey, 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:20edgarhello
19:20edgari have see the web site of clojure
19:20edgarand i see is a language for jvm
19:21edgaris there plans to make it a language such as ruby or python? independent of the JVM
19:21liebkecads: that should work, you can also do (empty? (difference a b))
19:22ataggartedgar: one of the points of being on the JVM is to benefit from the many libraries available in java
19:22ataggartthough I think there is a project to try and get clojure running on dot net
19:25edgarwell, on dot net may be great
19:28ataggartwhy?
19:30ataggartwhat deficiency do you see by running on the JVM?
19:30unlinkRunning on the JVM is supposed to be a strength -- you can leverage a huge body of existing libraries.
19:31ataggartplus the JVM itself is badass
19:31unlinkThough I'm not sure I'm a fan of creating a separate class for every function.
19:31ataggartI think (though may be completely off the mark) that that might be addressed with the addition of invokedynamic
19:33unlinkWhat is that? A planned JVM feature?
19:33dnolenhas anybody messed around with protecting java primitive arrays with the Clojure reference types? Is this a good approach?
19:33ataggartnew opcode for the jvm in JSE 7
19:34unlinkOK.
19:34unlinkInteresting.
19:37unlinkIn my mind the only big thing really lacking from Clojure is static typing.
19:38ataggartfunny, I thought the lack thereof was supposed to be a feature ;)
19:38unlinkIt 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:39unlinkAlgebraic types and type inferencing make static typing useful, usable and powerful.
19:39ataggartexample?
19:40unlinktype tree = Null | Leaf of int | Node of tree * tree
19:41unlinkHaskell has an even more powerful type system, but some find it overwhelming.
19:42ataggartI should say, what are you not able to do as easily, usefully, and powerfully without the static typing?
19:42dnolenin 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:43unlinkYou 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:44unlinkgot to run...
19:44hiredmanthat is an interesting point
19:44ataggartwhich brings its own philosophical issue
19:44hiredmanthe issue of homoiconicity
19:44unlinkIs static typing irreconcilable with homoiconicity? discuss.
19:44unlink:)
19:45ataggartlol
19:46ataggartI do like strong typing when it comes to what my IDE can do for me.
19:46ataggartnot having all those nifty features was one of the things that made me hesitant to start with dyanamic languages
19:47ataggartI 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:48ataggartI went back to java the next day
19:48AWizzArdin principle it could be possible that one can put an optional type system on top of dynamic languages
19:48ataggartand clojure sort of has that
19:48ataggartwith meta data
19:49AWizzArdmeta data could be a place where to store those type information
19:49ataggartyup, and multimethods can trigger off of it
19:49AWizzArdit can go even deeper
19:50AWizzArdhttp://groups.google.com/group/clojure/browse_frm/thread/7a48f48e4b197a15/47389c2a78e82b38
19:50hiredmanwell, metadata cannot be attached to everything
19:51ataggartjava strings and primitives iirc, right?
19:51hiredmanjava objects in general
19:51ataggartmm ya
19:51AWizzArdthose already carry type information I guess.. don't know if that information still exists in the bytecode
19:51hiredman,^(with-meta (Object.) {:foo 1})
19:51clojurebotjava.lang.ClassCastException: java.lang.Object cannot be cast to clojure.lang.IObj
19:51hiredman,^(with-meta [] {:foo 1})
19:51clojurebot{:foo 1}
19:52ataggarta not altogether unreasonable cost for switching to using java stuff directly
19:52hiredmanAWizzArd: if that was sufficient, why are type hints needed to prevent reflection?
19:52ataggartthough I can imagine it hurts when common clojure value types (e.g., strings) have that limitation
19:52AWizzArdI 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:53AWizzArdhiredman: I don't know enough about the internal. I just think that reflection is needed when Clojure comes into play
19:54AWizzArd(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:54AWizzArdWith gradual typing however this can be found out before compilation
19:54hiredmanyet (defn a [x] (.toString x)) seems very clear
19:55hiredmanbut unless you type hint x, you will get a reflection waring
19:55AWizzArdyes, for you and me it is clear
19:55AWizzArdthe clojure compiler however does not make use of that information
19:55AWizzArdthat is the dynamism about the language
19:56AWizzArdonly at runtime it will be clear what type the object x has
19:56hiredmanAWizzArd: 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:56AWizzArdbecause Clojure is dynamically typed. Can you tell what class x will have?
19:57AWizzArdthere are thousands of .toString methods. Which should be called?
19:57AWizzArdcurrently 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:58AWizzArdIn a java program variables have a type. In Clojure those are untyped, but objects (at runtime) have a type.
19:58ataggartactually, I'm not sure I have a point. :)
19:58ataggartI'm on my 4th beer
19:58AWizzArdA java program can always look up when you say x.toString() what type x must have
20:00AWizzArduh, 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:01ataggartyes, which carries over into the IDE issue, namely, with the strong/static typing everything that exists is known to exist ex ante
20:01ataggartwith dynamic languages you can't know ex ante what's what
20:01AWizzArdin principle you can.. it just is not very easy
20:01ataggartwell, yeah, you just have to run the code
20:02AWizzArdyou can, if you add a static type system on top of the dynamic language
20:02ataggartwell yes
20:02AWizzArdthat type system could even sit completely in your editor
20:02ataggartI think I'm okay with allow us to make ad hoc type systems
20:03AWizzArdso the compiler won't know anything about the types
20:03AWizzArdthe compiler could be the same. Only your Clojure editor knows about the types.
20:03AWizzArdWhen you say (def x 10) it can tell you that it thinks that x should be of type "byte".
20:03ataggartit'd be nice to get an editor to do that
20:04AWizzArdwhen you later do a (count x) it looks up that count expects a collection, not a byte
20:05AWizzArdall type hints could be put into metadata or comments, and the editor can use code folding to hide them by default
20:07AWizzArdataggart: 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:07ataggartk
20:07ataggartI'm reading the thread
20:09ataggartwatching...
20:09AWizzArdhiredman: btw, how do you turn on the reflection warnings? Via a binding before you compile?
20:22slashus2(set! *warn-on-reflection* true)
20:23gnuvinceAWizzArd: both -Xprof and -Xrunhprof:cpu=samples report roughly the same numbers.
20:25slashus2If 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:34AWizzArdslashus2: ah good thank. I tried alter-var-root ^^
20:34AWizzArdgnuvince: didn't know about those options, thanks
20:40slashus2No one has any idea about the implications of invokedynamic?
20:53slashus2I guess that it could only use the invokedynamic technique when invokedynamic exists, and the current way when not.
20:54cmvkkyeah, a separate version of the compiler for a new java version
20:54cmvkkthere are a few good articles out there about exactly what invokedynamic will do for languages like clojure
20:54cmvkkbut i don't know what they are offhand
20:56eeei thjought this thing would keep the full history
20:56eeedern it
20:56eeenow i don't know what rhickey said
20:57hiredman~logs
20:57clojurebotlogs is http://clojure-log.n01se.net/
20:57eeeis the log saved some
20:57eeeer
20:57eeethanks
20:57eee:)
21:02eeei iguess not much of today in the logs yet
21:02clojureboteveryday is Rich Hickey Appreciation Day
21:03slashus2I think he said that invokedynamic wouldn't do much for clojure.
21:04hiredman~google dynamic languages and invokedynamic
21:04clojurebotFirst, out of 1840 results is:
21:04clojurebotInvoke dynamic languages dynamically, Part 1: Introducing the Java ...
21:04clojurebothttp://www.ibm.com/developerworks/java/library/j-javascripting1/
21:04hiredman:(
21:11eeeis the way to go from "3" to '3 to use javas Integer/parseInt
21:11eee?
21:12eeeor is there something in clojure?
21:14hiredman,(symbol "3")
21:14clojurebot3
21:14hiredman,'3
21:14clojurebot3
21:15cmvkkinteresting.
21:15hiredman,(= (symbol "3") '3)
21:15clojurebotfalse
21:15Raynes,(read-string "3")
21:15clojurebot3
21:15hiredman,(class '3)
21:15clojurebotjava.lang.Integer
21:15RaynesMines better.
21:15Raynes:)
21:15eeeok
21:16cmvkkyour actually works.
21:16cmvkk,(+ (symbol "3") 4)
21:16clojurebotjava.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.lang.Number
21:16eee(read-string ("println \"Hello\""))
21:16eee,(read-string ("println \"Hello\""))
21:16clojurebotjava.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn
21:16Raynes,(read-string "2.3")
21:16clojurebot2.3
21:16hiredmananyway, it depends what you mean by '3
21:17eee,(read-string "(println \"Hello\""))
21:17clojurebotjava.lang.RuntimeException: java.lang.Exception: EOF while reading
21:17eee,(read-string "(println \"Hello\")")
21:17hiredman'foo general means the symbol foo
21:17clojurebot(println "Hello")
21:17eeecool
21:17RaynesI remember read-string because I was pissed off after writing my own function to do that for decimals and finding it.
21:17eeeread-string is god
21:17hiredmanif '3 means the symbol 3
21:17hiredman(symbol "3")
21:17eee,(read-string "(println \"Look at it go\")")
21:17clojurebot(println "Look at it go")
21:17cmvkkhmm...it hadn't occurred to me before this that '3 could be both a symbol and a number.
21:17eeeclever colution!
21:18cmvkki don't think '3 should be a valid symbol.
21:18cmvkki can't think of a situation in which that would be useful...
21:19eeewell, it's just a matter of not making an exception
21:19eeestuff can start with numbers
21:19eeestart with means "followed by n >= 0 stuff"
21:20replacais stuart sierra around these parts anywhere?
21:20cmvkki guess it would mostly never come up, since (symbol "3") is the only way to make that symbol.
21:20cmvkksince '3 just becomes the number 3.
21:23slashus2agony?
21:24Raynesslashus2: 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:36hiredman*snort*
21:36hiredmaneee: are you in #scala?
21:36eeeno
21:36eeeare you?
21:36hiredmanyeah
21:36hiredmaneveryday someone bitching about compiler bugs
21:36eeei'm just aying the thought crossed my mind
21:36eeethat's all
21:36eee(ducking)
21:37hiredman#scala does not sell scala at all
21:37eeedo you use that lang, too?
21:37hiredmannope
21:37hiredmanjust curious
21:38eeei understand they inheritted clojures cool persistent datastructures
21:38eeeor some of them
21:38hiredmanthey definetly have their share of problems
21:38unlink1ataggart: no, clojure absolutely does not have an optional type system.
21:38unlink1(static) type system
21:38hiredmaneee: apparently the guy who wrote the research papers rhickey based them on is in the scala camp
21:39hiredmanbagwell?
21:39eeei see
21:39eeei'm writing one
21:39hiredmanbut clojure got them first :P
21:39eeeyou may know
21:40eeehere's a little math riddle. probably easy for ya'll
21:41eeemaybe 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:42hiredman,(- (mod 10 5) 1)
21:42clojurebot-1
21:42hiredmanhmm
21:42eeeit's funny what I can just believe in my head . . .. vice what I can program sucincly
21:42hiredman,(- (mod 10 4) 1)
21:42clojurebot1
21:42hiredman,(+ (- (mod 10 5) 1) 5)
21:42clojurebot4
21:42eee,(mod 10 4)
21:42clojurebot2
21:43eeestill needs to be 2
21:43eeei thought I had it .. .. but doesn't work for 1 2 or 3
21:43eeehere's 15 mod 4
21:43hiredman,(* (mod 10 8) 2)
21:43clojurebot4
21:43eee,(int (mod 15/4 8))
21:43clojurebot3
21:43hiredman,(mod 10 8)
21:43clojurebot2
21:44eeecorrect
21:44eee(int (mod 10/4 8))
21:44eee,(int (mod 10/4 8))
21:44clojurebot2
21:44eee,(int (mod 12/4 8))
21:44clojurebot3
21:44eeeay
21:44eeeshould have been 4
21:44eee,(int (mod 12/4 16))
21:45clojurebot3
21:45eeei'm dumb
21:45eeei'll just do the if
22:02eeeyahoooo clojure is the coolest!
22:02eeei.e. i found my problem
22:02eee:)
22:03eeedynamic typing is the way to go again
22:09unlink1nah nah
22:22gcvis 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:37defnuser=> user=> java.lang.Exception: Unable to resolve symbol: lazy-cons in this context (core.clj:70)
22:38defnI get this when starting slime/clojure repl using swank
22:39defn nevermind it fixed itself when i updated the repo
22:40cmvkkyeah lazy-cons is no more
23:07gcvslime-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:55gcvdefinite flakiness with current package tracking in swank-clojure
23:56gcvit 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:56gcvstill trying to figure out where the nil namespace comes from