#clojure log - Sep 06 2010

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

0:10 technomancy: seancorfield: also: lein tasks have to have an ns form to be actual tasks

1:00 notsonerdysunny: ~pastebin

1:00 clojurebot: Gabh mo leithscéal?

1:11 Raynes: notsonerdysunny: gist.github.com is a popular choice.

1:38 notsonerdysunny: Raynes: thx ..

2:12 tnoborio: The communication has not been so understood well about ctor problem.

2:13 I wrote sample Java Class. http://gist.github.com/565876

2:15 I wrote sample class Hoge instead of java.io.File.

2:15 The result is the same.

2:54 seancorfield: technomancy: i have

2:54 (! 797)-> cat leiningen/hello.clj

2:54 (ns leiningen.hello)

2:54 (defn hello "I'm just a plugin that says Hello."

2:54 [project] (println (str "I'm a leiningen plugin that says Hello " (:name project) "!")))

2:54 it works in lein help hello

2:54 and lein hello

2:54 but doesn't show in lein or lein help

2:54 just fyi

4:32 esj: Hello Peoples

6:16 fliebel: morning

6:18 mrBliss: morning

6:19 esj: wotcha

6:26 bartj: chouser, thank you for lazy-xml -> it is unbelievably simple and makes dealing with xml fun!

6:27 fliebel: Are there some sanity checks I can perform on my own Clojure code? I'm trying to revive my Clojure skills with a lot of exercises, and since I don't have anyone to look after me all the time, I might be writing bogus code :) Things I'm already doing: Unfolding nested code, making fns of repetitive things, try to look for existing functions to replace my plumbing and hang in here a lot.

6:28 Raynes: I've always found it odd that XML is represented so differently from JSON in Clojure. Is there any particular reason for that? You use zippers to traverse XML, but JSON is transformed directly into Clojure maps and data structures by the parsers.

6:29 fliebel: Raynes: Might be that the lazy SAX parsrers suit zipping better.

6:30 Raynes: I didn't think of that.

6:30 Laziness.

7:10 opqdonut: what's the simplest way to call a clojure function from java

7:10 preferably by name

7:11 basically, I have a class written in Java, but I'd like to keep the implementation of one method on the clojure side

7:12 Chousuke: the RT class in Clojure has useful methods

7:12 you can use those to get the var of the function you need and then call invoke on it

7:13 there's no documentation, but it shouldn't be too difficult to understand if you just read the source file

7:13 raek: http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#Invoking_Clojure_from_Java

7:17 opqdonut: relatedly, what's the opposite of slurp?

7:17 mrBliss: spit

7:19 Raynes: -> (doc spit)

