#clojure logs

2008-04-11

11:13drewrIs there a built-in that tells me if an item in one sequence is in another?
11:13drewrIn Python, "1 in [1, 2, 3] => True"
11:13drewrSorry, ...if an item is in a sequence.
11:14abrooks(some? 1 '(1 2 3)) IIRC.
11:14abrooksGrr.
11:14abrooksThat's not the right name.
11:14abrooksHang on.
11:14rhickeydrewr: no there isn't
11:15drewrOK, it's trivial to write; just thought I'd ask.
11:15rhickeyClojure still missing CL's sequential find/member etc
11:15abrooks(some #(= 1 %) '(1 2 3)) was what I wanted. (But not what drewr wanted apparently.)
11:16ChouserArc'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:16Chouser(some? 1 [1 2 3]) would act like (some? #(= % 1) [1 2 3])
11:16abrookssome is "some" not "some?" I was wrong.
11:16rhickeyhow do they distinguish 'objects' and predicates?
11:17abrooksA predicate is a function always, right?
11:17rhickeyunless I'm looking for a function
11:17Chouserrhickey: I don't know how arc distiguishes. I can try to find out...
11:18abrooksWrap a function in a list/vector as a single item?
11:18ChouserWouldn't this suffice? (instance? Runnable x)
11:19rhickeyChouser: but what if I wanted to find a function, i.e. the value I'm looking for is a predicate?
11:19Chouseroh. excellent point.
11:19rhickey (some #{1} [1 2 3])
11:20rhickeyseems easy enough
11:20Chouseroh, nice!
11:21abrooksYeah, that's nifty.
11:21Chousersee, you have to tell people these things, rhickey. We're not smart enough to figure them out ourselves.
11:24drewrrhickey: So is nil the only false value?
11:25Chouseralsa 'false'
11:25Chouserer, 'false' is also false.
11:25drewrAh, thanks.
11:25abrooksI knew they were there at one brief point in time.
11:26cgrand"false" is the false to use for java interop
11:26Chouser"nil and false representing the values of logical falsity in conditional tests - anything else is logical truth"
11:31ChouserArc's 'some' converts its first argument using: (if (isa x 'fn) x [is _ x])
11:31ChouserI guess if you were looking for a function, you just can't use the shortcut.
11:32rhickeybleh
11:32Chouserheh
11:36drewrI can't figure out what I'm doing wrong here: http://paste.lisp.org/display/58981
11:36Chouserprobably just extra parens after #
11:37drewrChouser: Isn't #() synonomous with (fn [])?
11:38ChouserI think you want #(if (member? %2 b) (conj %1 %2) %1)
11:38ChouserThat would be the same as (fn [x y] (if (member? y b) (conj x y) x))
11:39drewrChouser: Ah! I totally missed that subtlety with the shortened syntax.
11:39Chouseryeah, I make that mistake a lot.
11:39drewrThis is why I'm actually *writing* Clojure instead of reading it.
11:40rhickey(defn items-in-common [a b]
11:40rhickey (filter (set a) b))
11:41drewr...and that's much nicer.
11:42rhickeyO(a + b) vs O(a*b)
11:42Chouseris that O(n log n) instead of O(n^2)?
11:42Chouseroh
11:43Chousersurely the lookups of b in (set a) take some time? log a?
11:43drewr;-)
11:45Chouser(set a) might be linear on a (is it really? not even log a?)
11:45abrooksA trie can naturally be accessed in order. I haven't looked at Riches implementations of sets but assume that they are tries.
11:46Chouser(filter * b) is linear on b * the set lookup operation, which can't be constant, can it?
11:47abrooksChouser: If both sets are ordered, it's a staggered walk O(a+b).
11:47abrooksActually, filter just uses conj doesn't it?
11:48Chouserfilter uses lazy-cons (boot.clj)
11:48abrooksOh, filter's in boot.clj
11:49Chouserbut 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:49rhickeyset lookup is effectively constant
11:50rhickeyditto hashmaps
11:50Chouserbecause it's a hash and not a binary tree of some sort?
11:50abrooksrhickey: It's order of trie depth, right?
11:50rhickeythe sorted versions are RB trees and thus logN
11:51abrooksrhickey: sort versions = sorted hashmap and what?
11:51Chouserabrooks: sorted-map
11:52rhickeytrie depth is so small as to be ignorable 6 for 1 billion items, 3 for 1 million
11:52Chouseroh, and sorted-set
11:52abrooksAh, sorted-set? Where is that? I only saw sorted-map (not hashmap I misspoke).
11:53Chouserabrooks: boot.clj. sorted-set is defined right after sorted-map
11:55abrooksOh, it's just not on the Data Structures page.
11:55abrooks... because sets are not on the Data Structures page.
11:55abrooks:)
11:55abrooksNo complaints. You're writing the language. We're all appreciative of that!
11:56Chouserrhickey: would you find it any easier to correct someone else's attempts at documenting things?
11:56Chouseror would you rather just do it yourself?
11:57rhickeydoes anyone else get the relational bits of set.clj without docs?
11:58rhickeye.g. that rels are sets of maps
11:58ChouserI think I understand it, but I haven't tried to use it, so I might be fooling myself.
12:01rhickeyChouser: 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:02rhickeybut 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:03Chouserrhickey: any reason there's no 'get' for sets?
12:03rhickeywhat's there to get?
12:04Chousertrue or false, I suppose.
12:04rhickeythey're not really associative
12:04Chouserok. 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:06ChouserI 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:07rhickeyIt could be, but then it would return the key, not true/false. I'm not opposed
12:08Chouserright, I hadn't realized set returned the key. I'm not asking for a change, just pondering things.
12:08ChouserI hadn't ever used 'get', just collections-as-functions and 'nth'
12:25ChouserWhat would be the Clojure equiv of this java? new Signal2<QImage, Double>()
12:26Chouser(new QSignalEmitter$Signal2) says No matching ctor found.
12:26rhickeyJust leave out the type params (new Signal2)
12:26Chouserhm.
12:26rhickeywhat is QSignalEmitter?
12:28ChouserI think what I'm trying to construct is actually com.trolltech.qt.QSignalEmitter$Signal2
12:29Chouserah, I have source code. public final class Signal2<A, B> extends AbstractSignal
12:30Chouserok, Signal2 is a class nested inside the class QSignalEmitter
12:31ChouserSignal2 definitely appears to have a constructor that takes no args.
12:37Chouseroh! A nested class constructor takes an instance of its containing class as its first argument?
12:38Chouserthat seems to have worked, anyway.
13:48ericthorsenrich: question on java completion in the editor...
13:49ericthorsenIn 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:50ericthorsenThe 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:51ericthorsenWe were thinking of making it part of the editor syntax where :
13:51rhickeyet: I'm running now, can you email?
13:51ericthorsenIf 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:51ericthorsenyes
14:02Chouserericthorsen: what kind of completion are you trying to do?
14:03ericthorsenWe are working on a NetBeans module for clojure....should have an alpha by the end of this month
14:03ericthorsenwe have been using it in house
14:03ericthorsenintegrated remote REPL, debugging, clojure and java completion, and the usual NetBeans language support stuff
14:03Chouserbut completion of what? (str <tab> ...produces what?
14:04Chouseryeah, I saw the announcment. Sounds ambitious. ;-)
14:05ericthorsenwhatever 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:05ericthorsen...and of course hippie completion
14:12Chouserok, cool.
14:33Chouserhow much of it have you been able to write in Clojure, or have you been trying?
14:34ericthorsenMost 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:35Chouserok. I'm looking at NetBeans for the first time.
14:35ericthorsenWe 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:35ericthorsenpretty amazing what comes out of the box
14:36ChouserIf I can extend it (add key bindings, etc. ...simple stuff) in Clojure, then I'll be pretty interested.
14:37ericthorseni'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:38ericthorsenthis is how we are writing the enclojure module...in clojure
14:39Chousersounds great.
14:39ericthorsenIt 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:39ericthorsenright now we are not adding any new features but just focusing on stability...something will be up before the end of April
14:40ChouserI've been a vimmer forever, and although the structure of emacs is interesting to me, its ancientness (and elisp) do not.
14:40ChouserI see there's a thing called jVi for NetBeans -- those plus clojure may be enough to move me off of vim.
14:40ericthorsenhard to get developers to move off their editors...:)
14:41Chouseryes, it is. I've tried really hard to use emacs, two or three times. Failed.
14:41ericthorsenI have high hopes of what I'm going to be able to do in my shop with clojure and NetBeans...very psyched
14:42Chouseris the idea of a "remote JVM" meant for like controlling a Java web server somewhere?
14:44ericthorsenthat'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:44ericthorsenSo the commands get sent to a remote JVM
14:45Chouserok, so not "remote machine" just a JVM that's independant of the editor.
14:46ericthorsenwe 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:46ericthorsenthat is correct
14:46ericthorsenalthough...it could be on a remote machine
14:47Chouserok. 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:48ericthorsenthx...u2