#clojure log - Nov 28 2008

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

0:13 dlonki: (dorun (for (for ...)))?

0:27 danlei: dlonki: 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 ...

1:00 dlonki: i see

1:13 anyone good with matlab? is its code fast enough ti use for real apps or is matlab only for use in prototyping?

2:29 danlei:

3:54 Lau_of_DK: Yyoo :)

5:19 AWizzArd: Moin

5:24 Lau_of_DK: Ola

7:20 Hey heey =)

7:29 pdoubleya: Lau_of_DK: hey

7:30 where is the . macro defined in the clojure clj files

7:30 * pdoubleya is a neewbee

7:31 lvijay: i think . is a built-in

7:31 .. is the macro

7:32 . is defined in java

7:32 pdoubleya: lvijay: ah, ok

7:32 wanted to see what it looked like :)

7:34 lvijay: if you're interested in its java implementation you should look at clojure.lang.Compiler

7:35 pdoubleya: is Compiler used just for AOT, or for the interpreter as well? (no class Interpreter)

7:36 Lau_of_DK: (doc .)

7:36 clojurebot: excusez-moi

7:37 pdoubleya: Lau_of_DK: thx

7:38 lvijay: Compile has AOT

7:40 i haven't looked into the AOT code yet

7:40 I know that Compiler is used to parse the clojure forms because I was hacking on it yesterday

7:41 pdoubleya: lvijay: did it survive the hacking? :)

7:42 lvijay: that's up to Rich and the others that decide upon Clojure's syntax

7:42 i made a suggestion and submitted a patch. Rich decides if it goes thru :-)

7:43 pdoubleya: nice to see people working on it...

7:53 lvijay: newbie question: how do I refer to a class that is not in the current namespace without importing it?

7:53 user=> java.util/Collection

7:53 java.lang.ClassNotFoundException: java.util (NO_SOURCE_FILE:0)

7:56 Lau_of_DK: like that

7:57 (java.util/Collection. x y z)

7:58 user> (javax.swing.JOptionPane/showMessageDialog nil "Its working")

7:58 nil

7:58

8:02 lvijay: here's my problem:

8:02 user=> (try (java.net/URL. "http://www.google.com/") (catch java.net/MalformedURLException e (println e)))

8:02 java.lang.IllegalArgumentException: Unable to resolve classname: java.net/MalformedURLException (NO_SOURCE_FILE:2)

8:04 hoeck: lvijay: "/" is for static member and method access, and for accessing stuff in namespaces

8:04 Lau_of_DK: java.net does not exist

8:05 lvijay: ok

8:05 hoeck: java.net is a package, not a class

8:06 you probably want (java.net.URL. "http://...")

8:06 Lau_of_DK: exactly hoeck :)

8:06 You literally took the words out of my ERC :)

8:06 lvijay: ah

8:07 hoeck: lvijay: and java.net.MalformedURLException

8:07 lvijay: I mixed up static references and package references

8:07 the above worked

8:07 hoeck: Lau_of_DK: you need better auto-completion then :)

8:08 lvijay: thanks hoeck and Lau_of_DK

8:10 Lau_of_DK: nps

8:10 hoeck: Ive got dabbrav-expand, what are you using? :)

8:11 hoeck: currently mibbit, but i love dabbrev-expand too

8:14 Lau_of_DK: k, never heard of mibbit

8:15 hoeck: http://www.mibbit.com/ ajax irc client, very useful at work :)

8:17 lvijay: hoeck: that's useful. i'm currently using chatzilla. i'm new to clojure and IRC

8:18 Lau_of_DK: hoeck: okay, but you realize that dabbrev-expand is not an irc client right? :)

8:18 hoeck: so was I'am about 3 months ago, i noticed mibbit in someones quit message

8:19 mibbit_test: uuuh, so pretty

8:19 :)

8:19 hoeck: Lau_of_DK: yeah, its not capable of interpreting elisp, so no chance to dabbrev-expand something here :)

8:19 Lau_of_DK: lvijay: If you code in emacs, chat in emacs

8:20 lvijay: i code in emacs

8:20 but is erc setup easy in emacsw32?

8:20 Lau_of_DK: :) then you know what to do

8:20 dunno, probably like linux, emacs is emacs right?