7:19 sexpbot: java.lang.SecurityException: Code did not pass sandbox guidelines: (#'clojure.core/spit)

7:19 Raynes: Of course.

7:19 opqdonut: ah

7:19 hmm, that's only in 1.2 right?

7:20 Raynes: In 1.1, it's in seq-utils.

7:21 Errrrr, not seq-utils.

7:22 In 1.1, it's in duck-streams.

7:23 raek: what was clojure.contrib.io? half way from clojure.contrib.duck-streams to clojure.java.io?

7:23 Raynes: raek: It was originally just duck-streams renamed.

7:27 opqdonut: thanks

7:52 Dranik: hello all!

8:08 bartj: I think emit in clojure.contrib.lazy-xml always emits to the stdout

8:08 is there a function which will store the "emit" to a variable instead ?

8:14 I am looking at http://github.com/richhickey/clojure-contrib/blob/bbe248f90e6ec33d5e85d2267fa1caf8c7cb99a7/src/main/clojure/clojure/contrib/lazy_xml.clj

8:17 grc: (pop (list)) throws an exception as the docs state that it should, but

8:17 (pop (java.lang.PersistentQueue/EMPTY)) returns a PersistentQueue. What

8:17 am I missing?

8:23 jgracin: bartj: with-out-str macro captures all output and returns it as string.

8:26 bartj: jgracin, big thanks

8:44 er, there is no "ignore" option while inserting records in clojure.contrib.sql ?

8:44 ie. if there are duplicate rows, I would like to over-ride the existing rows ?

8:48 hmm, update-or-insert-values does the job

9:14 silly question

9:15 I feel the "insert-values" method in clojure.contrib.sql should also support a "ignore clause"

9:15 apart from forking the file, what I can I do to ask the author (scgilardi) to include it ?

9:25 raek: bartj: you could create a ticket for it at the clojure-contrib assembla space

9:26 if you have signed the Contributor Agreement, you can send in a patch for it too

9:28 bartj: raek, thanks!

9:36 bobo_: has anyone thought about submiting a talk to jfokus? (swedish java conferance)

10:54 technomancy: seancorfield: weird; I tried that exact same thing and it works here

11:00 seancorfield: thx technomancy i'm sure i'm just doing something wrong

11:41 blais: (let [b (ref nil)] (dosync (ref-set b b)))

11:41 Will generate a stack overflow. Why won't Clojure let me create circular refs?

11:42 LauJensen: blais: a reference is a mutable thing, putting a mutable thing inside of a reference is redundant, as the security that the ref was supposed to provide is now void

11:43 AWizzArd: blais: Not that I want to defend the current behaviour, but why do you need it?

11:43 LauJensen: (let [b (ref nil)] (dosync (ref-set b @b))), would work and is what you'll se in most applications

11:45 blais: AWizzArd: just messing around. OTOH I do have a legitimate need for circular references in some piece of code (parsing a language, wanting to refer to parsed type definition objects, which may be recursive).

11:45 AWizzArd: blais: refs may contain other refs.

11:45 blais: AWizzArd: CL lets you do it.

11:45 AWizzArd: ,(let [a (ref nil), b (ref nil)] (dosync (ref-set a b)))

11:45 clojurebot: #<Ref@1e0937b: nil>

11:45 blais: No way to do it without refs?

11:45 LauJensen: blais: Did you understand what I wrote above?

11:46 blais: Yes.

11:46 AWizzArd: blais: you most certainly will not need this. Refs can contain other refs, and this should work for practical cases.

11:51 blais: Let me define the problem another way: I'm creating a DSL which defines various types. Each of these types may refer to each other. In the first pass I tag such references and do a bit of validation (I don't want to force the user to define types in a particular order). In a second pass, I will resolve the type references. This will create a circular data structure.

11:51 How would you approach this problem without creating temporaries?

11:57 AWizzArd: your example is not circular.

11:57 ,(let [a (ref nil) b (ref a)] (dosync (ref-set a b)))

11:57 clojurebot: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@101ba6f: #<Ref@16eb456: #<Ref@

11:57 blais: This one was.

11:57 Results in StackOverflow.

11:57 I suppose ref-set attempts automatically resolve a ref when it is provided one.

11:58 LauJensen: ,source ref-set

11:58 clojurebot: java.lang.Exception: Unable to resolve symbol: source in this context

11:58 LauJensen: source ref-set

11:59 ~source ref-set

11:59 msappler: hey anybody else developing an action/rpg diablo kind of game in clojure?

11:59 blais: (This clojurebot is fun.)

11:59 msappler: I am willing to share code / experience ;)

12:03 AWizzArd: blais: btw, there is no stack overflow

12:04 I forgot, just remembered.

12:04 Your code worked.

12:04 But, your repl tries to print the result.

12:04 ,(let [b (ref nil)] (dosync (ref-set b b)))

12:04 clojurebot: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@163fa09: #<Ref@

12:04 AWizzArd: ,(let [b (ref nil)] (dosync (ref-set b b)) 55)

12:04 clojurebot: 55

12:04 AWizzArd: Just make sure you work with those refs, but don't try to print them.

12:05 ,(let [b (ref nil)] (dosync (ref-set b b)) (class @b))

12:05 clojurebot: clojure.lang.Ref

12:05 AWizzArd: ,(let [b (ref nil)] (dosync (ref-set b b)) (= b @b))

12:05 clojurebot: true

12:07 blais: Ah! Thx AWiz. The docs for *print-circle* indicate it's not used yet.

12:07 Wow, this is useful for CLers learning clojure: http://hyperpolyglot.wikidot.com/lisp

12:10 AWizzArd: blais: yes, though it is not very correct in respect to Clojure.

12:10 Running in emacs can also be done via M-x slime

12:11 Making a standalone is possible. Though typically you can simply compile it to a double-clickable .jar file (vs .exe).

12:12 blais: it says CL is not case-sensitive, which is wrong. CL *is* case-sensitive, but also case-translating.

12:13 blais: AWiz: looks like a wiki page, feel free to amend.

12:16 AWizzArd: blais: good point

12:22 blais: unfortunately I can not edit it. But it contains tons of litte errors.

12:35 bartj: AWizzArd, case-translating ? that is the first time I heard that word!

12:38 AWizzArd: bartj: comes directly from the mouth of Kent Pitman

