#clojure log - Apr 11 2008

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

11:13 drewr: Is there a built-in that tells me if an item in one sequence is in another?

11:13 In Python, "1 in [1, 2, 3] => True"

11:13 Sorry, ...if an item is in a sequence.

11:14 abrooks: (some? 1 '(1 2 3)) IIRC.

11:14 Grr.

11:14 That's not the right name.

11:14 Hang on.

11:14 rhickey: drewr: no there isn't

11:15 drewr: OK, it's trivial to write; just thought I'd ask.

11:15 rhickey: Clojure still missing CL's sequential find/member etc

11:15 abrooks: (some #(= 1 %) '(1 2 3)) was what I wanted. (But not what drewr wanted apparently.)

11:16 Chouser: Arc's solution is to allow some high-order functions to take an object instead of a predicate, and assume you want the predicate to be equality.

11:16 (some? 1 [1 2 3]) would act like (some? #(= % 1) [1 2 3])

11:16 abrooks: some is "some" not "some?" I was wrong.

11:16 rhickey: how do they distinguish 'objects' and predicates?

11:17 abrooks: A predicate is a function always, right?

11:17 rhickey: unless I'm looking for a function

11:17 Chouser: rhickey: I don't know how arc distiguishes. I can try to find out...

11:18 abrooks: Wrap a function in a list/vector as a single item?

11:18 Chouser: Wouldn't this suffice? (instance? Runnable x)

11:19 rhickey: Chouser: but what if I wanted to find a function, i.e. the value I'm looking for is a predicate?

11:19 Chouser: oh. excellent point.

11:19 rhickey: (some #{1} [1 2 3])

11:20 seems easy enough

11:20 Chouser: oh, nice!

11:21 abrooks: Yeah, that's nifty.

11:21 Chouser: see, you have to tell people these things, rhickey. We're not smart enough to figure them out ourselves.

11:21 * abrooks makes another note for the Practical Clojure book.

11:24 drewr: rhickey: So is nil the only false value?

11:25 Chouser: alsa 'false'

11:25 er, 'false' is also false.

11:25 drewr: Ah, thanks.

11:25 * abrooks had entirely forgotten about sets in Clojure.

11:25 abrooks: I knew they were there at one brief point in time.

11:26 cgrand: "false" is the false to use for java interop

11:26 Chouser: "nil and false representing the values of logical falsity in conditional tests - anything else is logical truth"

11:31 Arc's 'some' converts its first argument using: (if (isa x 'fn) x [is _ x])

11:31 I guess if you were looking for a function, you just can't use the shortcut.

11:32 rhickey: bleh

11:32 Chouser: heh

11:36 drewr: I can't figure out what I'm doing wrong here: http://paste.lisp.org/display/58981

11:36 Chouser: probably just extra parens after #

11:37 drewr: Chouser: Isn't #() synonomous with (fn [])?

11:38 Chouser: I think you want #(if (member? %2 b) (conj %1 %2) %1)

11:38 That would be the same as (fn [x y] (if (member? y b) (conj x y) x))

11:39 drewr: Chouser: Ah! I totally missed that subtlety with the shortened syntax.

11:39 Chouser: yeah, I make that mistake a lot.

11:39 drewr: This is why I'm actually *writing* Clojure instead of reading it.

11:40 rhickey: (defn items-in-common [a b]

11:40 (filter (set a) b))

11:41 drewr: ...and that's much nicer.

11:42 rhickey: O(a + b) vs O(a*b)

11:42 Chouser: is that O(n log n) instead of O(n^2)?

11:42 oh

11:43 surely the lookups of b in (set a) take some time? log a?

11:43 * drewr realizes that learning three paradigms at once is rather challenging (i.e., Java, Lisp, FP)

11:43 drewr: ;-)

11:45 Chouser: (set a) might be linear on a (is it really? not even log a?)

11:45 abrooks: A trie can naturally be accessed in order. I haven't looked at Riches implementations of sets but assume that they are tries.

11:46 Chouser: (filter * b) is linear on b * the set lookup operation, which can't be constant, can it?

11:47 abrooks: Chouser: If both sets are ordered, it's a staggered walk O(a+b).

11:47 Actually, filter just uses conj doesn't it?

11:48 * abrooks checks set.clj

11:48 Chouser: filter uses lazy-cons (boot.clj)

11:48 abrooks: Oh, filter's in boot.clj

11:49 Chouser: but the set object built by (set a) isn't going to keep track of where it was last accessed, to allow a staggered walk, right? It'll have to do a fresh lookup from scratch for each item from b.

11:49 rhickey: set lookup is effectively constant

11:50 ditto hashmaps

11:50 Chouser: because it's a hash and not a binary tree of some sort?

11:50 abrooks: rhickey: It's order of trie depth, right?

11:50 rhickey: the sorted versions are RB trees and thus logN

11:51 abrooks: rhickey: sort versions = sorted hashmap and what?

11:51 Chouser: abrooks: sorted-map

11:52 rhickey: trie depth is so small as to be ignorable 6 for 1 billion items, 3 for 1 million

11:52 Chouser: oh, and sorted-set

11:52 abrooks: Ah, sorted-set? Where is that? I only saw sorted-map (not hashmap I misspoke).

11:53 * abrooks fell in love with tries when he fell in love with Judy (...arrays).

11:53 Chouser: abrooks: boot.clj. sorted-set is defined right after sorted-map

11:55 abrooks: Oh, it's just not on the Data Structures page.

11:55 ... because sets are not on the Data Structures page.

11:55 * rhickey needs to document sets

11:55 abrooks: :)

11:55 No complaints. You're writing the language. We're all appreciative of that!

11:56 Chouser: rhickey: would you find it any easier to correct someone else's attempts at documenting things?