8:20 pdoubleya: noobee 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...

8:20 hoeck: Lau_of_DK: but (at least my) emacs hangs when erc looses the irc connection

8:21 Lau_of_DK: hoeck: Mine too, so the trick is not to loose the connection :)

8:21 pdoubleya: () = evaluation

8:21 pdoubleya: Lau_of_DK: hmm ok, so it doesn't mean "a list of ..."

8:21 Lau_of_DK: user> (def f (fn [x] (+ x 2)))

8:21 #'user/f

8:21 user> f

8:21 #<user$f__1305 user$f__1305@2b2cf8>

8:21 user> (f 2)

8:22 4

8:22

8:22 lvijay: pdoubleya: do you know python?

8:22 pdoubleya: lvijay: no

8:23 lvijay: ok

8:23 Lau_of_DK: lvijay: Its not allowed to speak about Python in the presence of intelligent people, please respect the universal law

8:23 lvijay: :-)

8:24 pdoubleya: Lau_of_DK: thx

8:24 lvijay: Lau_of_DK: i guess that explains why i didn't get that memo. too busy py***ning

8:28 jdz: hello people!

8:30 hoeck: jdz: hello!

8:32 jdz: i assume the compilation stuff is supposed to be working?

8:32 i am having troubles with getting the example to work...

8:33 hoeck: jdz: do you mean :genclass?

8:34 Lau_of_DK: Catch all ya'll later

8:34 lisppaste8: jdz pasted "compilation problems" at http://paste.lisp.org/display/71165

8:46 hoeck: jdz: have you set your classpath to include "./classes" ?

8:47 jdz: looks like foo.clj gets compiled successfully but then clojure can't load the generated .class file

8:48 jdz: i get exactly the same error as you when ommitting the -cp ./classes at startup

8:50 jdz: hoeck: hmm, good point.

8:50 which means clojure is trying to load the class as well?

8:51 *classes

8:51 compiled files in short :)

8:51 hoeck: yes, it seems so, compile -> load .class

8:53 jdz: hmm, now i get java.lang.ExceptionInInitializerError

8:53 hoeck: compilation works for you?

8:53 if yes i'll bang at it until it works for me, too :)

8:54 hoeck: yes, it works here

8:59 jdz: yay, it works

8:59 i think the problem was with "classes" directory not existing before starting clojure

9:06 one question: what does it mean if the function name starts with a dash (like -main)?

9:07 hoeck: jdz: its for use with :genclass, specifies the method to implement in this function

9:08 and "main" or "-main" is for a static public main method in the generated namespace class

9:08 jdz: oh, found documentation in gen-class

9:09 hoeck: "main" without the dash won't work, will it?

9:09 hoeck: compilation docs are pretty up to date now, you may want to read there too: http://clojure.org/compilation

9:10 jdz: yes, i think i will have to read it from start to end (i just now realized that the dash prefix is explained there, too)

9:10 hoeck: jdz: it has to be -main now

9:11 jdz: hoeck: thanks for help!

9:11 hoeck: jdz: np

11:29 freddy_d: hello

11:30 anyone here?

11:31 I'm trying to figure out how to generate a Java class stub from Clojure to do the bridge, and having some trouble

11:34 blackdog: freddy_d, the only trouble i had was not having the classes directory in the classpath

11:34 freddy_d: blackdog: any chance you could point me to some docs?

11:35 blackdog: rich did put new docs on the site a couple of days ago

11:35 othre than that i worked from this http://paste.lisp.org/display/70665

11:35 freddy_d: basically I want to generate a.b.c.MyBean, with one method that returns MyClass

11:36 blackdog: so you want a a.b.c.MyBean namespace in clojure then

11:37 freddy_d: yes, I want to implement that one method in clojure

11:37 but I want the Java framework to "see" it from Java bytecode