12:39 bartj: AWizzArd, can you please be kind enough to explain what it means ?

12:40 you mean it has built-in functions to convert to camel-case, etc?

12:42 AWizzArd: bartj: it means that CL per default translates everything to upper-case.

12:43 bartj: AWizzArd, would that affect me as a programmer ?

12:43 AWizzArd: In Clojure this would work if the reader would call .toUpperCase on the input, if it does not find something that stops it from doing so.

12:44 bartj: AWizzArd, I mean how would this feature (case translation) help CL users ?

12:45 AWizzArd: Historically LISP was used on machines that only supported uppercase chars.

12:45 For better compatibility this case translation was built into CL.

12:46 In principle it does not affect you, if you don't use specific reader macros.

12:47 blais: ,(seq? {})

12:47 clojurebot: false

12:47 blais: ,(seq? [])

12:47 clojurebot: false

12:48 blais: ,(seq? '())

12:48 clojurebot: true

12:48 blais: What is the idiomatic way to verify that an object is a sequable?

12:48 AWizzArd: ,(coll? {})

12:48 clojurebot: true

12:48 blais: Ha.

12:48 Thx.

12:48 AWizzArd: ,(map coll? [{} [] ()])

12:48 clojurebot: (true true true)

12:49 AWizzArd: {} and [] don't implement the ISeq interface.

12:49 blais: Ya, exactly what I'd been looking for.

12:52 What's the idiomatic way to check that an object supports the map interface?

12:52 ,(type {})

12:52 clojurebot: clojure.lang.PersistentArrayMap

12:52 blais: Hmm.

12:53 emh: ,(map? {})

12:53 clojurebot: true

12:53 blais: *blush*

12:54 (Thought I'd tried that a second ago.)

12:56 Somebody ought to write a book like the Little Schemer for Clojure. Would be awesome.

13:26 Is there an idiomatic way to check that an object is of a specific type, as created by defstruct?

13:27 hiredman: defstruct doesn't create types

13:27 blais: I see a trick in the clojure libraries, to use a field as a type market.

13:27 s/market/marker/

13:27 sexpbot: <blais> I see a trick in the clojure libraries, to use a field as a type marker.

13:27 hiredman: it creates maps that may be more efficient when sharing the same keyset

13:28 blais: Yep, but... how do I check that an object I receive is of that type?

13:28 Oh, there is no type.

13:28 Hmm.

13:28 map? returns false for those objects.

13:29 hiredman: ,(map? (struct (create-struct :foo) 1))

13:29 clojurebot: true

13:30 blais: I'm using struct-map.

13:31 hiredman: ,(map? (struct-map (create-struct :foo) :foo 1))

13:31 clojurebot: true

13:34 blais: Aaaah got it. An error on my side, had misused create-struct vs. struct.

13:41 nlogax: when i'm messing around in the (lein) repl, and start a jetty server via compojure for example, can i interrupt it without getting thrown out into the shell?

13:45 bobo_: nlogax: you want the shell to return after starting jetty?

13:45 then join? false is what you want

13:46 http://gist.github.com/555465 like that

13:48 nlogax: bobo_: i was thinking more like killing jetty and returning to the repl (instead of everything dying, leaving me in bash). but that might do the trick, thanks!

13:49 bobo_: nlogax: http://github.com/swannodette/enlive-tutorial/blob/master/src/tutorial/template1.clj

13:50 if you look at the bottom, you can see how to be able to start/stop the server

13:50 nlogax: cool, thanks again :)

13:50 bobo_: :-)

13:53 raek: ,(type ^{:type :foo} {:a 1, :b 2})

13:53 clojurebot: :foo

13:54 raek: blais: ----^

13:55 type is define as something like this: (defn type [x] (or (:type (meta x)) (class x)))

13:58 blais: raek: nice. Thx.

14:01 ,(let [a '(typereff nil)] (= (first a) 'typereff))

14:01 clojurebot: true