11:56 or would you rather just do it yourself?

11:57 rhickey: does anyone else get the relational bits of set.clj without docs?

11:58 e.g. that rels are sets of maps

11:58 Chouser: I think I understand it, but I haven't tried to use it, so I might be fooling myself.

12:01 rhickey: Chouser: probably wouldn't take less time to correct than to write, unless it was really solid coming in, at least for the reference docs...

12:02 but the Wiki is a good place to take a crack at explaining it until I get around to it - if it's good I'll build on it

12:03 Chouser: rhickey: any reason there's no 'get' for sets?

12:03 rhickey: what's there to get?

12:04 Chouser: true or false, I suppose.

12:04 rhickey: they're not really associative

12:04 Chouser: ok. that's good enough. I mean, I don't really need get for hashes or vectors either, since I can use them as functions.

12:06 I guess I would have assumed that (get foo x) would be the same as (foo x) for sets, just like it is for hash and vector. no biggie at all.

12:07 rhickey: It could be, but then it would return the key, not true/false. I'm not opposed

12:08 Chouser: right, I hadn't realized set returned the key. I'm not asking for a change, just pondering things.

12:08 I hadn't ever used 'get', just collections-as-functions and 'nth'

12:25 What would be the Clojure equiv of this java? new Signal2<QImage, Double>()

12:26 (new QSignalEmitter$Signal2) says No matching ctor found.

12:26 rhickey: Just leave out the type params (new Signal2)

12:26 Chouser: hm.

12:26 rhickey: what is QSignalEmitter?

12:28 Chouser: I think what I'm trying to construct is actually com.trolltech.qt.QSignalEmitter$Signal2

12:29 ah, I have source code. public final class Signal2<A, B> extends AbstractSignal

12:30 ok, Signal2 is a class nested inside the class QSignalEmitter

12:31 Signal2 definitely appears to have a constructor that takes no args.

12:37 oh! A nested class constructor takes an instance of its containing class as its first argument?

12:38 that seems to have worked, anyway.

13:48 ericthorsen: rich: question on java completion in the editor...

13:49 In order for us to do the java completion in the editor we would have to have a clojure type hint or a compiled function.

13:50 The compiled clojure is not practical (partially defeats the purpose od having completion) and the hints will cause people to have noise in the code

13:51 We were thinking of making it part of the editor syntax where :

13:51 rhickey: et: I'm running now, can you email?

13:51 ericthorsen: If you use a clojure type hint, we would use that, else we would give you a way to give a type hint that would not wind up in the source....any thoughts?

13:51 yes

14:02 Chouser: ericthorsen: what kind of completion are you trying to do?

14:03 ericthorsen: We are working on a NetBeans module for clojure....should have an alpha by the end of this month

14:03 we have been using it in house

14:03 integrated remote REPL, debugging, clojure and java completion, and the usual NetBeans language support stuff

14:03 Chouser: but completion of what? (str <tab> ...produces what?

14:04 yeah, I saw the announcment. Sounds ambitious. ;-)

14:05 ericthorsen: whatever we can....we can do completion on namespaces and java types...there is also a code browser that lets you see all the current clojure bindings in your VM

14:05 ...and of course hippie completion

14:12 Chouser: ok, cool.

14:33 how much of it have you been able to write in Clojure, or have you been trying?

14:34 ericthorsen: Most of it...the one issue we are up against is the nature of NetBeans using static Java classes to do their SPI/API mappings

14:35 Chouser: ok. I'm looking at NetBeans for the first time.

14:35 ericthorsen: We are close to having a static java wrapper for a clojure proxy...I'll put it up in the contrib when it's baked

14:35 pretty amazing what comes out of the box

14:36 Chouser: If I can extend it (add key bindings, etc. ...simple stuff) in Clojure, then I'll be pretty interested.

14:37 ericthorsen: i'm sure is has a key binding mechanism in Netbeans but we have also made the REPL in a way that you can run commands locally (in the JVM that NetBeans is running)

14:38 this is how we are writing the enclojure module...in clojure

14:39 Chouser: sounds great.

14:39 ericthorsen: It will be off by default, but you can set it in the preferences to enable a checkbox to execute commands in the local JVM or the remote REPL...it's a fun way to develop

14:39 right now we are not adding any new features but just focusing on stability...something will be up before the end of April

14:40 Chouser: I've been a vimmer forever, and although the structure of emacs is interesting to me, its ancientness (and elisp) do not.

14:40 I see there's a thing called jVi for NetBeans -- those plus clojure may be enough to move me off of vim.

14:40 ericthorsen: hard to get developers to move off their editors...:)

14:41 Chouser: yes, it is. I've tried really hard to use emacs, two or three times. Failed.

14:41 ericthorsen: I have high hopes of what I'm going to be able to do in my shop with clojure and NetBeans...very psyched

14:42 Chouser: is the idea of a "remote JVM" meant for like controlling a Java web server somewhere?

14:44 ericthorsen: that's a separate issue...part of the enclojure module is written in clojure but you do not want to execute you clojure commands within the JVM of your IDE.

14:44 So the commands get sent to a remote JVM

14:45 Chouser: ok, so not "remote machine" just a JVM that's independant of the editor.

14:46 ericthorsen: we are thinking of allowing a remote REPL per NetBeans group so you can work against multiple running VMs for different groups but I'll want to get more feedbac from experienced NetBeans folks and users before moving ahead there

14:46 that is correct

14:46 although...it could be on a remote machine

14:47 Chouser: ok. Well, if I can get netbeans and jvi working happily enough, then I'll be very excited to try out enclojure. Keep it up!

14:48 ericthorsen: thx...u2

17:15 * drewr hates his imperative mind

Logging service provided by n01se.net