11:38 (hopefully I'm making some sense)

11:38 blackdog: yes using (ns (:genclass///00 is the way to go then

11:38 once you've defined your class in a clojure ns

11:39 you compile it with (compile a.b.c.MyBean)

11:39 http://clojure.org/compilation

11:40 freddy_d: blackdog: thanks for the pointers, I'll try it out

11:41 blackdog: k

11:47 freddy_d: blackdog: apologies, I'm a total newbie. why, in your pasted example, is it e.g. (defn- -mymax and not (defn mymax ?

11:48 blackdog: not sure, i think it's just convention so that clojure can find the methods

11:48 as opposed to an internal function

11:48 rich did mention something about it on the group if you do a search

13:49 danlei: b

14:16 sdfsf: is there no way to comment out a section in slime?

14:37 grkz: sdfsf: mark the region (go to start, C-space, go to end) and then M-;

14:39 peter_12: I'm curious how the Clojure folks approach the realm where OOP ORM's are commonly used for CRUD DB operations.

14:39 I don't like ORM's like Rails' ActiveRecord. All that imperative stuff is a real headache.

14:40 blackdog: rhickey, is mostly down on ORM i believe

14:41 peter_12: "down on" = ?

14:41 blackdog: he doesn't like it

14:41 peter_12: ahh

14:41 the same for me

14:41 blackdog: so there would be nothing in core for it

14:41 peter_12: so what is the general approach to mutating a database?

14:41 blackdog: have a look at clojure.contrin.sql

14:42 have a look at clojure.contrib.sql

14:42 peter_12: blackdog: ok. Thanks

14:42 blackdog: and you'll find resultset-seq in core.clj

14:42 peter_12: ahh that would be for SELECT

14:42 That is the easy case

14:42 DELETE is pretty easy too

14:43 it is UPDATE and INSERT that are the tricky ones

14:43 what should happen if failure etc

14:43 blackdog: the c.c.sql takes care of that

14:43 peter_12: ok

14:43 blackdog: it has a (transaction)

14:43 freddy_d: blackdog: 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:43 blackdog: cool!

14:44 freddy_d: thanks for your help

14:44 would the Clojure community be interested in the Stripes/Clojure integration? or does Clojure already have its own web framework?

14:44 blackdog: yw, i usually defer to Chouser, rhickey and more knowedable folks but i think they're on holiday :P

14:45 freddy_d: hehe

14:45 blackdog: Pupeno, has someting called compojure

14:45 and AWizzard is working on rife integration

14:50 peter_12: blackdog: 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:51 and then if there are errors how to get that back to the controller and view, in a web app, for example

14:52 blackdog: well i guess your app takes care of that, afaik there's no work on web stuff apart from compojure in terms of framework

14:53 peter_12: yeah, 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:54 it isn't really a web-specific issue but that is my current application

14:54 blackdog: i'm not a lisper so I don't have a good idea of how they accomplish such stuff in CL etc

14:55 peter_12: I may ask the Common Lisp and Scheme folks what they do

15:03 Pupeno: blackdog: ?

15:03 blackdog: hello

15:09 freddy_d: blackdog: interesting. well, a Stripes/Clojure integration might still be useful.

15:11 blackdog: given the number of java web frameworks i'm sure we;ll see quite a few

15:11 wrappers

15:12 ryrunfrnf: anyone 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:12 but what is the eq od do in cl?

15:16 gnuvince: ryrunfrnf: eq od do?

15:16 equivalent of do?

15:17 ryrunfrnf: look at loop/recur

15:55 kotarak: Say I have a gen-class: (ns foo.bar.Baz (:gen-class ...)). Can I refer to Baz directly in the source file?

16:26 sdfsf: who is albert cordona?

16:30 gnuvince: How do I get the absolute value of a number?

16:31 kotarak: Math/abs maybe?

16:32 gnuvince: Bingo

16:32 thanks

16:32 I was trying (.abs -3)

16:32 kotarak: gnuvince: that would be too easy. ;)

16:32 Chouser: (.abs -3M) works

16:32 * kotarak also looked or abs some while ago

17:01 AWizzArd: Chouser: 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:10 sdfsf: anyone use the Fiji/ImageJ package?

17:10 i want to write apps in clojrue as normal with it

17:10 is that possible?

17:20 AWizzArd: sdfsf: yes, Clojure is good to write normal and not so normal apps with it.

17:21 From 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:45 Chouser: AWizzArd: yep. (class -3M) -> java.math.BigDecimal

17:45 BigDecimal has an 'abs' method.

17:51 AWizzArd: yes, this I understand

18:14 ryrunfrnf: why doesnt errors report the linenumberwhere the error is ?

18:14 really annoying

18:38 AWizzArd: because in Lisp programming is not string editing

18:39 blackdog: AWizzArd, did you have any luck with the interation

18:39 AWizzArd: you are doing tree editing

18:39 blackdog: AWizzArd, did you have any luck with the integration

18:39 AWizzArd: blackdog: did not continue with it yet, but I will have a try tomorrow

18:39 I will use your example and see how far I get with it

18:40 blackdog: i didnt try compiling it or anything, but it's close :P

18:43 AWizzArd: If 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:43 ryrunfrnf: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol (NO_SOURCE_FILE:1)

18:43 is it now allowed to do: let [x blah c x]?

18:44 what exactly does clojure check when compiling?

18:44 blackdog: well you;ll get lot's of class files not just one,

18:44 AWizzArd: But 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:44 blackdog: you get a class for each function and namespace

18:45 and I'll be impressed if you can get away without clojure.jar

18:45 don't know

18:46 hiredman: ryrunfrnf: sounds like somewhere (seq ...) is getting called on something that seq doesn't know what to do with

18:46 do you do an destructering?

18:51 ryrunfrnf: meh, do youi guys have constant problems with getting stuck forever on dumb details?

18:52 like so often it is some really small stupid detail that is right ther ein your face and yous till miss it

18:52 i was using (defn f (params) instead of [params]...

18:53 Aisling: I used to work as a tutor in the lab at my university and I saw lots of people doing things like that.

18:53 It's not just you. Attention to detail helps but still you'll run into these errors.

18:54 hiredman: well

18:54 Aisling: Syntax support in your editor can help with this.

18:55 hiredman: besides 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:14 ryrunfrnf: java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.lang.Number (NO_SOURCE_FILE:2)

19:14 (let [n (minroot (+ (sq xr) (sq yr) (sq zr)))]

19:19 hiredman: clojurebot: cheesecake is delicious.

19:19 clojurebot: Roger.

19:33 ryrunfrnf: why os destructuring slower than first/rest?

19:38 gnuvince_: ryrunfrnf: destructuring has more bells and whistles

19:38 > (let [[x y & z :as all] [1 2 3 4]] [x y z all])

19:38 [1 2 (3 4) [1 2 3 4]]

19:44 ryrunfrnf: hmm when doign a raytracer

19:44 that must be perfect for multimethods right?

19:44 now i seee their advantage

19:44 have amethod intersect

19:44 and specialize on the thing its calle don

19:51 god clojure is sooooo much cleaner than common lisp

19:53 gnuvince_: :)

20:29 ryrunfrnf: is it impossible to set swank/slime-intendation to 4 chars always?

20:39 java.lang.IllegalArgumentException: Wrong number of args passed to keyword: :shape (NO_SOURCE_FILE:0)

20:42 (intersect sph [10 20 30] 30 40 50)

20:42 (defmethod intersect :Sphere [sphere point xr yr zr]

20:42 (defn sphere-intersect [sphere point xr yr zr]

20:42 wtf?

20:43 hiredman: ryrunfrnf: all the args to a multimethod get passed to the dispatch function

20:43 so what happens there is (:Sphere sphere poit xr yr xr)

20:43 which, uh, no?

20:44 wait

20:44 the is defmethod

20:44 not defmulti

20:45 ryrunfrnf: so i want to refer to the sphere itself, how do i?

20:46 (defmethod area :Rect [r]

20:46 (* (:wd r) (:ht r)))

20:46 hes assing the rect itself

20:46 hiredman: what does your defmulti look like?

20:47 ryrunfrnf: (defmulti intersect :shape)

20:48 lisppaste8: andjnsd pasted "defmulti" at http://paste.lisp.org/display/71202

20:51 ryrunfrnf: (defmethod intersect :Sphere [sphere a]

20:51 (+ (:x sphere) a))

20:51 works

20:52 hiredman: so

20:52 yeah

20:53 you are using a keyword as a dispatch function

20:53 but that only works if you have one arg

20:53 ryrunfrnf: isnt ricks example?

20:53 hiredman: yeah it is

20:53 but he only dispatches on one param

20:53 ryrunfrnf: ok

20:54 so how should i change it?

20:54 how do irefer to the sphere inside its defmethod? :Sphere?

20:55 hiredman: is the first argument always going to be hash with a :Sphere keyword?

20:55 ryrunfrnf: it is going to be a :shape

20:55 hash-map

20:55 sphere, cube etc

20:55 it is for a raytracer

20:56 hiredman: (doc defstruct)

20:56 clojurebot: Same as (def name (create-struct keys...)); arglists ([name & keys])

20:56 hiredman: btw

20:56 ryrunfrnf: yes

20:56 but isnt this pretty much was multimethods are for?

20:56 hvaing an intersect functiona nd dispathicng on the type

20:56 of :shape?

20:57 (defmethod intersect :Sphere [a]

20:57 (+ (:x :Sphere) a))

20:57 hiredman: so replace :shape in the defmulti with (fn [& x] (:shape (first x)))

20:57 ryrunfrnf: doesnt work

20:57 i dont get how to use them then

20:57 hiredman: ryrunfrnf: you don't seem to understand how dispatch functions work

20:57 ryrunfrnf: correct

20:58 hiredman: that is what multimethods are for, you just are passing more then one arg, but using a dispatch function that only takes one arg

20:58 keywords in clojure are functions of maps

20:58 ryrunfrnf: which is the dispathc function? defmulti?

20:58 hiredman: ryrunfrnf: you are using :shape as a dispatch function

20:58 the keyword :shape

20:59 ryrunfrnf: yes

20:59 what should i use?

20:59 AWizzArd: ryrunfrnf: have a look at this examplefor the generality of multimethods: http://paste.lisp.org/display/68846

20:59 hiredman: a function that can take as many args as you pass

21:00 the dispatch function needs to have the same arity as the method it dispatches to

21:00 or something like that

21:01 a keyword has an arity of 1

21:01 your method as an arity of more then 1

21:01 *boom*

21:06 ryrunfrnf: then i dont get what defmulti is for

21:06 hiredman: then don't use it

21:08 clojurebot: where are you?

21:08 clojurebot: http://gist.github.com/27733

21:08 hiredman: I use multimethods there

21:09 AWizzArd: ryrunfrnf: defmulti takes a function

21:10 when you say (defmulti foo my-fun) then my-fun gets called with the arguments that you gave to the call of foo

21:10 if you say (foo 1 2 3) then Clojure will do (my-fun 1 2 3) for you

21:10 my-fun yields a result

21:11 then Clojure goes through all (defmethod foo)'s to see if one of them was done for this result

21:11 look at http://paste.lisp.org/display/68846

21:11 there is the call (foo 2 4)

21:11 Clojure secretly calls my fn from above

21:12 This 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:12 There exists a method foo for 6

21:13 it 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:14 Clear now?

21:17 ryrunfrnf: no

21:18 (classes-of int int) would be clear

21:18 hiredman: ...

21:18 ryrunfrnf: i want to write a method intersect that takes an abstract shape and then dispatches to the correect shape-method

21:19 AWizzArd: what exactly is unclear in this example?

21:19 hiredman: ryrunfrnf: you are not going to be able to use a keyword as a dispatch, because your methods take more then one arg

21:20 your best bet is to write a dispatch function that takes a variable number of args

21:20 ryrunfrnf: ok i see

21:20 AWizzArd: you can pass keywords to defmulti btw, because they are treated asfunctions

21:20 hiredman: and uses the keyword to determine the :shape of the first argument

21:20 AWizzArd: (:my-key my-hashtable) ==> value for key

21:21 jeremy___: 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:21 (+ ~@x))

21:22 hiredman: no

21:22 jeremy___: I get a ClassCastException when I run (my-sum `(1 2 3))

21:22 hiredman: yeah

21:22 you do

21:22 ok

21:22 jeremy___: what am I doing wrong?

21:22 hiredman: a lot

21:22 ~ is unquote

21:22 mostly only used in macros

21:23 AWizzArd: you can use ~ or ~@ only inside a backquote expression. Your (+ ~@x) is just a plain list

21:24 try instead (defn my-sum [x] `(+ ~@x))

21:24 when you then (my-sum `(1 2 3)) ==> (+ 1 2 3)

21:24 hiredman: (doc apply)

21:24 clojurebot: Applies fn f to the argument list formed by prepending args to argseq.; arglists ([f args* argseq])

21:25 jeremy___: ah thanks it's starting to make sense

21:26 AWizzArd: This 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:26 ryrunfrnf: int he examples oyu posted both defmulti and defmethod contains information on implementation

21:26 they seem intertwined, thats what is confusing me

21:27 AWizzArd: Note however that you can write all programs without `, ~ and ~@. They are just shortcuts to plain function calls.

21:27 ryrunfrnf: You could have a (defn my-count [obj] (count obj)). And then you do (defmulti foo my-count).

21:28 this means that now all calls in the form of (foo ...) will in secretly be (my-count ...)

21:28 ryrunfrnf: so whats the point then?

21:28 AWizzArd: example: (foo [1 2 3]) === (my-count [1 2 3]) ==> 3

21:28 but without defmethods it would be pointless

21:29 now we put in a method: (defmethod foo 3 [arg] (println "Hello"))

21:29 ryrunfrnf: I 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:29 AWizzArd: We said the call (foo [1 2 3]) ==> 3. There exists a (defmethod foo 3 ...)

21:30 the 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:30 What now happens is: put the original argument to foo (it was [1 2 3]) to this method

21:30 arohner: what is the value of clojure.core.test?

21:30 AWizzArd: in this method it is called arg. We could have called it peter. The body of the method is (println "Hello")

21:31 So, (foo [1 2 3]) will print Hello

21:31 arohner: it's slightly annoying that the test function expects failures to throw exceptions, yet it does nothing to catch & report them

21:31 ryrunfrnf: Like 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:31 AWizzArd: that was the old school dispatching, as most languages do

21:31 this is the plain old type dispatch

21:31 hiredman: you can do that sort of thing

21:31 AWizzArd: but in Clojure you are not bound to that

21:32 This is just a subset of what Clojures methods can do

21:32 hiredman: yeah

21:32 AWizzArd: you can dispatch for example on the number of elements in your argument, as we just did in the my-count example

21:32 so no longer the type of the argument is important

21:32 but only how many elements it contains

21:33 hiredman: you can dispatch on just about anything

21:33 because the dispatcher is just another function

21:33 AWizzArd: add a (defmethod foo 5 [ryrun] (reverse ryrun))

21:33 now you can say: (foo "Hello")

21:33 and see what happens

21:34 ryrunfrnf: but i want a funiton intersect so i should have one defmulti and sveral defmethods?

21:34 hiredman: yes

21:34 AWizzArd: ryrunfrnf: first you should understand in detail how it works. I think these examples were pretty obvious. If not, what exactly puzzles you?

21:34 hiredman: but you will need slightly more complicated dispatch function because you are using more then one argument

21:41 AWizzArd: ryrunfrnf: in other languages a defmulti always looks basically the same. It is always something like: (defmulti name class)

21:42 where (class obj) returns the type of that object

21:42 you can not simply replace class with your own function

21:43 ryrunfrnf: but i dont get the 6 and the \H

21:43 wtf are those names of the methods?

21:43 if it is a 6 then do this?

21:44 hiredman: those are return values of the dispatch function

21:44 if the dispatch function returns 6 then do this method

21:45 which method is run is the result of what the dispatch function outputs

21:45 AWizzArd: ryrunfrnf: okay, so your problem lies in the (fn) which is passed to defmulti

21:45 in Clojure a function can have many parameter lists and bodies

21:46 The anon function that I passed to defmulti is such an example. It has the parameter collection and the body (first collection)

21:46 If this function is called with just one arg then this branch of the fn is used

21:47 Now the fn has a second branch. One that has two parameters. If we pass in two args they will be added.

21:47 ryrunfrnf: but why are they instances of a somehting instead foa type?

21:47 if u make a general speci it should be diosptache dona type

21:47 * hiredman dies

21:47 ryrunfrnf: not an isntanc eof the type

21:47 AWizzArd: try (defn blah [x] (first x) [x y] (+ y x)) and call blah

21:48 try calling blah with one arg and with two

21:48 hiredman: AWizzArd: I think you may be missing some parens

21:48 AWizzArd: oki right

21:49 parens around [x] (first x) and also around the second guy

21:49 hiredman: and the (first ...) is kind of pointless

21:49 AWizzArd: hiredman: why?

21:49 hiredman: AWizzArd: well I guess it depends

21:49 AWizzArd: (blah (range 8 24))

21:49 ryrunfrnf: i thin i see a little now

21:49 hiredman: I just assumed that since the [x y] form uses (+ )

21:49 AWizzArd: but also (blah 10 5)

21:50 hiredman: anyway

21:50 whatev

21:50 AWizzArd: ryrunfrnf: 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:51 when 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:52 A string is a collecting. The first element of "Hello World" is the char \H

21:52 hiredman: clojurebot: multimethods?

21:52 clojurebot: multimethods seperate the 20% from the 80%

21:52 AWizzArd: How can one teach the clojurebot new things?

21:53 hiredman: clojurebot: a is b

21:53 clojurebot: c'est bon!

21:53 hiredman: clojurebot: a?

21:53 clojurebot: a is b

21:53 hiredman: clojurebot: a is also c

21:54 clojurebot: Ack. Ack.

21:54 hiredman: clojurebot: a?

21:54 clojurebot: a is c

21:54 hiredman: clojurebot: a?

21:54 clojurebot: a is b

21:55 AWizzArd: clojurebot: multimethods is also what separates the boy from the man.

21:55 clojurebot: c'est bon!

21:55 rottcodd: clojurebot: b?

21:55 clojurebot: excusez-moi

21:56 ryrunfrnf: if i want to pass 5 args and dispatch on the ttype oa the first?

21:56 (defmulti intersect (fn [a b c d e]

21:56 (class a))) ?

21:57 hiredman: uh

21:57 you most likely don't want to use (class ...)

21:57 but that is the general idea

21:57 AWizzArd: this fn looks like a function that takes 5 arguments and returns the class of the first (while it ignores the other 4)

21:58 jeremy___: 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:58 hiredman: (doc float)

21:58 clojurebot: Coerce to float; arglists ([x])

21:58 AWizzArd: (float (/ 1 2 3 4))

21:58 hiredman: clojurebot: botsnack

21:58 clojurebot: thanks; that was delicious. (nom nom nom)

21:58 AWizzArd: (/ 1 2 3 4.0)

21:59 jeremy___: ah thanks I overlooked that on the API page.

21:59 ryrunfrnf: so if i want to dispatch on a type i should have a defstrcut not a function calle dpshere?

22:00 AWizzArd: a defstruct is done for optimization,it will not create types

22:00 structs are simple hashtables

22:01 but they don't use up RAM for (some) of their keys

22:02 ryrunfrnf: oh my

22:02 god

22:02 so i cant disptach on something called a sphere?

22:02 hiredman: YOU CAN DISPATCH ON WHATEVER YOU WANT

22:02 ryrunfrnf: becaus eif i d struct sphere it passes back a ahsh howthe f doi matcht hat?

22:02 AWizzArd: if 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:02 hiredman: JUST WRITE THE RIGHT FUNCTION

22:03 ryrunfrnf: yes but since all :shapes will use hashmaps how do i differ them?

22:03 hiredman: you could even dispatch on time of day

22:03 AWizzArd: in a structure map only one time the keys need to be stored.

22:03 ryrunfrnf: you will manually have to put some key/value into the hashtable

22:03 hiredman: ryrunfrnf: you have a key {:shape :sphere}

22:03 AWizzArd: (defstruct person :name :age)

22:03 hiredman: and you have a function that returns the value of that key of the hash

22:04 AWizzArd: (defn make-person [n a] (assoc (struct person n a) :type :person)

22:04 now each instance of your hashtable will also have the key/value pair {:type :person}

22:06 SimonAdameit: Good evening

22:07 AWizzArd: Moin Simon

22:13 lisppaste8: blarf pasted "im dying of frustration" at http://paste.lisp.org/display/71210

22:13 hiredman: man, I wonder who blarf is

22:13 ok

22:14 NO

22:14 no no

22:14 no

22:14 no

22:14 albino: that's a lot of 'no's

22:14 hiredman: see, here you have one thing you are passing, the hash

22:14 so your dispatch function should take one value

22:15 I think you will be better off if you have your dispatch function take a variable number of args

22:16 * hiredman scrolls up to find the example he already gave

22:16 ryrunfrnf: but it takes a sphere a point and 3 coordinates

22:17 hiredman: ryal all of which are in the hash

22:17 the hash is one "thing"

22:17 gnuvince_: Does clojure have a divmod function?

22:17 hiredman: object, datastructure, thing

22:18 (doc rem)

22:18 clojurebot: remainder of dividing numerator by denominator.; arglists ([num div])

22:18 ryrunfrnf: but which is thet dispatch function? defmethods?

22:18 hiredman: no

22:18 SimonAdameit: Using swank-clojure I get the following error: "Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/Repl"

22:18 gnuvince_: hiredman: that's only the second part :)

22:18 hiredman: the dispatch function is the function you pass to defmulti

22:19 gnuvince_: well I don't know what divmod is

22:19 so I guessed

22:19 SimonAdameit: Alot 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:19 Any Idea how to fix this?

22:19 gnuvince_: hiredman: (divmod 3 2) => (1 1)

22:20 hiredman: basically, it'd be: (defn divmod [m n] [(quot m n) (rem m n)])

22:20 hiredman: ok

22:20 AWizzArd: SimonAdameit: do you use the newest versions?

22:21 hiredman: clojurebot: emacs?

22:21 clojurebot: emacs is hard, lets go shopping!

22:21 SimonAdameit: AWizzArd: for slime, swank-clojure and clojure yes

22:21 and emacs 22

22:22 AWizzArd: I have the same, for me it works

22:22 SimonAdameit: could you paste the relevant .emacs parts, maybe I could try yours

22:22 AWizzArd: oki

22:23 ryrunfrnf: but isnt the defmethod that has a value of what the defmulti retuns called?

22:23 defmulti intersect retuns :shape a whc should be :Sphere

22:23 then defmethid intersect :Sphere is called?

22:24 lisppaste8: rte annotated #71210 with "multis" at http://paste.lisp.org/display/71210#1

22:24 hiredman: that should work

22:25 and could you use your own nick when you paste stuff?

22:26 SimonAdameit: AWizzArd: Yay, got it working to

22:27 It actually was a "stupid" error in specifying the wrong path :)

22:27 ryrunfrnf: yes but it doesnt

22:28 hiredman: what is the error

22:28 lisppaste8: AWizzArd pasted "Example emacs config for Clojure+slime" at http://paste.lisp.org/display/71211

22:28 AWizzArd: oki

22:28 hiredman: ryrunfrnf: paste the whole thing again

22:28 uh

22:28 yeah

22:28 you are missing parens

22:29 inside the fn, you need (:shape a)

22:30 ryrunfrnf: wow so annoying

22:30 now it works

22:30 hehe sorry guys

22:30 AWizzArd: I think you don't need these 5 args for defmultis dispatch fn

22:31 try (defmulti intersect :shape)

22:31 hiredman: AWizzArd: ssh it's working, back away slowlyr

22:31 AWizzArd: *g*

22:31 hiredman: AWizzArd: he passes more then one arg

22:31 not just the hash

22:31 keywords are functions of arity 1

22:31 so they blow up

22:31 which is how this whole thing started

22:32 AWizzArd: wow

22:32 well, you could need a calm-down-tea for tonight hire ;-)

22:32 it was a moving theme

22:32 hiredman: huh

22:33 Chouser: keywords can take 2 args (not found)

22:33 hiredman: Chouser: just noticed that

22:34 the point is, he is passing to many args to dispatch via a keyword, so cargo culting the examples doesn't work

22:36 * Chouser nods

22:36 sdfsf: the intersect function takes 5 args

22:37 a sphere a point and 3 coordinates

22:37 * hiredman dies again

22:37 sdfsf: so i need to pass everala rgs aight?

22:38 i should do porn instead

22:46 AWizzArd: sdfsf: if this data is already inside the hashtable then you would only have to pass this one arg, namely the hashtable

23:19 matzero: hello is this working?

23:19 microphone check 1 check 2

23:20 sdfsf: anyone seen matzero lately? i never se him around here

23:21 matzero: lol

23:21 cool thanks for the ping back

Logging service provided by n01se.net