14:01 blais: ,(let [a `(typereff nil)] (= (first a) 'typereff))

14:01 clojurebot: false

14:01 blais: What gives? Does syntax-quote do something to my symbols?

14:02 raek: yes

14:02 ,`conj

14:02 clojurebot: clojure.core/conj

14:03 raek: this is for avoiding symbol capture

14:04 ,`(~'typereff nil) ; possible, but not something that one normally should need to do

14:04 clojurebot: (typereff nil)

14:05 blais: A bit of a gotcha...

14:06 raek: that is, there is most probably a better way to do it

14:07 blais: I'll try to use a keyword. The 'typereff in the example above is used to tag some parts of a larger datastructure for future processing.

14:08 chouser: or just use `typereff when you go to compare it

14:08 raek: you could use ordinary quote or list

14:08 chouser: that way you get a nice namespaced symbol - less chance of accidental collision

14:08 raek: true

14:09 the use case looks much more of the one of keywords...

14:09 blais: Oh, good point.

14:09 raek: s/of/like/

14:09 sexpbot: <raek> the use case looks much more like the one like keywords...

14:09 blais: Thx chouser.

14:09 chouser: you can namespace keywords too, if you want.

14:09 ,::foo

14:09 clojurebot: :sandbox/foo

14:10 blais: Aaaaaha _that_'s what this is. I had seen those in the contrib module, had no idea. Thx.

14:39 This is getting a bit confusing, w/ cons vs. lists now:

14:39 ,(list? '(:typeref int32))

14:39 clojurebot: true

14:40 blais: ,(list? `(:typeref int32))

14:40 clojurebot: false

14:40 blais: ,(type '(:typeref int32))

14:40 clojurebot: clojure.lang.PersistentList

14:40 blais: ,(type `(:typeref int32))

14:40 clojurebot: clojure.lang.Cons

14:40 blais: I guess that's why; where's the elegance in this?

14:41 Is there an elegant way to check that something is a "list or a cons cell"?

14:42 kencausey: Are you sure you care? You should as much as possible code to Sequences and not care which exact implementation it is.

14:42 Or is this a question of testing for 1 or more than 1?

14:44 blais: Ken: the problem is this: sometimes creating lists appears to create PersistentList, sometimes (when using `) it creates Cons. It makes it a little tricky to mix-n-match them, doesn't it? Unless there's a way to check for both, and one has to take into account the possibility of either in the routine that processes the output.

14:45 I mean, I've just been caught by this one just now, some of my functions use syntax-quote to put lists together, and others don't. Now I have this weird animal made up of PersistentList and Cons objects and I need to process it.

14:45 kencausey: right, so perhaps you can explain why you need to know which one it is? It sounds like you are worrying about a problem you don't have. But I could of course be wrong.

14:46 blais: I suppose I should be careful how I create it from now, knowing that syntax-quote doesn't return a list.

14:46 What's the "normal" course of action?

14:47 kencausey: I'm a little too inexperienced to answer that, I simply know that for the most part you deal with Sequences and don't have to care whether it is Cons or a PersistentList or even perhaps a Map.

14:48 blais: Well I have a generic function that uses (cond) to process a hierarchical data structure, and it does something different for lists and maps. The syntax-quote problem broke it.

14:49 kencausey: post some code and maybe someone more experienced than I will be interested in commenting

14:49 hoeck: blais: maybe you want seq? instead?

14:50 blais: that returns true for anything that prints with normal parens

14:52 ,(map seq? [(concat '(1) '(2)) (list 1 2 3) (cons 1 '(2 3)) [] {}])

14:52 clojurebot: (true true true false false)

14:54 blais: That would work.

14:54 Thx.

15:30 dberg: clojure/java newbie here. downloaded clojure and clojure-contrib 1.2. (require 'clojure.contrib.str-utils) a file not found exception is thrown

15:30 is that fixed in the CLASSPATH env var?

15:31 fielcabral: is that a backquote?

15:31 oh guess not

15:32 dberg: you mean before 'clojure.contrib.str-utils?

15:32 fielcabral: yes

15:33 dberg: nope, single quote

15:33 blais: dberg: What's your setup and how are you attempting to run Clojure?

15:34 dberg: running ubuntu, downloaded 2 zip files for clojure and clojure-1.2

15:34 running java -jar clojure.jar

15:34 my guess is that somehow it has to access clojure-contrib.jar

15:34 blais: Right.

15:35 I found invocation of Clojure a little tricky when I started.

15:35 THere are a couple of ways I like to do it:

15:35 - Use Leiningen, which downloads all the libraries for you.

15:35 - Write a script that invokes java --like you did-- with all the jars you need.

15:36 dberg: leiningen is a buil tool then

15:36 chouser: but don't try to use -jar or $CLASSPATH, generally.

15:36 blais: The second way is when I'm done; when I'm developing I use the "lein swank" command and evaluate from Emacs.

15:37 leiningen also downloads all the dependencies you need. If you're on a fast network connection it's probably the easiest way to get setup.

15:37 chouser: why not?

15:37 dberg: nice, checking it now

15:38 blais: chouser: driving manual, works great when I need it, no magic. Simple. What's wrong with it?

15:38 chouser: avoid $CLASSPATH because any command-line args (like -cp or -jar) override it

15:38 dberg: ohhh, I see

15:38 chouser: avoid -jar because you can only specify one -- it overrides everything else

15:38 dberg: I was trying to set it without success

15:38 chouser: if you know what you're doing, you can make things work with any of them, but it's var simpler (especially when starting) to only use -cp

15:43 fielcabral: Could you share a good mnemonic/tip for remembering what comes after :require or :use in the ns form?

15:44 technomancy: fielcabral: rauol: require/as, use/only, lol.

15:44 fielcabral: :-)

15:44 LauJensen: technomancy: you still not getting query windows?

15:45 technomancy: LauJensen: no, it's working; I just sat down.

15:45 LauJensen: I thought you worked standing up

15:46 technomancy: true, but it's a holiday in the US

15:46 so to celebrate I am sitting down. =)

15:47 LauJensen: Fantastic :)

16:01 pcc1: for some java interop I need to set the contents of a specific java collection object to the contents of a seq. is there a builtin way to do this?

16:03 rainerschuster: i'm REPLing around with clojure-clr. can someone give me a hint on how to call a func in a STA in order to launch a WPF window? i grep ed the source, the samples, the group ...

16:07 LauJensen: pcc1: I suppose your java collection has an 'add' function you can call and pass it the seq? (.add obj seq)

16:08 pcc1: LauJensen: I meant something like (doto obj (.clear) (.addAll seq)))

16:09 LauJensen: or just (doto obj .clear (.addAll seq))

16:11 pcc1: LauJensen: yes, that works, thanks

16:11 blais: Clojure core already defines atom? as (not (coll?)). If I redefine as (defn atomp [x] (= (type x) clojure.lang.Atom)), is that heresy?

16:12 An integer is (not (coll?)), that doesn' tmake it an atom. Not sure I understand the rationale.

16:12 fielcabral: coll?

16:12 clojurebot: Reader syntax of collections has gotchas

16:13 LauJensen: blais: There's atom in the english sense, and then there's atom in the clojure.lang.Atom sense. What you're suggesting probably makes sense for your app domain, but the -p predicate isn't seen in Clojure-land - In fact I frown upon it :)

16:13 What you can do is refer clojure.core and rename atom? to core-atom?) and then define your own atom?

16:14 blais: Right, not an idiomatic name. I was just thinking of using atoms as temp storage (OMG mutable data structurrrrs!) instead of my two-step process for parsing. In my second pass I'll "change" (OMG!!!!!) the atoms.

16:15 So I need to check for atoms, and I found that definition of atom? from core, not coll?, weird, anyone knows why?

16:15 Lau: thx. I'll avoid the -p's.

16:17 LauJensen: blais: I know that the OMG was very popular in Ruby circles, but in Clojure it never got further than the p predicates :)

16:18 blais: Hahaha :-)

16:23 LauJensen: Man I wish I had more money to buy impressive Apple hardware: http://www.youtube.com/watch?v=iaz63L8x0Z8

16:44 rainerschuster: somebody using the CLR version?

17:02 kotarak: weren't types suposed to support mutable fields?

17:03 ok. never mind

17:04 raek: I think there is a volatile-mutable metadata key

17:04 http://efreedom.com/Question/1-3132931/Mutable-Fields-Clojure-Deftype

17:05 I don't know if this still works though

17:05 kotarak: raek: found out that ^:keyword doesn't work. Which is a pity (on a first sight). Have to use ^{:keyword true}  instead

17:15 raek: how is test namespaces related to the namespace-under-test nowadays?

17:15 e.g. what would be the test namespace for foo.bar.x?

17:21 I know it used to be foo.bar.test.x, but I think heard that it had changed...

17:30 technomancy: raek: if you don't use clj-stacktrace I recommend foo.bar.test-x since clojure.stacktrace makes it hard to distinguish between foo.bar.x and foo.bar.test.x in some cases

17:30 but yeah... you should use clj-stacktrace

17:30 then it's not an issue

17:37 raek: yes, that convention was what I was looking for... thanks!

17:46 AWizzArd: blais: how is it going so far?

17:59 raek: ,(into {} (for [x ['() () nil], y ['() () nil]] [[x y] (= x y)]))

17:59 clojurebot: {[() ()] true, [() nil] false, [nil ()] false, [nil nil] true}

18:00 raek: ,(= [1 2 3] '(1 2 3))

18:00 clojurebot: true

18:00 raek: ,(= [] ())

18:00 clojurebot: true

18:00 raek: ,(= nil ())

18:00 clojurebot: false

18:00 raek: hrm

18:01 seancorfield: technomancy: i double-checked and i can't get my new leiningen task to show up in the basic task list / help - even tho' the task runs and lein help hello shows the correct doc stuff

18:02 technomancy: that's with 1.3.1 snapshot... should i send you the file?

18:33 alpheus: Having a little trouble getting protocols. I think a protocol establishes a set of function signatures, where the function chosen at runtime will be discriminated by the type of the first argument and the arity (where type is either a Java class or something set up by defrecord or deftype). Is that about right?

18:34 blais: Anyone having problems re-evaluating (ns) directives? I get this, for example: "spit already refers to: #'clojure.contrib.io/spit in namespace: merced.parser". Is there a workaround?

18:37 LauJensen: blais: That one is a true pain :( (:use [clojure.contrib [io :exclude [spit]]]) . I dont know why it simply doesn't give the warning

18:47 blais: Lau: thx, but it's still not happy.

18:47 I'll have to reboot by VM.

18:48 OH

18:48 Yes, I see.

18:48 Reboot VM, use with exclude. Ta-daa. Thanks,

19:07 pdk: ,(* 3 2.58)

19:07 clojurebot: 7.74

19:08 pdk: ,(* 2 2.58)

19:08 clojurebot: 5.16

19:09 pdk: ,(* 2 1.74)

19:09 clojurebot: 3.48

19:11 pdk: ,(+ (* 7 2.58) 2.44 (* 2 1.78))

19:11 clojurebot: 24.060000000000002

19:23 fielcabral: Hi all. Is there an easier way to do this? I want to write a function like this: (defn place-chooser [like-speed? like-type? not-banned?]

19:23 (fn [place] (and (when like-speed? (like-speed? place))

19:23 (when like-type? (like-type? place))

19:23 (when not-banned? (not-banned? place)))))


19:23 I want to return a function that and's the three preds.

19:24 but the three preds could be all nil

19:24 is there a way to combine them?

19:24 ssideris: how about using [& preds] as the parameter

19:24 and then iterate over the passed predicates

19:25 fielcabral: like a do kind of loop?

19:25 ssideris: it would not limit it to 3... but still

19:25 I suppose it would be a loop/recur

19:25 fielcabral: or apply?

19:26 i'll try that, thank you

19:42 brianstamand: (+ 1 2)

19:42 clojurebot: 3

19:45 chouser: fielcabral: in your example, nil for any of the preds means the fn will return nil, doesn't it?

19:45 brianstamand: Whenever I call .setForeground for a JLabel, or .setText, within a (proxy [ActionListener] the program actually runs as expected but the REPL returns a bunch of exceptions. Anyone know what is going on here?

19:46 Everything actually works just fine but when the ActionEvent occurs like 50 lines of Exception text scroll past in the REPL.

19:49 (def x "hello")

19:49 x

19:57 bortreb: I think clojure is just awesome :)

19:58 ,(+ 1 2)

19:58 clojurebot: 3

20:02 ssideris: brianstamand: not that I'll know the answer, but what kind of exceptions do you get?

20:06 brianstamand: ssideris: null pointer exception

20:06 It seems that I'm passing an empty list to java somewhere

20:07 and then clojure just prints the exception and keeps executing the code - so the code works fine but the exception stack trace is printed to the REPL

20:07 ssideris: yeah exceptions in general don't necessarily kill your program

20:09 brianstamand: I've been able to cause the exception to occur by doing, for instance, ((.setText convert-label "hello")). The extra parens cause it

20:10 Now I just have to figure out which parens are unnecessary in my original program :P

20:21 chouser: two open parens together is very rarely what you mean in clojure

20:30 brianstamand: chouser: yeah, I figured it out. I was under the impression that I had to pass the 2nd argument of (let) a single list. So I had an extra set of parens around all the stuff I wanted let to take. i.e. (let [x y] ((+ 1 2) (+2 3)))

20:30 The extra set of parens got passed to java as nil and threw the null pointer exception

20:36 dreish: `(foo {~@(range 10)}) throws an exception. Is there a better way to do that?

20:36 I got it: `(foo ~(apply hash-map (range 10))).

Logging service provided by n01se.net