#clojure logs

2008-03-03

09:47middaycis clojure currently more as an experimental on in development language or it can it be used for practical use?
09:48rhickeyI think it's practical, but as the author I'm biased
09:49middayc:) well as the author you know the best where the focus is
09:50rhickeyit is in development, but most changes are for fixes, completeness, or new features, not experimentation
09:51middaycnice, I don't mind changes is language is still evolving
09:56middayccould I use something like LWJGL from clojure instead of java?
09:57rhickeyI don't see why not
09:57rhickeyalthough you can't target applets due to a Java restriction
09:59middaycgreat.. well opengl applets are very unstable anyway
09:59middaycI mean in regards to general public
10:01middaycI used java for some things and in the meantime I got consumed into these FP langs and paradigms .. now I would need to do some jvm related things but programming in java does not intrigue me that much
10:01middaycclojure seems very interesting from what I saw
10:02rhickeylisp + fp + JVM
10:02rhickey+ stm
10:05middaycOne use for java and lwjgl is for something like 2d action game... is clojure somewhere near java speedwise? I think I noticed somewhere groowy for example was quite slower at some tests (I think it was raytracing)
10:07rhickeyThe only place Clojure should be noticeably slower than Java is in numerics - all numbers are boxed in Clojure. But Clojure + a small Java vector lib should do the trick.
10:08middaycaha.. so I could write computational libs in java and use them in clojure
10:08rhickeyright
10:09middayccool :)
10:09Chouserrhickey: do you have an opinion on conditional forms that capture a name for the test result, like arc's aif, acond, etc.?
10:09Chouserdo you hate the idea?
10:09rhickeyanaphorics - I dislike them
10:10Chouserok
10:10rhickeyI will be adding if-let and when-let, which will take the name of the thing to be bound
10:10Chouserah! ok.
10:10Chouserso the source of the dislike is the unspecified name showing up in the enclosed block?
10:11rhickeyyes, they don't nest, cause problems for macros etc
10:11rhickeytoo cute
10:11Chouserwell, #() does that a bit now...
10:11Chouserwith similar problems, of course.
10:12rhickeyyes, and should be reserved for the simplest cases
10:12Chouserok
10:12rhickeynesting #() is bad style
10:12ChouserI'll be looking forward to when-let.
10:12Chouserwould a cond-let be too convoluted?
10:13rhickeyone name for all conditions or a name per condition?
10:14Chouserhm... I hadn't thought of one name for all. That might be quite nice.
10:14rhickeya lot of conditions are just boolean, not much to bind
10:14ChouserI was thinking one name per condition would be pretty wordy.
10:14Chouseryep, but isn't that generally true for all these (if-let, when-let, etc.)
10:16rhickeydepends on how you use cond
10:16Chouserthe syntax would be: (when-let bindform testexpr block) ?
10:16rhickeyyes
10:16ChouserI could probably write that... ;-)
10:16rhickey10 minutes tops
10:16ChouserOk, anyway, thanks for the discussion.
10:17ChouserNot sure about cond -- just poking around is all.
10:23Chouserhmph. doto just betrayed me. I can't think of any easy way to run one of two different methods inside a doto block (based on some test).
10:24ChouserI'll have to refactor into "let" and a bunch of (. foo blahs)
10:25rhickeyit would have to be more of a code walker to find . calls inside of ifs etc
10:26Chouseryep. more magic.
10:26ChouserIt just suggests perhaps I shouldn't have used doto at all.
10:26Chouserit seemed so nice at first. ;-)
10:26rhickeyprobably not
10:27ChouserI shouldn't complain, though. Making Java interop possible is hard enough. Demanding pretty is too much.
10:30arbschtclojure is reasonably pretty, even
10:31arbscht(I say that having used Foil :-)
10:33rhickeydoto is already more concise than the equivalent java
10:34rhickeybut I think the next level up is something like with-slots for Java objects
10:34rhickeynaming the object and its pieces
10:37ericthorsenRich: I've come across a couple of scenarios where I need to return iterators / enumerations on clojure seqs to a java framework.
10:37rhickeyall the collections are Iterable
10:37ericthorsenI wrote a simple wrapper that uses a ref to modify the state of a proxy since I always have to return the same reference back on the java side
10:37ericthorsenhmm...
10:38rhickeythere's also SeqIterator which turns any seq into an Iterator
10:38ericthorsenThat's much nicer of course...but I needed an Enumeration
10:39rhickeyfor what?
10:39ericthorsenit does bring up a general question about plugging java objects into existing frameworks implemented in clojure
10:39ericthorsenTreeNode.children returns an Enumeration
10:41rhickeyaargh - I wish they had gotten it right the first time
10:41ericthorseni know...
10:42rhickey2 'standard' iterators is silly
10:42rhickeyI can provide equivalent bridges to/from Enumeration
10:43ericthorsenit would be useful since everyone is going to come up against this
10:44ericthorsenIn cases where I'm handing off a java object to a framework that is expecting side effects to change the state of the object, the model would be to use references and transactions in the proxy yes?
10:48rhickeythat's one way.
10:49rhickeyit would allow those objects to participate in enclosing transactions
10:52rhickeySeqEnumeration is up
10:57ericthorsenthanks!
10:58ericthorsenwhat is another way ?
10:58ericthorsenno transactions?
10:59rhickeywithout transactions you devolve into Java's mutable state model, can just use clojure.lang.Box - don't call me with problems :)
10:59ericthorseni know that...that is why I asked what is another way? I did not think that is one you were referring to
11:01rhickeythat's pretty much it, safety or not, there's not really a per-thread-binding notion in normal Java objects, so no advantage of Var over Box
11:01ericthorsen...shy or storing the state somewhere else I mean...I'm fine with this option. I was just curious as to whether there was another option you had in mind for this scenario
11:01ericthorsenok
11:03rhickeyEnumerationSeq and support for Enumerations in seq is up
11:09Chouser(let [[foo bar] [1]]) --> java.lang.IndexOutOfBoundsException
11:09Chouserwas it silly for me to expect bar to be nil?
11:11rhickeyit is documented to use nth, which is documented to throw on out-of-bounds
11:11Chouserok
11:12rhickeyif you might have more stuff, you can use &
11:12Chouseryep, thanks.
11:13rhickey(let [[foo & [bar]] [1]] [foo bar])
11:13ChouserI have a cond-let working, with a single binding form. But so far I'm only using it like an "if", so I'm not sure yet if a single binding form makes sense in general or not.
11:13rhickey[1 nil]
11:13Chouseroh! fantastic.
11:15rhickeyfull destructuring is available for the & parameter
11:16Chousermakes sense, just not an idiom I had thought of. nice.
12:19arbschtdoes it make sense to define a multimethod with no args?
12:22arbschtwould it be too non-functional to have arbitrary dispatching functions rather than only functions of the args? as it is that's possible for args>0
14:20rhickeydispatching function of no args? does it call rand or something?
14:33arbschtor something
14:33arbschtlet's say it depends on a mutable variable
14:35arbschtthere's nothing stopping me defining a dispatching function with non-zero arity and ignoring the arguments to do something like that
14:36rhickeyor put an ordinary function in front of it, that reads var, passes something to multimethod
14:36arbschtright, that's how I've got it now
14:36rhickeyprobably easier for the next guy to understand that way
14:39arbschtmaybe. my first instinct was to try it with no-arg multimethods, but that might just be me
19:41rhickeysets are coming, any syntax preference:
19:41rhickey#[a b c]
19:42rhickey#{a b c}
19:42rhickeysomething else?
21:40ChouserRunning out of brackets... <a b c>
21:41rhickeystill haven't decided to take away <, >
21:41Chouseryeah.
21:42Chouser#[] isn't bad. # is starting get pretty diluted.
21:43rhickeyever used CL?
21:43Chouser[|a b c|]
21:43Chousernot really. I "learned" lisp in CL from "On Lisp", but never wrote more than a few functions in it.
21:43rhickeyI think the double chars are tricky for editors
21:43Chouserah, good point.
21:44ChouserI was thinking | suggests alternation which is sorta related to sets.
21:44Chouser|[ ]
21:44Chouseror maybe not.
21:46Chouser^[]
21:46rhickeyright now it's #{a b c}
21:47rhickey#[a b c] seemed to imply that nth would work, to me
21:49Chouserok
21:49Chouseralso (make-set a b c) or something?
21:49rhickeyhash-set, sorted-set, contains?, conj, disj, count etc
21:50rhickeyit's up now
21:51Chouserso fast. makes my head spin.
22:19albinoin python they had to go to a more literal translation set()
22:19albino{} for dictionarys [] for lists and () for tuples
23:22ChouserI'm so used to using hashes for that, I just forget to reach for sets.