#clojure logs

2008-10-20

00:00AWizzArdwell, one can code object oriented in all programming languages.. but usually this is done mostly in imperative ones
00:00sohailok...
00:00AWizzArdJust see what the ML and Haskell guys are doing. After doing this a few months you won't miss anything
00:00sohailwell let me create a bad object for you: {:Shape :Circle}
00:00sohail\o/ no radius!
00:00sohailanyway, this was just something I was thinking while going through the reference
00:01sohailI might just write something to straight-jacket myself
00:01AWizzArdmultimethods are just a subset of pattern matching
00:01AWizzArdClojure has no pattern matching (by descision) so it gives us destructuring and multimethods
00:03sohailAWizzArd, thanks for your help
00:03sohailwhenever one encounters something new, one always attempts to make it fit past experiences
00:03rukubitessohail: yes, lisp has always been about great power, and it is up to you to exert the great responsibility.
00:03hoecksohail: right :)
00:03AWizzArdof course one does.. but try to forget oop fully and dive into pure functional programming
00:04sohailsee something else that bothers me is that everything is typeless
00:04sohailno it isn't
00:04sohaildamnit, you can figure out the type of a struct right
00:04AWizzArdyou can
00:04sohailhow?
00:05AWizzArd(class (struct foo 10 20))
00:05AWizzArd==> #=clojure.lang.PersistentStructMap
00:05AWizzArdjust think of other names
00:06AWizzArddefstruct confuses you, because it absolutely has nothing to do with structures
00:06sohailAWizzArd, but how can I determine that (struct foo 10 20) was of type foo?
00:06sohailAWizzArd, probably
00:06AWizzArdas you know them from C, Lisp, whatever. Nothing with structs, nothing with classes
00:07rukubitessohail: if it contains the keys a foo contains.
00:07AWizzArdwhat is the type of this (list 'foo 10 "hallo") ?
00:07sohaila list?
00:07AWizzArdright
00:07AWizzArdand whatever it contains, it will not change
00:08AWizzArda Structured Map is a different data type
00:08sohailok so what if I have an app that is filled with structs all over the place which I created using (struct foo ...), and now I need to dispatch on the different foos?
00:08sohailseems I have no options
00:08AWizzArdit is like a list that you write on a piece of paper.. you write columns with headlines, and then add rows
00:08AWizzArdlike a table in sql
00:09sohailwell I have very inefficient options (compare all the keys!)
00:09AWizzArd(defstruct ..) could have been named as: (create-new-table ...)
00:09sohailI understand that
00:09AWizzArdyes
00:09sohailit's a collection of stuff
00:09AWizzArdyou can go on and build up structures as you know them
00:09sohailso it seems the right way to get away from that is to always have some indirection
00:09AWizzArdbut defstruct has nothing to do with them
00:10arohnersohail: the keys in a struct do not define a type
00:10sohailso there can be no types like cats and dogs?
00:10AWizzArdstruct is short for 'Structured Map'
00:10AWizzArdsohail: for now thing that there are no types such as cats and dogs
00:11AWizzArdthink
00:11sohailok
00:11AWizzArdbut of course you could always implement the abstractions to have them
00:11AWizzArdClojure wants to leave the land of types
00:11AWizzArdthat was yesterday
00:11AWizzArdClojure is doing it more general
00:11AWizzArdno dispatch on types
00:12sohailI ese
00:12sohailsee
00:12sohailthis is the philosophy of the language
00:12sohailyes, quite different!
00:12AWizzArdit may be unfortunate that the name (defstruct ..) reminds people of something
00:12AWizzArdit is very difficult to stop ones brain to do its associational work
00:12sohailso it is typeless
00:12sohailwell, the type system is fixed
00:12AWizzArdeverything has a type
00:12rukubitesAWizzArd: To be fair, it is also used as the basis of polymorphism, which encourages the thought of it as an object.
00:13AWizzArdok
00:13arbschtsohail: you can tag an object either with a property, or with metadata, if necessary
00:14sohailarbscht, sure
00:14sohailbut then we are getting into object system on top of clojure territory
00:15arbschtthere is common ground, naturally
00:15AWizzArdyou will just need some weeks-months training in functional programming, and you will see that Clojure is 4-dimensional and you can give up 2-dimensional thinking :-)
00:16sohailperhaps
00:16sohailI just don't see what doing everything by the seat of your pants has to do with functional programming :-)
00:16sohailbut I'm willing to find out!
00:17walterssohail: the main thing about clojure is immutable data structures; objects tend to be mutable
00:18sohailwalters, I find that totally orthogonal to not being able to extend the type system, but that's just me
00:18sohailI should shut up now before I piss you all of and then no one will help me
00:18sohails/of/off/
00:21AWizzArdwait, I give you another example
00:22AWizzArd(defmulti foo (fn ([collection] (first collection)) ([a b] (+ a b))))
00:22AWizzArdYou understand this so far?
00:23arohnersohail: I understand your ... anxiety. I've been in that situation when learning clojure
00:24arohnerand by type system, what you really want is to assert that a collection of data fits into a pattern
00:24arohneri.e. your shape example, a circle would be {:shape :circle, :radius 3}, right?
00:28AWizzArdsohail: just have a look how you can use multimethods in this paste:
00:28lisppaste8AWizzArd pasted "Generality of multimethods" at http://paste.lisp.org/display/68846
00:29rukubitesI am curious why defmulti only supports one argument.
00:29AWizzArdrukubites: in my example you see they support not only one, but even mixed
00:29AWizzArdone and the same multimethod can have one arg or three
00:29rukubitesOh hang on, yes.
00:31rukubitesI was getting sidetracked by the example which only uses defstruct. Another example using something like evenp would be cool.
00:33rukubitesAWizzArd: Your example is convincing me that clojure is quite cool. :)
00:35AWizzArdrukubites: (foo [\H 2 3])
00:35rukubitesYou can do something like (defmulti foo (fn [&more args] (map class-of args))) or the equivalent? Sorry I can't actually write proper clojure being as I have looked at it only today.
00:35AWizzArdit's turing complete
00:36rukubitesMy example is meant to mean that you define a dispatch that polymorphs according to each of its argument's classes.
00:36AWizzArdin the method that you provide to the macro "defmulti" you can do whatever you want
00:36rukubitesYes. Would the above work something like what I intended?
00:36arohnerAWizzArd: wow, that's more powerful than I thought multimethods were
00:38rukubitesAnd of course you can just write a macro which expands to defmulti to more easily express how you want your polymorphism to work.
00:38AWizzArdYou can think of it this way: (defmulti foo dispatch-fun) means: when you do (foo something) then dispatch-fun will be called with something. This will yield a value. Then all multimethods are checked until one is found whose second argument is equal to the value from the call (dispatch-fun).
00:38AWizzArdThen the function you provided to that multimethod is called with "something"
00:40AWizzArdSo, (foo 2 4) ==> it calls my (fn ..) that was provided in (defmulti foo ...). As it has two args the second branch is used: (fn [a b] (+ a b)). For the args 2, 4 it yields 6.
00:41AWizzArdNow the foo-method that has the key 6 will be called with the args 2 and 4. This is (defn foo [arg1 arg2] (* arg1 arg2)). So, the result is 8.
00:44AWizzArdthis is much better than dispatching on types only
00:46rukubitesSorry for a silly question... I want to access java.lang.Object.getClass() on object foo. How...?
00:47rukubitesOh got it.
00:47rukubites(. foo getClass)
00:49AWizzArdand I forgot again how to call System.out.println
00:51AWizzArdno right (.println System/out "huhu Leute")
00:52AWizzArdI'll go to bed, n8
01:04lisppaste8rukubites annotated #68846 with "More polymorphism" at http://paste.lisp.org/display/68846#1
01:04rukubitesThat's my first clojure code.
01:04rukubites(from a fulltime CL programmer)
01:13sohailrukubites, where do you work anyway
01:13sohail<arohner> i.e. your shape example, a circle would be {:shape :circle, :radius 3}, right?
01:13sohailyes, that is all I want
01:13sohailto ensure a specific pattern automatically
01:15rukubitessohail: I am actually a contractor, been working on a common lisp project for a few days short of a year. I telecommute from Australia.
01:15sohailrukubites, ah, I see
01:17rukubitessohail: And with respect to your problem, you are probably going to have to write your own object-verification functions and slot them into defmulti.
01:17rukubitesFor fun, that's what I did in my link above, using a function "classes-of".
01:18rukubitesThough that solution is brittle and unworkable IRL.
01:18sohailrukubites, sure :-)
01:43PupenoSo, if I am using a functional programming language, I can stop worrying about ORM?
01:44rukubitesORM?
01:44H4nsPupeno: yes - you need to worry about how to persist your data, but ORM will not be your solution anyway
01:53Pupenorukubites: Object Relational Mapping.
01:53burkelibbeyWhen I run slime-eval-last-sexp on a sexp with a line break in it (eg. (+ 2 <\n> 2) ), I get "insert-before-markers: Invalid character: -1, #o37777777777, #xffffffff". Anyone seen that before?
01:53rukubitesPupeno: Ahhh yes. E.G. AllegroCache.
01:54Pupenorukubites: in object oriented programming languages you end up using one ORM or another whenever you want to talk to a DB, and you can see that some people, like H4ns believes none should be used. It's a very heated debate with no clear solution.
01:54Pupenorukubites: that doesn't sound like an ORM, but I'm not sure.
01:54burkelibbeyEg. ActiveRecord, DataMapper, and so on.
01:56rukubitesWell I get the idea. We have dealt with issues of objects <--> DBs on my project, just wasn't aware of the term.
01:57rukubites"AllegroCache is a high-performance, dynamic object caching database system."
01:57rukubitesIt's by Franz.
01:58Pupenorukubites: yes, I don't think that's an ORM. cl-sql is ORMish.
01:59burkelibbeyThe impression I get is that AllegroCache provides its own persistence layer, where a true ORM just interfaces between the language and a (usually SQL-based) database backend
01:59rukubitesPostmodern then. :-)
02:00rukubitesWe are currently using the solution of 128gb ram :(
02:00Pupenoburkelibbey: right, you have to have something Relational there to Map to.
02:02Pupenommhhh... this web frameworks should be broken down into libraries, for HTML generation, for SQL, etc... both Compojure and Webjure seems to suffer from all-in-one-monolithic-pack.
02:04rukubitesburkelibbey: By the way, your swank example works fine for me.
02:04burkelibbeyrubikites: Yeah, I figured as much. I'm not sure what I've done wrong. I'll probably go update all my elisp stuff. Thanks.
02:06burkelibbeyerr, I suck at reading
02:06burkelibbeysorry about that massive typo
02:06rukubitesI like rubikites. :D
02:06burkelibbeyhaha
02:06rukubitesIt helps if I capitalize it as RukuBites.
02:06tWipPupeno: webjure now has html and sql stuff in their own files and namespaces
02:07burkelibbeyMuch better :)
02:07tWipFor my needs, HTML generation is very much a core functionality in anything resembling a web framework... so it is included
02:09RukuBitesburkelibbey: Now try doing slime-eval-print-last-expression on your example...
02:11Lau_of_DKMorning gents
02:12burkelibbeyrukubites: Hmmm, weird. That just gives me "Evaluation aborted" regardless of what I'm evaluating.
02:12RukuBitesYes it does.
02:13PupenotWip: yes, that's good (own files).
02:13RukuBitesburkelibbey: I've been told that it is to do with swank/eval-and-grab-output not being implemented.
02:13RukuBitesIt is my 100% favourite feature of SLIME. :(
02:14PupenotWip: eventually, someone will come with a different way of generating html and there would be an endless debate of the-better-vs-the-built-in, and that can be ugly, like what is happening now in Django or Rails.
02:14PupenoAnyway, have to go now, to code for money. See you latter!
02:15burkelibbeyRukuBites: too bad. I only ever played with CL for a couple of days, but liked that feature.
02:16tWipPupeno: I have no problem with that. This is open source, you can always fork if you need something different
02:16tWipI'm doing the "scratch my own itch" thing :)
02:25RukuBitesburkelibbey: Well as my second function to write in clojure, I will attempt to implement it. :-)
02:25burkelibbeyAwesome, my swank problem is fixed. I just git pull'd clojure-mode, swank-clojure, and slime.
02:25burkelibbeyrukubites: ooh, I hope it works out. good luck!
02:26RukuBitesSorry, very silly question... does clojure support multiple return values?
02:27RukuBitesI think the answer is no, just not 100% sure.
02:27hoeckRukuBites: no, not the way cl does, but its easy to return a literal vector and destructure the return value
02:28RukuBitesOf course it is. :-) The issue was in implementing the above function. It is much easier now.
02:30hoeckRukuBites: what does eval-and-grab-output?
02:31RukuBitesC-j in *slime-scratch*
02:32RukuBitesIt returns (a b) where a = *standard-output* of form and b = print-value of form.
02:32RukuBitesa and b are strings.
02:33RukuBites(slime-eval-print-last-expression) is the emacs function.
02:34hoeckaha, yeah, missing that too
02:35RukuBites*nod* I thought so since I pulled all the stuff fresh this morning.
02:36RukuBitesBut I really feel like I'm coding with one hand tied behind my back without it.
02:39RukuBitesHow is Clojure for streams? Does it just rely on java stuff? I looked but am not sure of the topic on the main page. I want to rebind *OUT* and store it as a string.
02:41RukuBitesOoooh, with-out-str. Sweet.
02:59RukuBites*victory*
03:01hoeckRukuBites: can you paste it??
03:01RukuBitesAm pasting.
03:02lisppaste8RukuBites pasted "Swank function for C-j in *slime-scratch*" at http://paste.lisp.org/display/68852
03:03RukuBitesMe too and this is my fourth function written for the language.
03:03RukuBitesIs it the correct idiom for clojure?
03:05RukuBitesI will post it to the list as well, since it works decently for me.
03:05RukuBitesNext on the list is to get slime to treat (in-ns ...) the same as it does (in-package ...)
03:09hoeckRukuBites: works perfectly, thanks!
03:10jdzRukuBites: why is there a with-out-str in there?
03:10burkelibbeyRukuBites: Yes, much thanks.
03:10RukuBitesjdz: Because that captures the *out* of the function.
03:10jdzRukuBites: and i think [retval nil] should be put a line above
03:11jdzRukuBites: *out* of which function?
03:11RukuBites(defn test-fn [] (do (println "Test") (+ 2 2)))
03:11RukuBitesTry C-j on (test-fn) and you will see.
03:16burkelibbeyAnyone have an opinion on paredit-mode?
03:16RukuBitesI like typing my own pars.
03:16burkelibbeyThat's kind of how I'm feeling so far.
03:17RukuBitesAlso I think it rebinds C-j! :( :(
03:17burkelibbeyack, that's no good :P
03:19burkelibbeyrukubites: Have you relocated your parentheses, or do you just use shift+9/0 ?
03:20burkelibbeyI'm considering swapping mine with [] in clojure mode, but I'm not sure if I'll be able to deal with it being different everywhere else
03:22RukuBitesburkelibbey: I just leave them as is, shift 9 and shift 0. My old laptop had euro and dollar keys just to the left and right of the "up" arrow, and I rebound them but never used it.
03:23RukuBitesI found the hook for the in-package to in-ns.
03:23burkelibbeyhmk. Well I need some sleep, thanks for al the help
03:23burkelibbeynice
03:47lisppaste8RukuBites pasted "(in-ns 'foo) support for clj buffers in slime." at http://paste.lisp.org/display/68853
03:48RukuBitesI think I will be quiet now. :-)
04:36Lau_of_DKIs anybody here able to explain (defn find= ...) from clj-me.blogspot.com ?
05:38clp8Can someone give me a had getting swank-clojure to work? I think I have the paths set correctly, but swank-clojure does not agree, because it can't find the clojure.lang.repl class. relevant part of my .emacs and the error is pasted here: http://paste.lisp.org/display/68860
05:52Lau_of_DKTry using absolute paths and no ~/
05:52Lau_of_DK+t
05:55clp8Lau_of_DK: doesn't help
05:55Lau_of_DKit will be part of the solution
05:55Lau_of_DKDid you otherwise follow instruction from the wiki ?
05:56clp8are you thinking that maybe ~ interferes with the jvm?
05:56clp8yes
05:56clp8everything is found, including clojure.jar, except that the repl class is not found
05:56Lau_of_DK~/ is not accepted in elisp
05:56Lau_of_DKBut I notice that you dont set (setq inferior-lisp-program ...) , why not +
05:56Lau_of_DK?
05:57clp8if you're sure...because ~ works throughout the rest of my .emacs
05:57clp8hold on
05:57clp8i'm not sure why not
05:57Lau_of_DKreally? it broke mine
05:57Lau_of_DKI would put this in run-clojure
05:58Lau_of_DK(setq inferior-lisp-program "/path/to/java -cp /path/to/clojure.jar")
05:58clp8I'm not setting it because I'm not using inferior-lisp mode directly, I'm using swank
05:58clp8(or, at least, trying)
05:59clp8i followed this: http://en.wikibooks.org/wiki/Clojure_Programming#Emacs_.2F_Slime_Integration
05:59Lau_of_DKok, then Im blank. I set emacs up to run swank/slime, which works perfectly, just following the direction from the wiki
06:00Lau_of_DKhttp://en.wikibooks.org/wiki/Clojure_Programming#Emacs_.2F_inferior-lisp
06:01clp8that isn't slime...that is using inferio-lisp-mode
06:02clp8*inferior
06:03Lau_of_DKskip to the section below
06:03clp8then we are indeed using the same guide
06:03clp8would you mind pastebinning the clojure section of your .emacs?
06:04Lau_of_DKI wouldnt mind, but its a home Im afraid, at work atm
06:04H4nslisppaste8: url
06:04lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
06:04clp8i'm starting to think that my problem is related to using an old version of clojure. most of these guides are refering to a file called clojure-lang-1.0-SNAPSHOT.jar , and I have a file called something else
06:05lisppaste8H4ns pasted "Clojure related section from my .emacs" at http://paste.lisp.org/display/68861
06:06H4nsclp8: clojure-lang-1.0-SNAPSHOT.jar is the file that you get when you compile clojure from source.
06:06H4nsclp8: (at least that is what i got)
06:07clp8hmmm. Perhaps I should do that, then
06:08clp8your line; (setq swank-clojure-binary "/home/hans/bin/clojure")
06:08H4nsclp8: does clojure work for you on the command line?
06:08clp8yes
06:08clp8but, I was going to ask, does that line link to? a binary, or a directory?
06:08H4nsclp8: it is a shell script
06:08clp8that launches clojure?
06:09H4nsclp8: i like that better than referring to the jar from emacs, as i will have the same setup in slime and on the command line
06:09H4nsclp8: yes, with the right classpath and stuff.
06:09clp8ie, something that contains java -cp clojure.jar foo.bar.repl?
06:09H4nsexactly
06:09clp8i might try that, then
06:09clp8darn, I have a lecture :(
06:09H4nsit is a bastardized version from the clojure-extras git
06:09clp8i have to go, but I will be back in 50 minutes to bug this channel some more :) thanks for the help guy
06:10clp8*guys
06:10Lau_of_DKnp
07:11clp8H4ns: that does not help me. It seems that java simply doesn't find the clojure.lang.repl class
07:17hoeckclp8: have you looked at the commandline params of the running jvm?
07:17clp8no, I haven't
07:17clp8how should I do that?
07:18hoeckon which os?
07:19clp8solaris
07:20hoeckthen use ps or top
07:23clp8hmmm
07:26hoeckregarding slime, it worked for me by only setting things for swank-clojure using m-x customize-group swank-clojure
07:26clp8slime has always worked for me
07:27clp8it's just getting clojure to load right
07:27clp8i don't suppose you know what file clojure.lang.repl is defined it?
07:27clp8*in
07:28hoeckyeah, sorry, i meant setting swank-clojure classpaths
07:29hoeckRepl.java :)
07:32hoeckclp8: does evaling (swank-clojure-cmd) in emacs-scratch-buffer return correct classpaths?
07:36clp8hoeck: evaling this worked: (setq swank-clojure-extra-classpaths (list "/aber/clp8/Desktop/clojure/src/jvm/clojure/lang/"))
07:37clp8but it prints a bunch of exceptions and slime doesn't work right. this makes me think that classpaths are not set, or, at least, not set right
07:42hoeckclp8: evaling (swank-clojure-cmd) should return something like ("java" "-cp" "/..../clojure.jar:more-classpaths" "clojure.lang.Repl")
07:44clp8the only extra classpath is the one for REPL that I added myself
07:44clp8are classpaths recursive? could I just add the top of the clojure tree?
07:45H4nsclp8: no. you need to specify all the jars on the command line. very new jre's accept wildcards, too.
07:46clp8I see. This isn't mentioned in any of the wiki guides, though
07:46clp8i'll do that now
07:48clp8...I only have one jarfile; clojure.jar
07:51clp8i think I might try building clojure from source, see if that improves the situation
07:51clp8I can't understand why java isn't looking in clojure.jar for the repl class
07:59clp8if I give the directory with clojure.jar in it, slime seems to work...sort of
08:31AWizzArdMoin
08:41duck1123is Stuart Halloway around? (or does anyone know what his nick is?)
09:05arbschtcool :)
09:06AWizzArdMay I get an autograph? :-)
09:43RadioApeShotHi #clojure
09:44RadioApeShotI am trying to get the latest version of swank-clojure running under my emacs
09:44AWizzArdyeah, I had that too some days ago ;-)
09:44RadioApeShotBut seem to be stuck
09:44RadioApeShot(add-to-list 'load-path "/path/to/swank-clojure")
09:44RadioApeShot (require 'swank-clojure-autoload)
09:45RadioApeShotMy emacs chokes on (require 'swank-clojure-autoload) saying I need to set the path to the clojure jar
09:45RadioApeShotBut the readme indicates I do this after require-ing swank-clojure-autoload
09:46duck1123I have mine set before, if that helps
09:48H4nsRadioApeShot: http://paste.lisp.org/display/68861 works for me
09:49RadioApeShotthanks
09:51lisppaste8AWizzArd pasted "Emacs config for Clojure+Slime" at http://paste.lisp.org/display/68867
10:00AWizzArdRadioApeShot: any progress?
10:12AWizzArdhmm, was the svn restructured a bit?
10:13ChouserI don't think so. What are you seeing?
10:14AWizzArdChouser: I was probably mistaken, nevermind
10:15RadioApeShotSorry
10:16RadioApeShotFriend came in with boy troubles
10:16RadioApeShotSo if I setq the clojure location before require-ing M-X Slime does bring up a clojure
10:16RadioApeShotBut I get an error about *e
10:17RadioApeShotAnd a lot of Java stuff.
10:17RadioApeShotAnd then the REPL does show up
10:17RadioApeShotBut I can't send s-expr to it.
10:18RadioApeShotShould I set up a lisp-paste or something with the backtrace?
10:18duck1123is that old swank-clojure or old clojure itself
10:18duck1123someone had this problem the other day
10:18duck1123I would recommend getting the latest of everything
10:19AWizzArdRadioApeShot: what version von Emacs do you have and what version of Java? Did you start Clojure with M-x clojure ?
10:21AWizzArdAs you can see, there was a function (clojure) defined which will call (slime 'clojure) and not try to run slime with Common Lisp.
10:23RadioApeShotEmacs 23, Java 1.6 (b11).
10:24RadioApeShotAnd there does not appear to be an interactive function called clojure on my system.
10:24RadioApeShotIt may be an old clojure.
10:24RadioApeShotIt is the latest binary release.
10:24duck1123I'm pretty sure that was the fix
10:24RadioApeShotShould I try to build clojure from something more recent
10:24RadioApeShotOk
10:24RadioApeShotI have the source here already
10:24duck1123*e was recently added
10:25duck1123this chan isn't publicly logged, is it?
10:25arbschtit is
10:25arbschtRadioApeShot: get svn clojure
10:25arbschtduck1123: http://clojure-log.n01se.net/
10:27AWizzArdI also had the problem with *e
10:27AWizzArdbecause I downloaded the "binary Clojure" from the website first, and didn't compile my own via ant from svn
11:05AWizzArdHow can I call java.lang.String.hashCode()?
11:06sohailisn't it (. java.lang.String hashCode)?
11:06wwmorgan_AWizzard: (.hashCode "foo") ?
11:06AWizzArdwwmorgan_: yes.. but if I want to go the full path
11:07AWizzArdI want to learn how to do it.. for example: System.out.println() ==> (.println System/out "foo")
11:07wwmorgan_You mean make sure you're calling String hashcode instead of Object hashCode?
11:08AWizzArdfrom that I would say: the method I want to call comes first, and then the rest of the path, delimited by slashes and not dots, so that would give me: (.hashCode java/lang/String "foo")
11:08AWizzArdbut this does not work
11:09wwmorgan_you could also do (. "foo" hashCode)
11:10AWizzArdBut how can I know which hashCode method I am calling?
11:10RadioApeShotAWizzArd: Newest Clojure fixed it.
11:10RadioApeShotThanks
11:10AWizzArdRadioApeShot: yes right, I had the same... just have a freshly compiled clojure.ant. Enjoy hacking! :-)
11:11wwmorgan_AWizzArd: Since clojure uses reflection to find the method to call at run-time, I think you'll get the closest fit if you don't specify which hashCode to call, ie the String hashCode
11:11wwmorgan_you could also use a type tag to specify which hashCode to call at compile-time
11:12AWizzArdSo you think there is no way to enforce calling a specific method?
11:12wwmorgan_(let [string "foo"] (.hashCode #^String string))
11:13wwmorgan_alternatively (let [string "foo"] (.hashCode #^java.lang.String string))
11:20ChouserAWizzArd: in the .println example, System/out is not part of the "path" to the method, it's an instance of java.io.PrintStream
11:22AWizzArdi think these paths are called packages in Java?
11:22Chouserjava and java.io are packages; java.io.PrintStream is a class.
11:24AWizzArdso how can I reference the three different categories of a "path"? I need sometimes the dot, sometimes the slash, telling what the package is, what the Object, and what the method is.
11:25AWizzArdsometimes it is with a dot in the front, sometimes it is dotMethodName in the front (no space between dot and the method)
11:27AWizzArdbbl
11:27Chouserthe full name of a class includes the package path to it. In Java and Clojure these are separated with a dot.
11:29Chouserto refer to a static field (like "out" in System) or method, use a slash (since in this case the class is just acting like a namespace)
11:30ChouserSystem/out or java.lang.System/out (or you can use the older syntax (. System out) or (. java.lang.System out))
11:32Chouserto refer to an instance field or method (like hashCode in String), use the leading dot and an instance (.hashCode "foo") (or you can use the older syntax (. "foo" hashCode))
11:34Chouserin this last case (using an instance), if the compiler doesn't know the type of the instance, Clojure will have to do some reflection at runtime.
11:35ChouserThis reflection may be too slow in some cases, so it can be helpful to give the compiler a type hint: (.hashCode #^String "foo") or (.hashCode #^java.lang.String "foo")
11:36Chousersorry, that example doesn't work because of the literal string. Try: (def x "foo") (.hashCode #^String x)
11:38alvin__in the case of the literal string you wouldn't need a hint?
11:39Chouseralvin__: I would guess not. Anyway, you're not allowed to provide one. :-)
11:39ChouserIn general you can find out if reflection will be done at runtime by doing: (set! *warn-on-reflection* true)
11:40ChouserIf you do that in the Repl and then (.hashCode x), you'll see a little warning that the hashCode method will have to be looked up at runtime.
11:44Chouserbut don't go crazy with the type hints -- code looks so much better without them, make sure you really need the speed improvement first.
11:57alvin__what's the best way to iterate through a java array? is (loop) the only option?
11:58wwmorgan_alvin_: you can call seq on a java array, and then all of clojure's iterative capabilities are avaiable to you
12:00alvin__O.O
12:05gnuvinceDoes anybody know if Rich's presentation and pannel at Lisp50 are going to be video-tapped?
12:07arbschtoopsla events are typically recorded
12:07arbschtthe talks, anyway
12:09gnuvincegreat
12:10albinolisp50 is separate from oopsla, no?
12:10alvin__is there anybody here who's worked with JMX?
12:11gnuvincealvin__: they show it in the OOPSLA schedule
12:13alvin__gnuvince: you mean albino :)
12:16alvin__bbl
12:42AWizzArdre
12:46AWizzArdChouser: thanks for the explanations
12:46Chouseryw
12:47gnuvinceWhat's the function (or method) to get the numerical value of a char?
12:47gnuvinceFor example, (ord \A) => 65
12:48wwmorgan_gnuvince: (int \A) => 65
12:48gnuvinceDuh... thanks wwmorgan_ :)
12:51AWizzArdWhat is preferrable? (.toString 123) or (format "%d" 123)?
12:52kotarakAWizzArd, why not (str 123)?
12:52AWizzArdgood, thx
12:56Lau_of_DKEvening gents
12:56arbschthi lau
12:56duck1123hey lau
12:56kotarakLau_of_DK, hi. Got a solution for euler-37
12:57Lau_of_DKThen post it on the wiki :)
12:57kotarakok.
12:57Lau_of_DKoh wait
12:57Lau_of_DKDid you succeed in removing strings ?
12:58Lau_of_DKkotarak?
12:58kotarakyes
12:58Lau_of_DKWow - I cant wait to see it
12:58Lau_of_DKCan you just post it below my solution with the note: Optimized to run without strings...or something like that :)
12:59kotarakI have it on a different machine. Will remake it from memory. But will take a minute....
12:59Lau_of_DKhehe
12:59Hundamit vergleichbar
12:59Hunwoopsy
13:03arbschtthe clojure-euler wiki navigation has become quite confusing
13:04Lau_of_DKarbscht, sorry about tht
13:04Lau_of_DKI moved all the single digit values into triple-digits, but I lack the rights to delete the original ones, so I need to get a hold o achim_p
13:04arbschtI see
13:04Lau_of_DKJust know that there are now duplicates, nothing has been removed, but it would be nice to have it start at 001 and end at 210
13:05arbschtwhat will we do in 15 years when project euler reaches 1000? :)
13:05Lau_of_DKMake a new wiki :)
13:05arbschtheh
13:08Lau_of_DKQuestion guys: On clj-me.blogspot.com cgrande wrote a routine called (defn find= ...), in it he declares a variable like this
13:08Lau_of_DK (let [ [s1 & etc]
13:08Lau_of_DKWhat does that syntax mean ?
13:09duck1123is that for destructuring?
13:09Chouserdestructures a seq, the first going into s1, the rest into etc
13:10Lau_of_DKso when the argument is a seq of seqs, then the first seq goes into s1, and the others into etc ?
13:10Chouser(let [[a & b] '(1 2 3)] {:a a :b b}) -> {:b (2 3), :a 1}
13:10ChouserLau_of_DK: sure
13:10sohaildoes clojure make it possible to load/save clojure compiled files?
13:11kotaraksohail, not yet, but in work
13:11Lau_of_DKChouser, thanks alot! Where do you guys pick up this stuff, have you got a secret book ?
13:11Chousersohail: there are no clojure compiled files.
13:11sohailthen what does the compiler do?
13:11sohailI meant compiled representation actually :-)
13:12sohailkotarak, how does a large clojure (doesn't exist yet?) project handle compiling everything on startup then?
13:13kotaraksohail, it does so on startup, I suppose.
13:13kotaraklisppaste8, url
13:13lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
13:13ChouserLau_of_DK: sorry, friend, it's all on the web site: http://clojure.org/special_forms
13:13ChouserLau_of_DK: click on "let"
13:13sohailkotarak, sounds slo
13:13sohailw
13:13Chousersohail: the compiler is relatively simple, so it runs pretty fast.
13:14AWizzArdis there a way to know how many threads are running in parallel in a running Clojure program?
13:14Chousersohail: pre-compiled to .class files is coming.
13:14sohailChouser, great :-)
13:15Chouserusually called "AOT compilation", just so you know what people are talking about when you see it.
13:15AWizzArdsohail: did you see my example from yesterday? About the generality of multimethods? http://paste.lisp.org/display/68846
13:15waltersAWizzArd: there are some decent free tools around the JVM - VisualVM is one
13:15AWizzArdwalters: danke
13:15waltersAWizzArd: but there are plenty others
13:15sohailAWizzArd, I did
13:16sohailthanks for that
13:16AWizzArdso, in your dispatch method you can protect from bad number of args, and so on
13:16sohailI still think that there will eventually be a straight-jacket on top of clojure
13:16sohailyep
13:16sohailbut I think this should be automatic
13:16AWizzArdit already is there, at runtime
13:18sohailyeah but if you're lucky, all you'll get is an exception which tells you nothing about what really happened
13:19AWizzArdsohail: then write something like the Erlang Dialyzer for Clojure
13:20AWizzArdyou can prove tons of stuff about code before running it
13:20lisppaste8kotarak pasted "euler-37 and prime?" at http://paste.lisp.org/display/68876
13:22Lau_of_DKWELL done kotarak
13:22Lau_of_DKThats a fantastic (trunc )
13:22gnuvincelet doesn't allow the definition of recursive bindings?
13:23kotarakLau_of_DK, it has to go only one way. The other way is handled in candidate generation
13:23Lau_of_DKDouble your gun, double your fun,... and speed
13:24sohailAWizzArd, still not the same thing
13:24sohailbut again, I'm probably wrong in wanting what I want
13:24AWizzArdnot the same as?
13:24sohailsame thing as what I want
13:24AWizzArdwhat do you want?
13:25sohailan ABCL that doesn't cause java 1.6 to segfault
13:25sohail;-)
13:25kotarakgnuvince, no, there is no letrec
13:25arbschtgnuvince: let is not letrec. however, you can label functions like so (fn foo [] ... (foo))
13:26gnuvinceI was trying the infinite fibonacci sequence thing from Haskell. It works with def, but not with let.
13:26dmilessohail, java -version
13:29sohaildmiles, I know, I know
13:29sohailbut this app will be run on all sorts of versions so I need to make sure it works on all 1.6
13:30sohail(it's .06 btw)
13:30dmilesIcedTea6 1.3 Runtime Environment (build 1.6.0_0-b12) OpenJDK 64-Bit Server VM (build 1.6.0_0-b12, mixed mode)
13:30dmilesworks pretty good
13:30sohailunfortunately, I won't control what it runs under
13:30dmilesoh true
13:31sohailI can't bring myself to write Java
13:31dmileswhenever my jvm gets buggy i just reclock my computer or increase airflow
13:31dmilesthat does almost always solve it
13:31sohail:-/
13:32dmilesi dunno, seems like this new one lets me clock higher meaning its probly slower jvm
13:39AWizzArdDoes the jvm offer extrem lightweight threads? Some that it manages the jvm itself? Something lightweight as Erlang or Haskell threads?
13:41AWizzArdit would be nice if only on physically available cores/cpus native threads were running, and the rest would be lightweight threads which can be initialized 1000x faster and consume much less memory
13:47waltersAWizzArd: you can change the stack size I believe; but basically like all optimization problems don't worry about it unless it truly is a problem for your app that shows up in measurements
13:48AWizzArdI am about to port my common lisp Genetic Programming system to Clojure. I will have ten thousands of programs that need to be run to test their fitness.
13:48AWizzArdIt makes no sense if 10k threads get started on just 2 cpu cores.
13:49waltersi think using a thread pool gets you pretty far
13:49AWizzArdAs I see it, Clojure automatically parallelizes stuff
13:49AWizzArdin this one video Rich showed an example of ants running around
13:50duck1123watching that video right now
13:50tWipfor some value of automatically
13:50duck1123I though he said though that clojure does NOT parallelize automatically
13:50AWizzArdhe had no threadpool there and no real management for concurrency (besides for checking if space is already taken by some other and, so that not two of these beasts can be on the same field on the "chessboard")
14:05Chouseryou can have thousands of agents with actions scheduled on them, and they will queue up for available CPUs.
14:06AWizzArdChouser: I will have to read more about that. Still didn't look into concurrency stuff yet (refs/agents).
14:57lisppaste8karmazilla pasted "wonder if this can be optimized" at http://paste.lisp.org/display/68886
15:01wwmorgan_karmazilla: optimized for time/space or refactored to be more clojure-y?
15:01karmazillatime
15:01karmazillatakes 8 seconds to run on my machine
15:02wwmorgan_http://en.wikipedia.org/wiki/Sieve_of_Atkin
16:06Lau_of_DKDoes clojure provide some way of getting the actual digits?
16:06Lau_of_DKuser=> (reduce + (map #(Math/pow % %) (range 1 11)))
16:06Lau_of_DK1.0405071317E10
16:08arbschtLau_of_DK: what are "the actual digits"?
16:09Lau_of_DKuser=> (reduce + (map #(int (Math/pow % %)) (range 1 11)))
16:09Lau_of_DK2552554964
16:09Lau_of_DKsomething like that
16:09Lau_of_DKa pure int result
16:10arbschtMath/pow returns a double, so that would seem to be the only way
16:11wwmorgan_(str (BigDecimal. (reduce + (map #(Math/pow % %) (range 1 11))))) => "10405071317"
16:12Lau_of_DKBigDecimal - Thats the stuff
16:12Lau_of_DKThanks wwmorgan_
16:14arbschtor, (reduce + (map #(.pow (bigint %) %) (range 1 11)))
16:16alvin__i need to go through a seq and add items to a hash map depending on the current value from the seq... what's the best way to code this kind of behaviour?
16:18gnuvincealvin__: loop/recur sounds like the obvious candidate
16:20alvin__gnuvince: ok, let me try it... i'll get back some time tomorrow :D
16:24aperottehello all, is there a way to import all of the classes in a package or a jar at once?
16:25aperotteor is that just wasteful and lazy on my part:-[
16:30cemerickaperotte: No, there's no built-in way to do that. It's a conscious design decision iirc
16:31gnuvinceDoes Clojure have a for-each function when you're not interested in the return value?
16:32wwmorgan_gnuvince: (doc doseq)
16:33gnuvinceCool, thanks.
16:34aperottecemerick: ok, thanks
16:43Chousergnuvince: if you're trying to accumulate data in a hash, say counting the occurences of each value in a seq, you may be able to use merge-with
16:45Chouseruser=> (apply merge-with + {} (for [i [:a :b :a :c :a :b]] {i 1}))
16:45Chouser{:c 1, :a 3, :b 2}
16:46Chouserif you don't need to handle hash key collisions, it's even easier with (into)
16:49scottjHow do you set *out* to the repl or stdout? I'm using compojure and I think it's changed *out*
16:52Chouserscottj: wrap (binding [*out* foo] ... ) around your expression
16:55scottjChouser: oh, I guess what I mean is, what is the value of foo for stdout/repl?
16:57Chouseroh! I don't know that. You could try System/out even though it doesn't give the same value that the REPL has by default for *out*
16:58wwmorgan_The default repl value for *out* is (java.io.OutputStreamWriter. System/out (java.nio.charset.Charset/forName "UTF-8"))
17:18Chousercan anyone think of a nice simple concrete example of objects that would have methods dispatching on different attributes?
17:19Chouserlike if you had a {:shape circle :radius 5}, you'd want an area method that dispatches on :shape
17:19ChouserBut if I want to demonstrate dispatching on something other than :shape, what would I add?
17:20Chouserthe only thing I've thought of so far is a fill pattern like :fill checkerboard :gridsize 1
17:20Chouserwhich seems kinda lame.
17:21Chousermaybe I should use cars instead of shapes, and have a MPG-estimate method dispatch on 4wd vs 2wd, and have longevity-estimate dispatch on model of vehicle.
17:22Chouserlame. *sigh*
17:24HunChouser: i used opcodes for a cpu simulator for this
17:24Huneach opcode gets 2 to 3 parameters in this ISA, each can be immediate, a register, an address or a indirect address
17:25Hundefining that with generic functions was reeeally easy (CLOS though). should suffice as an example if the listeners have any assembler experience
17:28Chouserone method per opcode?
17:28Huntrue
17:29Chouserbut don't they all dispatch on cpu type or something?
17:29Hunit was amazingly fast, only slightly slower than a hand-tuned table-based dispatch
17:29Hunno, it was a single experimental cpu. not much use for a type there
17:29Huntake the easiest one
17:29Chouserso what did they dispatch on?
17:29Hunmove
17:30Hunthat one gets 2 operands, source and destination
17:30Hunon the operands
17:30Hunso that i could take into account that i could do just about anything with varied costs, except memory=>memory which errors
17:30Hun(it was a pretty stupid design, taking bad things from x86)
17:31Chouserok, I think I understand. thanks!
17:32Hunthink in combinations of operands and you might find a lot of interesting uses for generic functions
17:51danlarkinIn university we had to write an assembler macro-expander in assembler... you're bringing back bad, bad memories with your opcode talk
17:52Huni did one in lisp because the team that should write the assembler took to long. was about 40 lines :)
17:54danlarkinI'm jealous
17:54danlarkinit was that class that made me decide low-level programming was not for me
17:55danlarkinalthough it was invaluable to learn it... poor kids these days with no foundation!
17:58danlarkin(it was only 2 years ago that I left school, so I'm speaking facetiously)
18:00Hunhehe
18:00Huni'm still in college. doing a HW-Design course this term, together with some compilers :)
18:10danlarkinHun: which college do you attend?
18:11Hununiversity of applied sciences augsburg
18:11Hungermany
18:11Huni'm in my seventh term now
18:17danlarkinI'm out, peace!
18:19scgilardiI see by the schedule that Rich's talk is starting right now
18:33achim_pamazing, look at cgrands take on subsets(-by-card) (http://clj-me.blogspot.com/, compared to http://paste.lisp.org/display/68832). still parsing it, mentally ...
22:26crathmanwhat is the integer divide function in clojure?
22:27Chouserquot
22:28crathmanchouser: thx
22:30nicknullis clojure fast?
22:30nicknullhow fast is it compared to java? to other lisps?
22:41Chousernicknull: with care, clojure can run as fast as Java
22:51nicknullwould it be suitable to write an application that uses fairly heavy numerical computing(image recognition)?
22:52Chousernicknull: I've not done it, but I think rhickey's hoping to use Clojure in heavy math apps like audio analysis.
22:53Chousertake a bit of care with your inner loops, take advantage of multiple cpus, and let us know how it goes. :-)
22:57nicknullcool
22:57nicknullhe works with audio analysis?
22:57nicknullis tomhickey his brother?
22:57gnuvince_Yes, he is.
22:57nicknullor they just occupate the same namespace?
22:57nicknullok
22:57gnuvince_And Rich seems to work with super fun stuff: election projection systems, finger printing analysis, audio analysis, broadcast automation systems, etc.
22:58gnuvince_I'm really jealous of the election projection thing.
22:58gnuvince_I'm Canadian, but I enjoy following American politics.
23:09Chousergnuvince_: wow, that's ... something. Most Americans don't even like following American politics.
23:11gnuvince_Chouser: I'm weird like that :)
23:11Chousergnuvince_: well I do like it, so I guess I can empathize. Never really tried to follow any other country's politics.
23:12gnuvince_Chouser: It's different when your neighbor is the biggest and most powerful country in the world.
23:13gnuvince_Plus, some things happening there are really interesting
23:13gnuvince_The very large difference between the SF liberal crowd and the Bible Belt conservative crowd
23:17Chousergnuvince_: indeed! And each completely at a loss to understand the other.
23:18nicknullgnuvince: now im jealous to that sthe sutff i wanna do. datamining, machine learning, signal analsyis etc
23:18gnuvince_Being a mostly liberal guy myself, I'm hoping to see you guys elect Obama ;)
23:19Chousergnuvince_: ah, well now we have a problem. :-)
23:19gnuvince_Chouser: McCain man?
23:20nicknulli also like to follow american politics. have quite the effec ton the rest of the world...
23:20Chouserhm, pretty off topic...
23:21nicknullMcWar
23:22nicknulltomhickey: is rich using matlab? is he using clojure and matlab together?
23:33crathmanI see lazy-cons.... is there a way to declare a function lazy?
23:34Chousernope, just return that lazy-cons.