#clojure logs

2008-11-28

00:13dlonki(dorun (for (for ...)))?
00:27danleidlonki: compare (def x (for [i (range 5)] (do (print i) i))) to (def x (dorun (for [i (range 5)] (do (print i) i)))), and (def x (doall ...
01:00dlonkii see
01:13dlonkianyone good with matlab? is its code fast enough ti use for real apps or is matlab only for use in prototyping?
02:29danlei
03:54Lau_of_DKYyoo :)
05:19AWizzArdMoin
05:24Lau_of_DKOla
07:20Lau_of_DKHey heey =)
07:29pdoubleyaLau_of_DK: hey
07:30pdoubleyawhere is the . macro defined in the clojure clj files
07:31lvijayi think . is a built-in
07:31lvijay.. is the macro
07:32lvijay. is defined in java
07:32pdoubleyalvijay: ah, ok
07:32pdoubleyawanted to see what it looked like :)
07:34lvijayif you're interested in its java implementation you should look at clojure.lang.Compiler
07:35pdoubleyais Compiler used just for AOT, or for the interpreter as well? (no class Interpreter)
07:36Lau_of_DK(doc .)
07:36clojurebotexcusez-moi
07:37pdoubleyaLau_of_DK: thx
07:38lvijayCompile has AOT
07:40lvijayi haven't looked into the AOT code yet
07:40lvijayI know that Compiler is used to parse the clojure forms because I was hacking on it yesterday
07:41pdoubleyalvijay: did it survive the hacking? :)
07:42lvijaythat's up to Rich and the others that decide upon Clojure's syntax
07:42lvijayi made a suggestion and submitted a patch. Rich decides if it goes thru :-)
07:43pdoubleyanice to see people working on it...
07:53lvijaynewbie question: how do I refer to a class that is not in the current namespace without importing it?
07:53lvijayuser=> java.util/Collection
07:53lvijayjava.lang.ClassNotFoundException: java.util (NO_SOURCE_FILE:0)
07:56Lau_of_DKlike that
07:57Lau_of_DK(java.util/Collection. x y z)
07:58Lau_of_DKuser> (javax.swing.JOptionPane/showMessageDialog nil "Its working")
07:58Lau_of_DKnil
07:58Lau_of_DK
08:02lvijayhere's my problem:
08:02lvijayuser=> (try (java.net/URL. "http://www.google.com/") (catch java.net/MalformedURLException e (println e)))
08:02lvijayjava.lang.IllegalArgumentException: Unable to resolve classname: java.net/MalformedURLException (NO_SOURCE_FILE:2)
08:04hoecklvijay: "/" is for static member and method access, and for accessing stuff in namespaces
08:04Lau_of_DKjava.net does not exist
08:05lvijayok
08:05hoeckjava.net is a package, not a class
08:06hoeckyou probably want (java.net.URL. "http://...")
08:06Lau_of_DKexactly hoeck :)
08:06Lau_of_DKYou literally took the words out of my ERC :)
08:06lvijayah
08:07hoecklvijay: and java.net.MalformedURLException
08:07lvijayI mixed up static references and package references
08:07lvijaythe above worked
08:07hoeckLau_of_DK: you need better auto-completion then :)
08:08lvijaythanks hoeck and Lau_of_DK
08:10Lau_of_DKnps
08:10Lau_of_DKhoeck: Ive got dabbrav-expand, what are you using? :)
08:11hoeckcurrently mibbit, but i love dabbrev-expand too
08:14Lau_of_DKk, never heard of mibbit
08:15hoeckhttp://www.mibbit.com/ ajax irc client, very useful at work :)
08:17lvijayhoeck: that's useful. i'm currently using chatzilla. i'm new to clojure and IRC
08:18Lau_of_DKhoeck: okay, but you realize that dabbrev-expand is not an irc client right? :)
08:18hoeckso was I'am about 3 months ago, i noticed mibbit in someones quit message
08:19mibbit_testuuuh, so pretty
08:19mibbit_test:)
08:19hoeckLau_of_DK: yeah, its not capable of interpreting elisp, so no chance to dabbrev-expand something here :)
08:19Lau_of_DKlvijay: If you code in emacs, chat in emacs
08:20lvijayi code in emacs
08:20lvijaybut is erc setup easy in emacsw32?
08:20Lau_of_DK:) then you know what to do
08:20Lau_of_DKdunno, probably like linux, emacs is emacs right?
08:20pdoubleyanoobee question: learning clojure, is there a rule of thumb for when I don't need parens? e.g. (.substring "hello" 1 5) works, don't need parens around 1 5 altho i thought i would...
08:20hoeckLau_of_DK: but (at least my) emacs hangs when erc looses the irc connection
08:21Lau_of_DKhoeck: Mine too, so the trick is not to loose the connection :)
08:21Lau_of_DKpdoubleya: () = evaluation
08:21pdoubleyaLau_of_DK: hmm ok, so it doesn't mean "a list of ..."
08:21Lau_of_DKuser> (def f (fn [x] (+ x 2)))
08:21Lau_of_DK#'user/f
08:21Lau_of_DKuser> f
08:21Lau_of_DK#<user$f__1305 user$f__1305@2b2cf8>
08:21Lau_of_DKuser> (f 2)
08:22Lau_of_DK4
08:22Lau_of_DK
08:22lvijaypdoubleya: do you know python?
08:22pdoubleyalvijay: no
08:23lvijayok
08:23Lau_of_DKlvijay: Its not allowed to speak about Python in the presence of intelligent people, please respect the universal law
08:23lvijay:-)
08:24pdoubleyaLau_of_DK: thx
08:24lvijayLau_of_DK: i guess that explains why i didn't get that memo. too busy py***ning
08:28jdzhello people!
08:30hoeckjdz: hello!
08:32jdzi assume the compilation stuff is supposed to be working?
08:32jdzi am having troubles with getting the example to work...
08:33hoeckjdz: do you mean :genclass?
08:34Lau_of_DKCatch all ya'll later
08:34lisppaste8jdz pasted "compilation problems" at http://paste.lisp.org/display/71165
08:46hoeckjdz: have you set your classpath to include "./classes" ?
08:47hoeckjdz: looks like foo.clj gets compiled successfully but then clojure can't load the generated .class file
08:48hoeckjdz: i get exactly the same error as you when ommitting the -cp ./classes at startup
08:50jdzhoeck: hmm, good point.
08:50jdzwhich means clojure is trying to load the class as well?
08:51jdz*classes
08:51jdzcompiled files in short :)
08:51hoeckyes, it seems so, compile -> load .class
08:53jdzhmm, now i get java.lang.ExceptionInInitializerError
08:53jdzhoeck: compilation works for you?
08:53jdzif yes i'll bang at it until it works for me, too :)
08:54hoeckyes, it works here
08:59jdzyay, it works
08:59jdzi think the problem was with "classes" directory not existing before starting clojure
09:06jdzone question: what does it mean if the function name starts with a dash (like -main)?
09:07hoeckjdz: its for use with :genclass, specifies the method to implement in this function
09:08hoeckand "main" or "-main" is for a static public main method in the generated namespace class
09:08jdzoh, found documentation in gen-class
09:09jdzhoeck: "main" without the dash won't work, will it?
09:09hoeckcompilation docs are pretty up to date now, you may want to read there too: http://clojure.org/compilation
09:10jdzyes, i think i will have to read it from start to end (i just now realized that the dash prefix is explained there, too)
09:10hoeckjdz: it has to be -main now
09:11jdzhoeck: thanks for help!
09:11hoeckjdz: np
11:29freddy_dhello
11:30freddy_danyone here?
11:31freddy_dI'm trying to figure out how to generate a Java class stub from Clojure to do the bridge, and having some trouble
11:34blackdogfreddy_d, the only trouble i had was not having the classes directory in the classpath
11:34freddy_dblackdog: any chance you could point me to some docs?
11:35blackdogrich did put new docs on the site a couple of days ago
11:35blackdogothre than that i worked from this http://paste.lisp.org/display/70665
11:35freddy_dbasically I want to generate a.b.c.MyBean, with one method that returns MyClass
11:36blackdogso you want a a.b.c.MyBean namespace in clojure then
11:37freddy_dyes, I want to implement that one method in clojure
11:37freddy_dbut I want the Java framework to "see" it from Java bytecode
11:38freddy_d(hopefully I'm making some sense)
11:38blackdogyes using (ns (:genclass///00 is the way to go then
11:38blackdogonce you've defined your class in a clojure ns
11:39blackdogyou compile it with (compile a.b.c.MyBean)
11:39blackdoghttp://clojure.org/compilation
11:40freddy_dblackdog: thanks for the pointers, I'll try it out
11:41blackdogk
11:47freddy_dblackdog: apologies, I'm a total newbie. why, in your pasted example, is it e.g. (defn- -mymax and not (defn mymax ?
11:48blackdognot sure, i think it's just convention so that clojure can find the methods
11:48blackdogas opposed to an internal function
11:48blackdogrich did mention something about it on the group if you do a search
13:49danleib
14:16sdfsfis there no way to comment out a section in slime?
14:37grkzsdfsf: mark the region (go to start, C-space, go to end) and then M-;
14:39peter_12I'm curious how the Clojure folks approach the realm where OOP ORM's are commonly used for CRUD DB operations.
14:39peter_12I don't like ORM's like Rails' ActiveRecord. All that imperative stuff is a real headache.
14:40blackdogrhickey, is mostly down on ORM i believe
14:41peter_12"down on" = ?
14:41blackdoghe doesn't like it
14:41peter_12ahh
14:41peter_12the same for me
14:41blackdogso there would be nothing in core for it
14:41peter_12so what is the general approach to mutating a database?
14:41blackdoghave a look at clojure.contrin.sql
14:42blackdoghave a look at clojure.contrib.sql
14:42peter_12blackdog: ok. Thanks
14:42blackdogand you'll find resultset-seq in core.clj
14:42peter_12ahh that would be for SELECT
14:42peter_12That is the easy case
14:42peter_12DELETE is pretty easy too
14:43peter_12it is UPDATE and INSERT that are the tricky ones
14:43peter_12what should happen if failure etc
14:43blackdogthe c.c.sql takes care of that
14:43peter_12ok
14:43blackdogit has a (transaction)
14:43freddy_dblackdog: it's all good now, I managed to compile .clj to java, scripted it with Ant, and Stripes web framework picks it up. Very nice. :)
14:43blackdogcool!
14:44freddy_dthanks for your help
14:44freddy_dwould the Clojure community be interested in the Stripes/Clojure integration? or does Clojure already have its own web framework?
14:44blackdogyw, i usually defer to Chouser, rhickey and more knowedable folks but i think they're on holiday :P
14:45freddy_dhehe
14:45blackdogPupeno, has someting called compojure
14:45blackdogand AWizzard is working on rife integration
14:50peter_12blackdog: looking at clojure.contrib.sql, it seems like that is dealing with one level of abstraction lower than I am interested in. I'm interested in how clojure folks might handle validation of data before attempting a db insert
14:51peter_12and then if there are errors how to get that back to the controller and view, in a web app, for example
14:52blackdogwell i guess your app takes care of that, afaik there's no work on web stuff apart from compojure in terms of framework
14:53peter_12yeah, the app takes care of that, I was just wondering if there was a general attitude of how that should best be done. I don't like, and have never liked, how Rails does that.
14:54peter_12it isn't really a web-specific issue but that is my current application
14:54blackdogi'm not a lisper so I don't have a good idea of how they accomplish such stuff in CL etc
14:55peter_12I may ask the Common Lisp and Scheme folks what they do
15:03Pupenoblackdog: ?
15:03blackdoghello
15:09freddy_dblackdog: interesting. well, a Stripes/Clojure integration might still be useful.
15:11blackdoggiven the number of java web frameworks i'm sure we;ll see quite a few
15:11blackdogwrappers
15:12ryrunfrnfanyone good with common lisp? im translating pg ansi cl raytracer to clojure and wow clojure is so much cleaner and more elegant than cl.
15:12ryrunfrnfbut what is the eq od do in cl?
15:16gnuvinceryrunfrnf: eq od do?
15:16gnuvinceequivalent of do?
15:17gnuvinceryrunfrnf: look at loop/recur
15:55kotarakSay I have a gen-class: (ns foo.bar.Baz (:gen-class ...)). Can I refer to Baz directly in the source file?
16:26sdfsfwho is albert cordona?
16:30gnuvinceHow do I get the absolute value of a number?
16:31kotarakMath/abs maybe?
16:32gnuvinceBingo
16:32gnuvincethanks
16:32gnuvinceI was trying (.abs -3)
16:32kotarakgnuvince: that would be too easy. ;)
16:32Chouser(.abs -3M) works
17:01AWizzArdChouser: how can it work? Is it because nM is treated specifically by the reader and is some kind of postfix reader macro which translates into (new BigDecimal "n") ?
17:10sdfsfanyone use the Fiji/ImageJ package?
17:10sdfsfi want to write apps in clojrue as normal with it
17:10sdfsfis that possible?
17:20AWizzArdsdfsf: yes, Clojure is good to write normal and not so normal apps with it.
17:21AWizzArdFrom todays perspective Clojure has the potential to make it easier to write non-normal apps (namely those that make use of multiple cores in CPUs).
17:45ChouserAWizzArd: yep. (class -3M) -> java.math.BigDecimal
17:45ChouserBigDecimal has an 'abs' method.
17:51AWizzArdyes, this I understand
18:14ryrunfrnfwhy doesnt errors report the linenumberwhere the error is ?
18:14ryrunfrnfreally annoying
18:38AWizzArdbecause in Lisp programming is not string editing
18:39blackdogAWizzArd, did you have any luck with the interation
18:39AWizzArdyou are doing tree editing
18:39blackdogAWizzArd, did you have any luck with the integration
18:39AWizzArdblackdog: did not continue with it yet, but I will have a try tomorrow
18:39AWizzArdI will use your example and see how far I get with it
18:40blackdogi didnt try compiling it or anything, but it's close :P
18:43AWizzArdIf I use purely java code from within Clojure the resulting .class file should be more or less exactly the same as if I had compiled it from a .java source. The clojure.jar would not be needed in that case.
18:43ryrunfrnfjava.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol (NO_SOURCE_FILE:1)
18:43ryrunfrnfis it now allowed to do: let [x blah c x]?
18:44ryrunfrnfwhat exactly does clojure check when compiling?
18:44blackdogwell you;ll get lot's of class files not just one,
18:44AWizzArdBut if I use any Clojure functionality I will have to use the clojure.jar and find a way how to start Jetty so that it will know about that as well.
18:44blackdogyou get a class for each function and namespace
18:45blackdogand I'll be impressed if you can get away without clojure.jar
18:45blackdogdon't know
18:46hiredmanryrunfrnf: sounds like somewhere (seq ...) is getting called on something that seq doesn't know what to do with
18:46hiredmando you do an destructering?
18:51ryrunfrnfmeh, do youi guys have constant problems with getting stuck forever on dumb details?
18:52ryrunfrnflike so often it is some really small stupid detail that is right ther ein your face and yous till miss it
18:52ryrunfrnfi was using (defn f (params) instead of [params]...
18:53AislingI used to work as a tutor in the lab at my university and I saw lots of people doing things like that.
18:53AislingIt's not just you. Attention to detail helps but still you'll run into these errors.
18:54hiredmanwell
18:54AislingSyntax support in your editor can help with this.
18:55hiredmanbesides starting to write my lisp in ruby, and watching the mit sicp videos, I don't have previous lisp experience, so I don't automatically put parens everywhere :P
19:14ryrunfrnfjava.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.lang.Number (NO_SOURCE_FILE:2)
19:14ryrunfrnf(let [n (minroot (+ (sq xr) (sq yr) (sq zr)))]
19:19hiredmanclojurebot: cheesecake is delicious.
19:19clojurebotRoger.
19:33ryrunfrnfwhy os destructuring slower than first/rest?
19:38gnuvince_ryrunfrnf: destructuring has more bells and whistles
19:38gnuvince_> (let [[x y & z :as all] [1 2 3 4]] [x y z all])
19:38gnuvince_[1 2 (3 4) [1 2 3 4]]
19:44ryrunfrnfhmm when doign a raytracer
19:44ryrunfrnfthat must be perfect for multimethods right?
19:44ryrunfrnfnow i seee their advantage
19:44ryrunfrnfhave amethod intersect
19:44ryrunfrnfand specialize on the thing its calle don
19:51ryrunfrnfgod clojure is sooooo much cleaner than common lisp
19:53gnuvince_:)
20:29ryrunfrnfis it impossible to set swank/slime-intendation to 4 chars always?
20:39ryrunfrnfjava.lang.IllegalArgumentException: Wrong number of args passed to keyword: :shape (NO_SOURCE_FILE:0)
20:42ryrunfrnf(intersect sph [10 20 30] 30 40 50)
20:42ryrunfrnf(defmethod intersect :Sphere [sphere point xr yr zr]
20:42ryrunfrnf(defn sphere-intersect [sphere point xr yr zr]
20:42ryrunfrnfwtf?
20:43hiredmanryrunfrnf: all the args to a multimethod get passed to the dispatch function
20:43hiredmanso what happens there is (:Sphere sphere poit xr yr xr)
20:43hiredmanwhich, uh, no?
20:44hiredmanwait
20:44hiredmanthe is defmethod
20:44hiredmannot defmulti
20:45ryrunfrnfso i want to refer to the sphere itself, how do i?
20:46ryrunfrnf(defmethod area :Rect [r]
20:46ryrunfrnf (* (:wd r) (:ht r)))
20:46ryrunfrnfhes assing the rect itself
20:46hiredmanwhat does your defmulti look like?
20:47ryrunfrnf(defmulti intersect :shape)
20:48lisppaste8andjnsd pasted "defmulti" at http://paste.lisp.org/display/71202
20:51ryrunfrnf(defmethod intersect :Sphere [sphere a]
20:51ryrunfrnf (+ (:x sphere) a))
20:51ryrunfrnf works
20:52hiredmanso
20:52hiredmanyeah
20:53hiredmanyou are using a keyword as a dispatch function
20:53hiredmanbut that only works if you have one arg
20:53ryrunfrnfisnt ricks example?
20:53hiredmanyeah it is
20:53hiredmanbut he only dispatches on one param
20:53ryrunfrnfok
20:54ryrunfrnfso how should i change it?
20:54ryrunfrnfhow do irefer to the sphere inside its defmethod? :Sphere?
20:55hiredmanis the first argument always going to be hash with a :Sphere keyword?
20:55ryrunfrnfit is going to be a :shape
20:55ryrunfrnfhash-map
20:55ryrunfrnfsphere, cube etc
20:55ryrunfrnfit is for a raytracer
20:56hiredman(doc defstruct)
20:56clojurebotSame as (def name (create-struct keys...)); arglists ([name & keys])
20:56hiredmanbtw
20:56ryrunfrnfyes
20:56ryrunfrnfbut isnt this pretty much was multimethods are for?
20:56ryrunfrnfhvaing an intersect functiona nd dispathicng on the type
20:56ryrunfrnfof :shape?
20:57ryrunfrnf(defmethod intersect :Sphere [a]
20:57ryrunfrnf (+ (:x :Sphere) a))
20:57hiredmanso replace :shape in the defmulti with (fn [& x] (:shape (first x)))
20:57ryrunfrnfdoesnt work
20:57ryrunfrnfi dont get how to use them then
20:57hiredmanryrunfrnf: you don't seem to understand how dispatch functions work
20:57ryrunfrnfcorrect
20:58hiredmanthat is what multimethods are for, you just are passing more then one arg, but using a dispatch function that only takes one arg
20:58hiredmankeywords in clojure are functions of maps
20:58ryrunfrnfwhich is the dispathc function? defmulti?
20:58hiredmanryrunfrnf: you are using :shape as a dispatch function
20:58hiredmanthe keyword :shape
20:59ryrunfrnfyes
20:59ryrunfrnfwhat should i use?
20:59AWizzArdryrunfrnf: have a look at this examplefor the generality of multimethods: http://paste.lisp.org/display/68846
20:59hiredmana function that can take as many args as you pass
21:00hiredmanthe dispatch function needs to have the same arity as the method it dispatches to
21:00hiredmanor something like that
21:01hiredmana keyword has an arity of 1
21:01hiredmanyour method as an arity of more then 1
21:01hiredman*boom*
21:06ryrunfrnfthen i dont get what defmulti is for
21:06hiredmanthen don't use it
21:08hiredmanclojurebot: where are you?
21:08clojurebothttp://gist.github.com/27733
21:08hiredmanI use multimethods there
21:09AWizzArdryrunfrnf: defmulti takes a function
21:10AWizzArdwhen you say (defmulti foo my-fun) then my-fun gets called with the arguments that you gave to the call of foo
21:10AWizzArdif you say (foo 1 2 3) then Clojure will do (my-fun 1 2 3) for you
21:10AWizzArdmy-fun yields a result
21:11AWizzArdthen Clojure goes through all (defmethod foo)'s to see if one of them was done for this result
21:11AWizzArdlook at http://paste.lisp.org/display/68846
21:11AWizzArdthere is the call (foo 2 4)
21:11AWizzArdClojure secretly calls my fn from above
21:12AWizzArdThis fn takes either 1 arg or 2. As I gave two we need to look into that branch. It simply adds both numbers. So, (foo 2 4) will yield 6.
21:12AWizzArdThere exists a method foo for 6
21:13AWizzArdit gets both original arguments that were given, which were 2 and 4, and then passes them to the respective defmethod foo, which will multiply it's args
21:14AWizzArdClear now?
21:17ryrunfrnfno
21:18ryrunfrnf(classes-of int int) would be clear
21:18hiredman...
21:18ryrunfrnfi want to write a method intersect that takes an abstract shape and then dispatches to the correect shape-method
21:19AWizzArdwhat exactly is unclear in this example?
21:19hiredmanryrunfrnf: you are not going to be able to use a keyword as a dispatch, because your methods take more then one arg
21:20hiredmanyour best bet is to write a dispatch function that takes a variable number of args
21:20ryrunfrnfok i see
21:20AWizzArdyou can pass keywords to defmulti btw, because they are treated asfunctions
21:20hiredmanand uses the keyword to determine the :shape of the first argument
21:20AWizzArd(:my-key my-hashtable) ==> value for key
21:21jeremy___ok here's a newbie question: Here's a function my-sum that take a list of numbers and adds them together: (defn my-sum [x]
21:21jeremy___ (+ ~@x))
21:22hiredmanno
21:22jeremy___I get a ClassCastException when I run (my-sum `(1 2 3))
21:22hiredmanyeah
21:22hiredmanyou do
21:22hiredmanok
21:22jeremy___what am I doing wrong?
21:22hiredmana lot
21:22hiredman~ is unquote
21:22hiredmanmostly only used in macros
21:23AWizzArdyou can use ~ or ~@ only inside a backquote expression. Your (+ ~@x) is just a plain list
21:24AWizzArdtry instead (defn my-sum [x] `(+ ~@x))
21:24AWizzArdwhen you then (my-sum `(1 2 3)) ==> (+ 1 2 3)
21:24hiredman(doc apply)
21:24clojurebotApplies fn f to the argument list formed by prepending args to argseq.; arglists ([f args* argseq])
21:25jeremy___ah thanks it's starting to make sense
21:26AWizzArdThis is used to contstruct lists. Lists are data. Data is code. So the backquote and ~ as well as ~@ are very often used to create code.
21:26ryrunfrnfint he examples oyu posted both defmulti and defmethod contains information on implementation
21:26ryrunfrnfthey seem intertwined, thats what is confusing me
21:27AWizzArdNote however that you can write all programs without `, ~ and ~@. They are just shortcuts to plain function calls.
21:27AWizzArdryrunfrnf: You could have a (defn my-count [obj] (count obj)). And then you do (defmulti foo my-count).
21:28AWizzArdthis means that now all calls in the form of (foo ...) will in secretly be (my-count ...)
21:28ryrunfrnfso whats the point then?
21:28AWizzArdexample: (foo [1 2 3]) === (my-count [1 2 3]) ==> 3
21:28AWizzArdbut without defmethods it would be pointless
21:29AWizzArdnow we put in a method: (defmethod foo 3 [arg] (println "Hello"))
21:29ryrunfrnfI thought it worked like: declare a function name and what it takes. then declare a bunch of methods to call depending on the type
21:29AWizzArdWe said the call (foo [1 2 3]) ==> 3. There exists a (defmethod foo 3 ...)
21:30AWizzArdthe 3 in the (defmethod ..) is the one that was the result of the call to (foo [1 2 3]) which under the hood was really a call to my-count.
21:30AWizzArdWhat now happens is: put the original argument to foo (it was [1 2 3]) to this method
21:30arohnerwhat is the value of clojure.core.test?
21:30AWizzArdin this method it is called arg. We could have called it peter. The body of the method is (println "Hello")
21:31AWizzArdSo, (foo [1 2 3]) will print Hello
21:31arohnerit's slightly annoying that the test function expects failures to throw exceptions, yet it does nothing to catch & report them
21:31ryrunfrnfLike I thought it worked kind of liek inherited methods so i could do Obj.method and dont do inthe function If obj == type then blah else blahaba
21:31AWizzArdthat was the old school dispatching, as most languages do
21:31AWizzArdthis is the plain old type dispatch
21:31hiredmanyou can do that sort of thing
21:31AWizzArdbut in Clojure you are not bound to that
21:32AWizzArdThis is just a subset of what Clojures methods can do
21:32hiredmanyeah
21:32AWizzArdyou can dispatch for example on the number of elements in your argument, as we just did in the my-count example
21:32AWizzArdso no longer the type of the argument is important
21:32AWizzArdbut only how many elements it contains
21:33hiredmanyou can dispatch on just about anything
21:33hiredmanbecause the dispatcher is just another function
21:33AWizzArdadd a (defmethod foo 5 [ryrun] (reverse ryrun))
21:33AWizzArdnow you can say: (foo "Hello")
21:33AWizzArdand see what happens
21:34ryrunfrnfbut i want a funiton intersect so i should have one defmulti and sveral defmethods?
21:34hiredmanyes
21:34AWizzArdryrunfrnf: first you should understand in detail how it works. I think these examples were pretty obvious. If not, what exactly puzzles you?
21:34hiredmanbut you will need slightly more complicated dispatch function because you are using more then one argument
21:41AWizzArdryrunfrnf: in other languages a defmulti always looks basically the same. It is always something like: (defmulti name class)
21:42AWizzArdwhere (class obj) returns the type of that object
21:42AWizzArdyou can not simply replace class with your own function
21:43ryrunfrnfbut i dont get the 6 and the \H
21:43ryrunfrnfwtf are those names of the methods?
21:43ryrunfrnfif it is a 6 then do this?
21:44hiredmanthose are return values of the dispatch function
21:44hiredmanif the dispatch function returns 6 then do this method
21:45hiredmanwhich method is run is the result of what the dispatch function outputs
21:45AWizzArdryrunfrnf: okay, so your problem lies in the (fn) which is passed to defmulti
21:45AWizzArdin Clojure a function can have many parameter lists and bodies
21:46AWizzArdThe anon function that I passed to defmulti is such an example. It has the parameter collection and the body (first collection)
21:46AWizzArdIf this function is called with just one arg then this branch of the fn is used
21:47AWizzArdNow the fn has a second branch. One that has two parameters. If we pass in two args they will be added.
21:47ryrunfrnfbut why are they instances of a somehting instead foa type?
21:47ryrunfrnfif u make a general speci it should be diosptache dona type
21:47ryrunfrnfnot an isntanc eof the type
21:47AWizzArdtry (defn blah [x] (first x) [x y] (+ y x)) and call blah
21:48AWizzArdtry calling blah with one arg and with two
21:48hiredmanAWizzArd: I think you may be missing some parens
21:48AWizzArdoki right
21:49AWizzArdparens around [x] (first x) and also around the second guy
21:49hiredmanand the (first ...) is kind of pointless
21:49AWizzArdhiredman: why?
21:49hiredmanAWizzArd: well I guess it depends
21:49AWizzArd(blah (range 8 24))
21:49ryrunfrnfi thin i see a little now
21:49hiredmanI just assumed that since the [x y] form uses (+ )
21:49AWizzArdbut also (blah 10 5)
21:50hiredmananyway
21:50hiredmanwhatev
21:50AWizzArdryrunfrnf: when you understand blah just do in my example at http://paste.lisp.org/display/68846 a replacement of the defmulti. (defmulti foo blah)
21:51AWizzArdwhen we call (foo "Hello World") then foo gets only one arg. This means we go into the branch 1 of blah. This simply returns the first element of the collection.
21:52AWizzArdA string is a collecting. The first element of "Hello World" is the char \H
21:52hiredmanclojurebot: multimethods?
21:52clojurebotmultimethods seperate the 20% from the 80%
21:52AWizzArdHow can one teach the clojurebot new things?
21:53hiredmanclojurebot: a is b
21:53clojurebotc'est bon!
21:53hiredmanclojurebot: a?
21:53clojurebota is b
21:53hiredmanclojurebot: a is also c
21:54clojurebotAck. Ack.
21:54hiredmanclojurebot: a?
21:54clojurebota is c
21:54hiredmanclojurebot: a?
21:54clojurebota is b
21:55AWizzArdclojurebot: multimethods is also what separates the boy from the man.
21:55clojurebotc'est bon!
21:55rottcoddclojurebot: b?
21:55clojurebotexcusez-moi
21:56ryrunfrnfif i want to pass 5 args and dispatch on the ttype oa the first?
21:56ryrunfrnf(defmulti intersect (fn [a b c d e]
21:56ryrunfrnf (class a))) ?
21:57hiredmanuh
21:57hiredmanyou most likely don't want to use (class ...)
21:57hiredmanbut that is the general idea
21:57AWizzArdthis fn looks like a function that takes 5 arguments and returns the class of the first (while it ignores the other 4)
21:58jeremy___Here's another newbie question: Is there a way to force floating points when I run (/ 1 2 3 4) besides making one of the args a decimal (e.g 2.0)?
21:58hiredman(doc float)
21:58clojurebotCoerce to float; arglists ([x])
21:58AWizzArd(float (/ 1 2 3 4))
21:58hiredmanclojurebot: botsnack
21:58clojurebotthanks; that was delicious. (nom nom nom)
21:58AWizzArd(/ 1 2 3 4.0)
21:59jeremy___ah thanks I overlooked that on the API page.
21:59ryrunfrnfso if i want to dispatch on a type i should have a defstrcut not a function calle dpshere?
22:00AWizzArda defstruct is done for optimization,it will not create types
22:00AWizzArdstructs are simple hashtables
22:01AWizzArdbut they don't use up RAM for (some) of their keys
22:02ryrunfrnfoh my
22:02ryrunfrnfgod
22:02ryrunfrnfso i cant disptach on something called a sphere?
22:02hiredmanYOU CAN DISPATCH ON WHATEVER YOU WANT
22:02ryrunfrnfbecaus eif i d struct sphere it passes back a ahsh howthe f doi matcht hat?
22:02AWizzArdif you have a (defstruct person :name :street :age :telephone) and want to do it for New York, then you would have 18 million instances or something like that. If it were a hashtable then all 18 mio entries would consume space for the keys :name :street :age :telephone.
22:02hiredmanJUST WRITE THE RIGHT FUNCTION
22:03ryrunfrnfyes but since all :shapes will use hashmaps how do i differ them?
22:03hiredmanyou could even dispatch on time of day
22:03AWizzArdin a structure map only one time the keys need to be stored.
22:03AWizzArdryrunfrnf: you will manually have to put some key/value into the hashtable
22:03hiredmanryrunfrnf: you have a key {:shape :sphere}
22:03AWizzArd(defstruct person :name :age)
22:03hiredmanand you have a function that returns the value of that key of the hash
22:04AWizzArd(defn make-person [n a] (assoc (struct person n a) :type :person)
22:04AWizzArdnow each instance of your hashtable will also have the key/value pair {:type :person}
22:06SimonAdameitGood evening
22:07AWizzArdMoin Simon
22:13lisppaste8blarf pasted "im dying of frustration" at http://paste.lisp.org/display/71210
22:13hiredmanman, I wonder who blarf is
22:13hiredmanok
22:14hiredmanNO
22:14hiredmanno no
22:14hiredmanno
22:14hiredmanno
22:14albinothat's a lot of 'no's
22:14hiredmansee, here you have one thing you are passing, the hash
22:14hiredmanso your dispatch function should take one value
22:15hiredmanI think you will be better off if you have your dispatch function take a variable number of args
22:16ryrunfrnfbut it takes a sphere a point and 3 coordinates
22:17hiredmanryal all of which are in the hash
22:17hiredmanthe hash is one "thing"
22:17gnuvince_Does clojure have a divmod function?
22:17hiredmanobject, datastructure, thing
22:18hiredman(doc rem)
22:18clojurebotremainder of dividing numerator by denominator.; arglists ([num div])
22:18ryrunfrnfbut which is thet dispatch function? defmethods?
22:18hiredmanno
22:18SimonAdameitUsing swank-clojure I get the following error: "Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/Repl"
22:18gnuvince_hiredman: that's only the second part :)
22:18hiredmanthe dispatch function is the function you pass to defmulti
22:19hiredmangnuvince_: well I don't know what divmod is
22:19hiredmanso I guessed
22:19SimonAdameitAlot of people seem to have gotten that, but the tip to fully qualify the clojure jar path that I found in the google group did not work
22:19SimonAdameitAny Idea how to fix this?
22:19gnuvince_hiredman: (divmod 3 2) => (1 1)
22:20gnuvince_hiredman: basically, it'd be: (defn divmod [m n] [(quot m n) (rem m n)])
22:20hiredmanok
22:20AWizzArdSimonAdameit: do you use the newest versions?
22:21hiredmanclojurebot: emacs?
22:21clojurebotemacs is hard, lets go shopping!
22:21SimonAdameitAWizzArd: for slime, swank-clojure and clojure yes
22:21SimonAdameitand emacs 22
22:22AWizzArdI have the same, for me it works
22:22SimonAdameitcould you paste the relevant .emacs parts, maybe I could try yours
22:22AWizzArdoki
22:23ryrunfrnfbut isnt the defmethod that has a value of what the defmulti retuns called?
22:23ryrunfrnfdefmulti intersect retuns :shape a whc should be :Sphere
22:23ryrunfrnfthen defmethid intersect :Sphere is called?
22:24lisppaste8rte annotated #71210 with "multis" at http://paste.lisp.org/display/71210#1
22:24hiredmanthat should work
22:25hiredmanand could you use your own nick when you paste stuff?
22:26SimonAdameitAWizzArd: Yay, got it working to
22:27SimonAdameitIt actually was a "stupid" error in specifying the wrong path :)
22:27ryrunfrnfyes but it doesnt
22:28hiredmanwhat is the error
22:28lisppaste8AWizzArd pasted "Example emacs config for Clojure+slime" at http://paste.lisp.org/display/71211
22:28AWizzArdoki
22:28hiredmanryrunfrnf: paste the whole thing again
22:28hiredmanuh
22:28hiredmanyeah
22:28hiredmanyou are missing parens
22:29hiredmaninside the fn, you need (:shape a)
22:30ryrunfrnfwow so annoying
22:30ryrunfrnfnow it works
22:30ryrunfrnfhehe sorry guys
22:30AWizzArdI think you don't need these 5 args for defmultis dispatch fn
22:31AWizzArdtry (defmulti intersect :shape)
22:31hiredmanAWizzArd: ssh it's working, back away slowlyr
22:31AWizzArd*g*
22:31hiredmanAWizzArd: he passes more then one arg
22:31hiredmannot just the hash
22:31hiredmankeywords are functions of arity 1
22:31hiredmanso they blow up
22:31hiredmanwhich is how this whole thing started
22:32AWizzArdwow
22:32AWizzArdwell, you could need a calm-down-tea for tonight hire ;-)
22:32AWizzArdit was a moving theme
22:32hiredmanhuh
22:33Chouserkeywords can take 2 args (not found)
22:33hiredmanChouser: just noticed that
22:34hiredmanthe point is, he is passing to many args to dispatch via a keyword, so cargo culting the examples doesn't work
22:36sdfsfthe intersect function takes 5 args
22:37sdfsfa sphere a point and 3 coordinates
22:37sdfsfso i need to pass everala rgs aight?
22:38sdfsfi should do porn instead
22:46AWizzArdsdfsf: if this data is already inside the hashtable then you would only have to pass this one arg, namely the hashtable
23:19matzerohello is this working?
23:19matzeromicrophone check 1 check 2
23:20sdfsfanyone seen matzero lately? i never se him around here
23:21matzerolol
23:21matzerocool thanks for the ping back