#clojure logs

2008-06-13

03:58yrbcan anyone point me to some clojure source to reference when wrapping a java library
04:02slougii was pointed to parallel.clj yesterday. don't know if it's a good example.
04:02slougii have some code in user.clj, how can i get command line arguments?
05:35Chouser*command-line-args*
07:27yrbanyone have any ideas about what concepts would be valuable in a clojure gui toolkit
07:28blackdogi was looking at pivot yesterday a nice wrapper for that would be good
07:30blackdoghttp://weblogs.java.net/blog/gkbrown/archive/2008/06/introducing_piv.html
07:30yrbcool, I will take a look
07:31blackdogspecifing the xml as a clojure map instead would be good
07:42yrbyes using maps in place of their xml would be a huge improvement. The java community sure loves xml
07:49yrbI was thinking of doing a declaritive framework that leverages metadata to take care of rendering
07:49yrbsort of aimed towards rapid prototyping
08:01yrbrhickey: The screencasts are a brillant resource :). Any plans to do one focused on structuring data, and living without "objects"?
08:02rhickeyyrb: glad they are of use. Yes, I hope over time to cover some higher-level things
08:02blackdogthat
08:03blackdogthe move from objects to non objects would be useful for me too
08:05blackdogfor example, yesterday i was wondering if the namespace stuff would be better for containing all my swing var components rather than a map, e.g. ui-form1/list1
08:05blackdogui-form1/combo1
08:05blackdogwould that kind of structuring be good practice?
08:05rhickeywhat are list1, combo1?
08:06blackdoginstances of those objects
08:06blackdogswing components
08:07blackdogi'm sticking them in a map right now, but maybe using defs is better, i dunno
08:07blackdogmy point is, when not from functional land i'm not sure
08:08rhickeylet's say you have a widget that has a combo and list, if you put them in ns vars then creating a second instance of that widget will be a name clash
08:09yrbI think I would go with the map, just because it means you can walk it programmatically
08:09blackdogyes, but they are per form or per container,
08:09blackdogok
08:10blackdogok, i think i was heading in the direction of over using namespaces :)
08:18yrbrhickey: Would I be correct in saying that you look at objects more as state containers, rather than a way of encapsulating behavior?
08:20rhickeyI think CL generic functions were right to take methods out of classes
08:21yrband in clojure namespaces would be the way to encapsulate behavior?
08:21rhickeydata doesn't behave
08:21rhickeythings happen, and there might be new data
08:21rhickeythose things might involve multiple entities
08:21rhickeyno single one of which 'owns' the activity
08:22rhickeyso OO is kind of an oversimplification that gets in the way IMO
08:23rhickeysimilarly, I think associating behavior with at-birth types is another over simplification that gets in the way of modeling the way we think
08:24rhickeyin real world thinking we much more associate 'behavior' with state/attributes than types
08:24yrbI would have to agree that once you use multimethods/generic functions you don't want to go back to single dispatch
08:24rhickeydrunk is not a type
08:24rhickeybut people who are drunk walk differently
08:25rhickeysimilarly, no one is born a plumber or a painter
08:25Chouserzipper objects have behavior
08:25rhickeynot really
08:25rhickeythere is an open set of functions that may manipulate them
08:26rhickeyalso open to functions that manipulate them in combination with other things
08:26yrbI suppose this is why you see so many manager types in java....
08:27blackdogrhickey, in your gen-and-load-class example, you use a fred.lucy.Ethel namespace and then refer to a (in-ns 'fred.lucy.Ethel__2276) in the implementation, why the __2276?
08:28ChouserI'm referring to the functions stored in zipper vector objects metadata.
08:28blackdogrhickey, sorry gen-and-save-class
08:29rhickeyChouser: buts that's not behavior in the OO Zipper as a class way
08:29rhickeyit's a flexible system that makes behavior available as data, or dynamically etc
08:31yrbi think i see why structs are the way they are now
08:32ChouserI guess I'm not clear on the difference. Each zipper obj is a little bundle of instance data and type- (not class-, I just mean xml vs. vector etc.) -specific code.
08:33rhickeyblackdog: that's just left over testing cruft, not a real example. I used to have a gensym in there so I could test gen-and-load class without having to keep restarting
08:33blackdogok so usually i'd just do (in-ns 'fred.lucy.Ethel) and create the methods
08:34Chouserof course you also have type-independant functions that act as a more convenient API, but the methods (sorry, meta-data-stored functions) of the zipper objs form a public API of their own.
08:35rhickeyChouser: the difference is Clojure doesn't dictate that is the only way you can do 'behavior'. It's how I chose to do it for zippers. I'm not saying associating behavior with an object is always bad, just that dictating it is bad, tying it to types is bad, and not having other ways to model things is bad
08:36bpattisonso it's the degrees of freedom that's appealing Clojure and dynamic lanugages in general?
08:37rhickeylot's of dynamic languages follow the same OO line
08:37rhickeyCL generic functions are the exception
08:38rhickeythey too are somewhat stuck to types
08:38rhickeyalthough they support value dispatch
08:38yrbwell you are free to write your own restrictive OO system ;) that is the wonder of lisp
08:40ChouserI expect my first several large clojure projects will be examples of to take advantage of having enough rope to hang yourself.
08:40Chousers/of/of how/
08:40bpattisonbut doesn't having all that flexibility make it difficult to maintain large scale systems?
08:41blackdogi think rich talks about that in the videos, the contention is it's much easier to reason about functional programs and test them
08:41yrbyou can still drown in a tea cup ;)
08:42blackdogi still have to validate that :)
08:42bpattisonI'll go back and look at the videos
08:42ChouserThere appear to be several decisions baked into clojure that prevent modules from doing things that would make it impossible to include several foreign modules in the same project.
08:43Chouserafter that, it's just up to you to choose to write good code.
08:43rhickeybpattison: in many ways no, since a micro-abstraction that serves a small part of an app is easily described and has finite scope. Many people fail to realize how much complexity they bring in every time they say class X...
08:43rhickeyhttp://groups.google.com/group/clojure/msg/ab1b275a1ef8373f
08:45bpattisonhmmm, interesting ... I think that my biggest hang up in giving up type systems -- there's so many times I've changed abstract classes and the compiler has found all the other places that I need to change the code
08:46rhickeybpattison: that's a definite benefit to the straightjacket, I think providing similar refactoring for more dynamic/flexible systems is an area for exploration
08:47yrbrhickey: I think it would be good if there was a prominent link to that on the wiki
08:48rhickeygo for it :)
08:55yrbI must say having less restrictions is painful because now that I can do anything what do I do...
08:57yrbbut I know as I get to know the tools it is going allow me to express the design better
08:58blackdogbpattison, remeber you can add the type hints to clojure anyway and be as restrictive as you want
08:59rhickeybut I only use them for optimization, not enforcement
09:03ChouserThe set of designs that could be enforced with type hints is much smaller than the set of designs possible in clojure.
09:03bpattisonI guess my issue isn't enforcing types per se -- but being able to maintain code that some one else wrote 2 years ago -- but maybe type safety is the wrong approach to address code maintanability
09:04yrbrhickey: along those lines if you could maybe create some high level models with reasoning of a large application, like an architecture overview.
09:04rhickeythe set of things that types systems can enforce is much smaller than the set of things you need to get right in large systems over time
09:05rhickeynote that I do think this is an important area, just don't believe that types are the places to hang this stuff
09:06rhickeyconstraints, preconditions, rules, contracts
09:06yrbit would give me at least a jump start and orientation to start thinking
09:06rhickeyas with oo, many of these things cross entities
09:06rhickeyso attaching them to types is limiting
09:14yrbwhat was your motivating reason for metadata, considering the amount of flexibility you get through the use of maps?
09:15rhickeyyrb: funny you should mention that right now, one of the reasons was to provide a place to put the info one might need for constraints, preconditions, rules, contracts
09:16rhickeywithout it being mixed in with the information the app is processing
09:16rhickeyit really is 'meta'
09:20yrbthat is a good point it means the functions that touch the data don't have to know about the metadata
09:27yrbthough it seems like something that should be used more sparingly than I would typically associate with a "metadata" system, where you try to add as much as possible
09:35yrbsomething like contextL could be interesting in clojure
09:36rhickeythe fact that defn-ed fns can be dynamically rebound directly supports some context-like programming
12:03Lau_of_DKAm I the only one here having trouble with Blip.tv ?
12:04blackdogbeen ok for me
12:04Lau_of_DKAre you in Firefox?
12:04blackdogyes ff3 on ubuntu
12:05Lau_of_DKok.. Maybe its cause Im on ff2 - It crashes my sound system and if I fiddle with the window (position/size) it crashes Gnome
12:05Lau_of_DKAlmost like being back in Windows
12:06cgrandthere's a drop-down which enable you to download a .mov
12:13Lau_of_DKcgrand, thanks :) And btw the prime generator made perfect sense, its an impressive func
13:52Lau_of_DKQuestion
13:52Lau_of_DKuser> (rem-exacts "ABCD" "BBBB")
13:52Lau_of_DK(\A \x \C \D)
13:52Lau_of_DKuser> (apply str (rem-exacts "ABCD" "BBBB"))
13:52Lau_of_DK"AxCD"
13:53Lau_of_DKI in the defn (rem-exacts) I wrap the code in (apply str (...)) it still returns 4 char values, and not a string... why is there a difference if its wrapped in the function, or on the result?
13:56Chouser*whew* I'm so relieved that my meta-data can have meta-data.
13:57Chouser(def x (with-meta [] (with-meta {:is :meta} {:is :meta-meta})))
13:57Chouser^^x
13:58ChouserLau_of_DK: you'd have to paste rem-exacts for us to see the problem.
13:58Lau_of_DKChouser, here goes
13:59Lau_of_DK(defn rem-exacts
13:59Lau_of_DK ([guess] (rem-exacts code guess))
13:59Lau_of_DK ([code guess]
13:59Lau_of_DK (map (fn [c g]
13:59Lau_of_DK (if (= c g) \x c)) code guess)))
14:00Chouser(apply str (map ... )) should work
14:00Lau_of_DKThats what I was trying to explain: It doesnt
14:00Lau_of_DKIt still returns chars
14:00Lau_of_DKIf I do it IN the defn, I does not work, if I apply on the result, it works
14:01Lau_of_DKhmm
14:01Lau_of_DKand now it works - all I did was evaluate it again...
14:01Lau_of_DKhope its not a bug in the new Clojure release
14:03Lau_of_DKI had the same problem with another function, once evaluated the 3.rd or 4.th time, the REPL understood the changes.. And this happens directly after updating
14:11hoeckrevision 906 was broken on my machine, but 905 worked
14:12Lau_of_DKBroken, how?
14:12ChouserI had to clean and rebuild.
14:12Lau_of_DKI just checkout the latest SVN, built it, removed old directory and copied to that location
14:14hoeckLau_of_DK: weird Exception after starting clojure. But your rem-extracts function works fine under 905.
14:15hoeckoh, sorry, needed just a clean rebuild, thanks chouser for that hint.
14:20Lau_of_DKk :)
14:23grosourshi everybody
14:24Chouserhi
14:25grosours^^ hi specially to you the Chouser
14:25Chouser:-)
14:25grosours^the^then
14:25jgracinhi grosours
14:41Lau_of_DKhey jgracin & grosours :)
15:03jgracinhi Lau_of_DK. slow reflexes, watching soccer. :-)
15:06Lau_of_DKThats good man, soccers great for people with slow reflexes - 10 goals scored every year
15:28ed-t8hello, i am totally newb to clojure and java, can you call libs that you create in java in clojure?
15:29Chousered-t8: yes
15:29ed-t8I realise that there is the (. notation) to call classes which are already part of JVM
15:29ed-t8but what about classes that you want to create, say i want to create a form in java but call its methods from clojure, is that doable
15:29Chouserthat notation works for all Java classes in your classpath
15:29ed-t8oh right
15:30Chouserbut why do you want to create a form in Java? ;-)
15:30ed-t8because netbeans comes with a nice gui designer :)
15:31ed-t8is there a good IDE for clojure?
15:31ChouserActually, netbeans is probably your best bet. There's a plugin for it called enclojure.
15:31ed-t8yeah i've tried that but i can't figure out how to make .clj files the main class
15:32ed-t8i've also tried SLIME but that didn't seem to work very well
15:32ChouserI haven't used either of those enough to help you. sorry.
15:32ed-t8what do you use?
15:32Chouservim
15:33ed-t8argh
15:33Chouserand a REPL in an xterm
15:33blackdogi have a syntax mode for jedit
15:33ed-t8i'm more of an emacs used
15:33ed-t8user*
15:33blackdogand the beginnings of a repl
15:33ChouserI know people have gotten SLIME to work.
15:33dudleyfed-t8: The SLIME mode works pretty well for me
15:33ed-t8dudleyf: does it work for loading say a JFrame ?
15:34ed-t8dudleyf: i can get SLIME to work for basic clojure expressions, just not for anything that uses the JVM (for some strange reason)
15:34lisppaste8blackdog pasted "clojure with miglayout" at http://paste.lisp.org/display/62182
15:34dudleyfI've never tried gui stuff with it
15:34blackdoged-t8, i use clojure with miglayout for gui stuff
15:34blackdogit loooks a bit like the lisppaste there
15:35ed-t8blackdog: what is miglayout?
15:35blackdogi just found it last week, it's a layout manager
15:35blackdogbut it's very easy to use
15:36ed-t8nice, i would definitely rather use the netbeans gui designer though. :)
15:37blackdogno gui editor of course but i just got fed with 200mb going to netbeans
15:37blackdogi used to complain with 60mb going to jedit but now that's negligable :)
15:38ed-t8:D yeah it is quite large
15:38la_mered-t8: You can bootstrap a clojure app by just starting clojure with clojure.lang.Script as the main java class instead of the Repl, and then pass the path to your .clj file as an argument
15:39ed-t8la_mer: nice, can it handle multiple files?
15:39blackdogi think it does
15:40la_mered-t8: Sure, you can pass as many files as you want, if you can build your environment serially like that. There are some modules floating around (perhaps built in to clojure these days?) that will allow you to load in other files using (require 'foo) as well.
15:40blackdog(load-file 'foo)
15:41la_merSure, there's that, too. Wasn't someone working on a require mechanism?
15:41blackdogoh don't know
15:41blackdogwhat would the difference be?
15:41Chouserclojure-contrib lib.clj I think, but I still haven't looked at it.
15:42blackdoglike a require from a CLOJURE_LIBS env var or something?
15:42la_merblackdog: here's one reference of an implementation from March: http://groups.google.com/group/clojure/browse_frm/thread/7e30c97c0b31c11a
15:42blackdogthanks,
15:43blackdogthat's useful :)
15:46la_merI think Rich said at some point that some kind of require/provides mechanism would be rolled up into the core distribution (or at least a "blessed" contrib module), but I haven't kept track of developments there.
17:07lisppaste8Lau_of_DK pasted "Bug?" at http://paste.lisp.org/display/62190
17:07Lau_of_DKrhickey, can you look at that paste, I think it might be a bug
17:08rhickeywhat does 'blows up' mean/
17:08rhickey?
17:09Lau_of_DKIt means "Wrong number of args: PersistantVector", but I found the error, it was a sloppy naming of "score" in the args... :( Sorry.
17:09Lau_of_DKWould be sweet if the REPL could provide that sort of information, but I guess that impossible
17:18Lau_of_DKrhickey, note: That Java talk was really good, if advertised a little it should draw quite a crowd from Java/C# - All you need now is a few ShowMeDo videos where you code some cool stuff, and you're all set :)
17:18rhickeyall I need now is some more hours in a day :)
17:19Lau_of_DKyou're telling me :) There's definiately an addictive scent to Clojure, especially since this is the first time Im using functional style programming.
17:19Lau_of_DKAnyway, until we make that happen, try coffee
17:20Lau_of_DKA bit atypical for hackers, but alright, things change I guess :)
17:20Chouserjust made up a gallon of iced tea this morning. Should last a day or two.
17:24Lau_of_DKrhickey, speaking of time. How do you actually find the time to be so productive with Clojure - Is this your full time occupation?
17:27wybiralrhickey must realize that time is an illusion caused by believing in state. Much like functions, rhickey simply "exists" ...
17:27Chouserheh
17:29rhickeypart-time
17:36slavahow long have you been working on clojure?
17:37albinoahh, slava came here
17:40Lau_of_DKslava, I think he said 2 years active development and 4 years of dreaming about it
18:01Lau_of_DKif I need to do a (max (list 1 2 3)), how do I splice the list to evaluate the members, I suppose there's some sugar for it?
18:02ChouserNot sure what you mean. (max 1 2 3) and (apply max (list 1 2 3)) both work
18:02Lau_of_DKapply - thanks :)
18:38rhickeyslava: 3 years, released last fall
18:51Lau_of_DKuser> (count '((1 2 3) (1 2 3)))
18:51Lau_of_DK2
18:52Lau_of_DKIs there a version of disj or something, that will allow me to retrieve number of elements, in this case, 6
18:52Lau_of_DK?
18:56Lau_of_DKChouser, cgrand , anybody ?
18:57cgrandyou need to code a flatten function
18:57Lau_of_DKexactly
18:59Lau_of_DKDo you know whats available in Clojure?
19:00cgrandnot tested & going to bed: (defn flatten [x] (if (seq? x) (mapcat flatten x) (list x)))
19:01Lau_of_DKI'll fiddle with it, thanks, sleep tight :)
19:18albinoHas anyone tried to use the STM model from clojure in straight java?
19:20Lau_of_DKyou mean compared to gay java?
19:20Lau_of_DK(sorry bad joke)
19:20Lau_of_DKHow do you mean in straight java ?
19:20albinoI wasn't speaking of the sexual preference of the language :)
19:20albinoI mean without using the clojure language
19:21Lau_of_DKI havent, no. But why would you bother ?
19:22albinowell because a lot of programmers in the world don't like the syntax of lisp and only know java
19:22Lau_of_DKThats true
19:22albinoit was more of curriosity question, whether people had tried to import the clojure stm libraries and then made the right method calls
19:26JamesIryalbino, there are STM impls for Java that might have a more "natural" api for that language.
19:26albinoJamesIry: do you know if there are any which are being proposed as a default to be shipped with the jvm?
19:27JamesIryalbino: nope, not even close
19:28albinoJamesIry: thanks
19:28JamesIryalbino: STM isn't on the Java radar right now. I think Java 7 will have some new concurrency stuff with a fork/join style library that will be very nice and might be a good thing to add to Clojure
19:28blackdogit's in JamesIry
19:29JamesIryIt's in me?
19:29blackdogriich gas added an implementation of the fork join jsr
19:29JamesIryOh, cool!
19:29blackdogparallel.clj
19:30Lau_of_DKHas anyone here found an easy way to build a complex GUI in say Netbeans, and then drive it from Clojure ?
19:30blackdognopes, I'm using miglayout to layout my swing, it's quite easy
19:31Lau_of_DKmiglayout? Never heard of it
19:31blackdogi just heard about it last week, it's a layout manager, but it's designed for use from code, it's kind of css'ish
19:33Lau_of_DKHave you got a link and a Hellomiglayout tutorial?
19:34blackdogthis is the article i found about it first
19:34blackdoghttp://www.devx.com/Java/Article/38017
19:34JamesIryhttp://www.miglayout.com/
19:35Lau_of_DKBut do you then manually reformat that to the (. obj method) standard?
19:36blackdogyes,
19:36Lau_of_DKWhat I was trying to avoid :)
19:36blackdogi;ve nver done swing before, and I more or less have got what I wanted
19:36Lau_of_DKWould be sweet if I could visually build the whole thing, then import some class, and be done with it
19:36blackdogwithout thinking too much
19:36blackdogwhich was what i wanted :)
19:36Lau_of_DKhehe
19:36Lau_of_DKAlright blackdog , I'll have a closer look
19:38lisppaste8blackdog pasted "migpanel" at http://paste.lisp.org/display/62197
19:39Lau_of_DKLooks very easy - Considered doing a little lib as a User contrib to clojure ?
19:39lisppaste8blackdog pasted "moremig" at http://paste.lisp.org/display/62198
19:39Lau_of_DKDo I have to import anything other than javax.swing JPanel to get that working ?
19:40lisppaste8blackdog pasted "swing imports" at http://paste.lisp.org/display/62199
19:41Lau_of_DKblackdog - Have you got a .clj file with all these imports on common functions that I can see ?
19:42blackdogno, I just the basic JButton etc
19:42blackdogi only wrapped panel so i could set the title easil
19:43lisppaste8blackdog pasted "easy on the fingers" at http://paste.lisp.org/display/62200
19:52Lau_of_DKthanks blackdog, thats actually exactly what I need - its easy to customize
19:52blackdogcool,
19:52blackdogyea it's not too daunting
20:07fyuryublackdog: what is the purpose of the tilda in ~'actionPerformed in that macro? I know what ~ and ~@ are for but the quote puzzles me
20:08blackdogah, rich showed me that and said he would fix it
20:08blackdogbut it isn't yet as of todays new release
20:08blackdogit's something to do with how the proxy function finds varaibles
20:09blackdogbut apart fromthat I know no more,
20:09fyuryuaha, ok. Thanks
20:09blackdogit is a bug workaround AFAIK
20:54jcriteshey.... I was wondering if someone could give me a hint for how I would go about porting to or implementing the visitor pattern in clojure
20:55slavaclojure has multi-methods, so...
20:55jcritesoh, I don't need it then :)
20:55jcritesare they reflection-based?
20:55jcritesnot that I need performance for my application
21:03jcritesis it possible to create classes in Clojure that are visible to Java?
21:03blackdogthere's a gen-and-save-class function
21:03blackdoghaven't used it
21:04blackdoggenclass.clj
21:08slavather'es also 'implement'
21:08slavawhich allows you to create an anonymous implementation of an interface inline
21:08blackdogproxy now
21:08slavathat's a really neat feature
21:08blackdogthink implement was deprecated in favor of proxy - same thing
21:11jcriteshmmm I'm having trouble udnerstanding how to do things in Clojure; it's so different :)
21:11jcritesdoes it have something like a record type?
21:11jcriteswhat if I want a structure that represents a person, with a name and an age? how would I represent it?
21:12blackdogthe map i suppose but you can have a struct-map which is for space saving of records
21:12jcritesI could use a list, but then the semantics would depend on arbitrary ordering of the records, which is bad...
21:12blackdogif you have a look at resultset-seq it uses a struct map
21:12jcritesI'll take a look at it, thanks
21:14jcritesyup, struct maps look like what I want. thanks again! :-) so struct maps with functions that operate on them take the place of traditional Java classes?
21:15blackdogi'm just using resultset-seq as is can't comment further
21:16blackdogi'm not sure that oo is encouraged at all :) by rich anyway, he's quite down on it for data
21:17blackdoghere's a comment i snagged earlier today
21:17blackdog<rhickey> data doesn't behave
21:17blackdog<rhickey> things happen, and there might be new data
21:17blackdog<rhickey> those things might involve multiple entities
21:17blackdog<rhickey> no single one of which 'owns' the activity
21:17blackdog<rhickey> so OO is kind of an oversimplification that gets in the way IMO
21:17jcriteseveryone is certainly entitled to his opinion, especially a language designer :)
21:18blackdoghttp://clojure-log.n01se.net/date/2008-06-13.html
21:18blackdogfor more on typing and oo etc
21:24jcriteshmmm
21:25jcritesyou could imagine C-like structures with an inheritance model, providing an IS-A relationship, but with non-OO style operations on them (clojure-style :)
21:41pjb3is when-not different than if?
21:43pjb3ah, if has to have multiple arguments, never mind
21:50slavarhickey: a struct-map is essentially just an optimization right?
21:50rhickeyyes
21:51rhickeywhen you'll have lots of maps with the same fields/keys