#clojure log - Aug 07 2010

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

3:14 neotyk: ,(doseq [{a :a b :b :or {:a 1 :b 2}} #{{:a 3} {:b 4}}] (println a " " b))

3:14 clojurebot: nil 4 3 nil

3:14 neotyk: how do I get 1 4 3 2?

3:20 hiredman: you don't use keywords in the :or

3:20 ,(doseq [{a :a b :b :or {a 1 b 2}} #{{:a 3} {:b 4}}] (println a " " b))

3:20 clojurebot: 1 4 3 2

3:33 neotyk: hiredman: thank you

5:56 tomoj: any good blog articles about zippers?

7:34 defn: (doc dorun)

7:34 clojurebot: "([coll] [n coll]); When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. dorun can be used to force any effects. Walks through the successive nexts of the seq, does not retain the head and returns nil."

10:17 Bahman: Hi all!

10:25 raek: good morning, Bahman (SGT)

10:26 Bahman: Hi there raek!

10:26 What's SGT?

10:26 raek: standard greeting time

10:26 user joins => morning, user about to leave => night

10:26 Bahman: :-)

10:26 In fact, I'm joining at evening after work.

10:26 :-D

10:27 raek: yes, local time and greeting time can be very different :-)

10:29 Bahman: LOL Subtle explanation!

10:38 * raek just found http://nadeausoftware.com/articles/2008/02/java_tip_how_read_files_quickly

10:42 gfrlog: why can't I "use" a namespace created in the repl?

10:45 rhudson: I think the general answer is that use & require are designed for use in programs that are in multiple source files

10:45 gfrlog: okay

10:45 so for things loaded dynamically, "require" is implied, and "use" is done with "refer"?

10:46 * neotyk is thanking raek for sharing

10:46 rhudson: If use mean 'use is more or less 'require plus 'refer, yes

10:47 gfrlog: and a vanilla 'require does nothing but load a source file

10:47 okay

10:48 rhudson: Well, 'require also allows you to define an alias in the same step.

10:48 gfrlog: yeah

10:48 hmm

10:48 rhudson: If you say (require 'clojure.xml), you have to call clojure.xml/parse

10:48 gfrlog: right

10:48 rhudson: but (require '[clojure.xml :as xml]) lets you call 'xml/parse

10:48 gfrlog: yes

10:49 so if I wanted to dynamically load source strings that thought they were files and wanted to "require/use" each other....

10:49 I'd have to create my own 'ns macro?

10:49 to translate stuff to refer?

10:50 rhudson: If I follow what you're trying to do, yes

10:50 "each other" -- you can't have circular dependencies

10:51 gfrlog: right

10:51 raek: there is also 'alias for doing the :as part...

10:51 rhudson: right

10:51 gfrlog: you can't have circular dependencies in a traditional project structure either, right?

10:51 rhudson: right

10:51 gfrlog: okay

10:53 thanks

10:53 rhudson: you're welcome

10:54 raek: splitting up multimethod implementations into multiple files is a situation that can be tricky

10:54 gfrlog: is it possible to interrupt a repl computation without closing the repl?

10:54 Ctrl+C always closes my repl

10:55 raek: I often end up making a foo.bar root namespace, a foo.bar.common ns with the defmulti and some foo.bar.impl-x/y/z with the implementations

10:56 one approach could be to do the long computation in a future

10:57 (future (long-computation-is-looong))

10:57 and if you want to abort it, just do a (future-cancel *1)

11:06 gfrlog: interesting

11:08 raek: I guess it depends on what kind of time-consuming evals you do

11:09 gfrlog: man I'm having trouble with http.agent; I want it to try to connect to a port with nothing listening on it and return false or nil or something, but it just hangs on forever, even when I set both timeout values

11:10 raek: printing infinite seqs and circular structures can be limited by rebinding *print-length* and *print-level*

11:10 gfrlog: is that a buggy library? I've had trouble with it before

11:11 raek: I know there is a http://github.com/technomancy/clojure-http-client library that seems to be popular

11:11 contrib is not a *official* clojure library, just a collection of interesting things

11:11 gfrlog: right

11:12 it's nice to have good things in it though

11:12 rather than as separate projects

11:13 pdk: if it's a collection of interesting things then you have leeway to be fairly fast and loose with what you choose to include for users' convenience :p

11:15 raek: gfrlog: could your problem have something to do with exceptions in the agent?

11:16 gfrlog: I did get a connection time out error in the agent itself

11:16 but the contrib functions are responding strangely

11:16 like done? returns false

11:16 and the exception didn't come until 5 times longer than my timeouts specified

11:17 and error? throws the exception that the agent is holding

11:23 rhudson: Looks like you need to use 'agent-error (in clojure.core) to check for exceptions

11:24 gfrlog: yeah :( that doesn't solve the issue of not being able to control the timeout though

11:57 edbond: is there noop in enlive? I need to remove div#flash only if context map has :error key.

11:57 tried [:#flash] (if (context :error) nil) but it removed in either case.

11:59 end up with: [:#flash] (if-not (context :error) nil identity)

12:04 gfrlog: does clojure do any kind of uber-compiling that isn't available for dynamically loaded code? or are all methods of code-loading equivalent?

12:04 (assuming parse-time is negligible)

12:22 jlf`: technomancy: ping

12:23 gfrlog: how do I change the *some-value* type variables that some libs use for configuration?

12:23 I thought they were vars, which I thought meant using set!

12:23 but clearly I have no idea what's going on

12:25 perhaps 'binding?

12:25 rhudson: or 'with-bindings

12:27 gfrlog: I guess 'let could also work

12:28 raek: let will not work in that case

12:29 (def *x* 1) (def f [] *x*) (let [*x* 2] (f)) ; will return 1

12:29 replace let with binding and it will return 2

12:30 variables are always lexically scoped

12:30 but their values can be dynamically rebound

12:37 gfrlog: I see

12:37 thanks

12:47 daaku: is there a way to find out if there are updates available for a project's dependencies via lein?

14:05 jstirrell`: I'm kinda new at this whole linux thing... what's the easiest way to run a clojure function with cron?

14:09 would something like "*/1 * * * * ~/cljproject/lein repl && (namespace/function params)" work?

14:10 raek: you cannot pass input to the repl that way

14:11 you could use the more manual java -cp <jars> clojure.main -e '(namespace/function) (System/exit 0)'

14:11 dnolen: jstirrell: if you want a repl that supports eval from the command line you might wanna take a look at cake, you can do, cake eval "( ... )"

14:11 raek: maybe cljr or cake can run a file as a script without having to specify the classpath manually

14:12 jstirrell`: ok sweet thanks

14:13 raek: you can try to run the command in the terminal so see that everything works before writing it to the crontab

14:13 (edit your crontab with "crontab -e")

14:14 jstirrell`: k

14:14 raek: "~/cljproject/lein" will probably fail, unless you happen to have the lein executable in that directory

14:14 also, "(namespace/function params)" will fail, since it's not a shell command, but clojure code

14:15 jstirrell`: yeah that didn't seem right based on the cron examples I was looking at

14:15 raek: it might be easier to put it into a shell script, where you could set up the working directory etc

14:58 _na_ka_na_: hey guys the clojure compiler can't resolve circular dependencies - how the java compiler does ?

15:00 rhudson: Dunno, but you can use 'declare for forward references

15:02 _na_ka_na_: declaring is not working

15:02 Chousuke: don't do circular dependencies

15:02 _na_ka_na_: maybe I should declare and then require

15:02 rhudson: What are you trying to do?

15:02 raek: _na_ka_na_: dependencies between namespaces or vars?

15:02 declare is only ofr vars

15:04 _na_ka_na_: I have (ns b (:require c)) (defn fn-b [] 2) and (ns c (:require b)) (defn fn-c [] (b/fn-b))

15:04 trying to compile as .. java -cp lib\clojure-1.1.0.jar;src;classes clojure.main -e "(compile 'b)" .. fails

15:04 rhudson: You can't have circular dependencies between namespaces

15:05 _na_ka_na_: but if I have 2 useful namespaces and each wants to use other's fn then ?

15:06 rhudson: Then you need to refactor somehow

15:07 _na_ka_na_: is that because of some design principle/reason or just a limitation ?

15:08 rhudson: Not sure. But you can't really do that in Java either

15:08 _na_ka_na_: I just tried that and it worked

15:08 in Java

15:08 clojurebot: hmm… sounds like your out of heap space

15:10 _na_ka_na_: suppose you have a string ns with a super useful fn str and a math ns with a super useful fn + ... now can't it be possible that they need each other ?

15:11 raek: if the functions are that tightly dependent on each other. maybe they should be in the same namespace?

15:11 rhudson: Sure. Development can go like that. I've done it.

15:12 One thing to consider is taking something in the circle and putting it in a separate ns

15:16 Say function f is in ns a (because other things in a use it), a requires ns b, and you need to call f from somewhere in b. You can't have b require a. But you can put f in ns c, and have a and b both require c.

15:20 _na_ka_na_: Hmm I get that, but are circular dependencies bad ? Java takes care of them.

15:21 rhudson: I know in Java I've had situations where A and B seem to be fine in a circle, ... until I do a clean build.

15:23 I don't know what the technical issues and/or design rationales were in Clojure, but I do think having an acyclic dependency graph between ns's makes it easier to think about the structure of a project.

15:25 You can have mutual dependencies (e.g. mutually recursive functions) in a single ns, but then the dependencies are explicit, using 'declare or whatever.

15:27 _na_ka_na_: ok, guess I haven't come across some of the evils of circular deps yet

15:27 rhudson: thanks for taking time to answer

15:28 rhudson: sure

15:28 raek: I'm about to write a patch for clojure issue #404, which branch should I base it on? clojure/master?

15:29 (that is, http://github.com/clojure/clojure, branch master)

15:32 hrm, the 1.2.x branch seems to be more recently updated, I'm using that instead

15:36 edbond: can't get ring wrap-file to work? Any ideas?

15:54 mattikus: is emacs still the best editor/ide for clojure?

15:54 with criterion for best being generally most accepted and widely used?

15:55 tomoj: no

15:55 there was an anti-emacs revolt

15:55 mattikus: orly?

15:55 qbg: tomoj: When was this?

15:55 tomoj: I think most of the revolutionaries said that if you are already familiar with emacs, it's the best

15:56 but that we should not recommend emacs to new clojure users who aren't already familiar with it

15:56 and should try to avoid giving the impression that to really use clojure, you have to use emacs

15:56 but a majority of clojure users still use emacs, I think?

15:57 http://briancarper.net/blog/534/emacs-isnt-for-everyone

15:57 that revolutionary is actually an emacs user

15:57 raek: even though emacs possibly is the most used now, but I don't see any reason why vim, eclipse, intellij or netbeans shouldn

15:57 't be used

15:58 mattikus: i'm a vim guy, but i currently use emacs for my very infrequent clojure stuff

15:59 raek: I happen to like emacs, so that's why I use it. I use eclipse and vi frequently too, but I haven't done any clojure developing in those yet

16:00 qbg: CCW works, and is somewhat simple, but I feel Emacs is simpler

16:00 Maybe because I've used SLIME for so long

16:00 And my process isn't very advanced

16:01 raek: also, the project management and package management is done by tools outside the IDE (lein, cljr, cake) anyway, so I guess the issue's most about how you prefer to edit text

16:02 mattikus: right

16:02 are people focusing on lein?

16:02 qbg: lein is the current de facto standard

16:02 edbond: what for used clone-for in enlive?

16:02 raek: leiningen is great for projects (basically, when you have more than one source file)

16:03 cljr is great for when what you do is not a project

16:03 I've heard rumors that they might merge some day

16:04 mattikus: i havent heard of cljr

16:04 raek: cljr keeps a central repository of installed packages, leiningen keeps dependencies on a per project basis

16:04 which allows different projects to use different versions, etc

16:05 with cljr you don't need a project directory structure with a project.clj to start working

16:05 it makes clojure work more like python and ruby

16:06 if you want to use compojure, you just run "cljr install compojure"

16:06 you can also search for packages

16:07 then, you can easily start a repl with "cljr repl/swingrepl/swank", *in any directory*

16:07 and all the currently installed packages will be on the classpath

16:17 mattikus: anyone have experience clojure programming with viper mode?

16:24 raek: when running "ant test" on clojure 1.2.x adn master branches, a test in test_pretty.clj fails sporadically

17:04 dsantiago: I'm trying to import a Java class that is called Compiler (in its own library), and when I put that in an import statement, Clojure complains that "Compiler already refers to: class clojure.lang.Compiler." refer-clojure doesn't seem to let me fix this, is there something I can do about this?

17:07 qbg: Don't import it?

17:07 raek: (ns-unmap 'user 'Compiler) worked for me, but I don't know anything about the cause of the problem

17:07 dsantiago: Hm.

17:09 I guess I'll just not import it. It has a really long full name, though.

17:09 daaku: anyone know how to use setup/teardown in lazytest? i've got a Fixture with my setup/teardown functions with reify -- but i'm can't seem to figure out how to use it. i'd like for it to run for top level it/given calls inside a describe

17:09 raek: as you said, (:refer-clojure :exclude [Compiler]) doesn't seem to respect the user's wish

17:50 daaku: is there a form of into-array where i can specify what to cast the objects into? (i have a number of different objects which implement an interface, and the java counterpart needs an array of objects that implement the interface)

17:54 qbg: ,(class (into-array Comparable [1 2 3]))

17:54 clojurebot: [Ljava.lang.Comparable;

17:54 qbg: That seems to work

17:56 daaku: qbg: oh, cool. didn't realize that worked

18:41 raek: just sent in my first patch!

18:41 now I will get some sleep

19:13 kencausey: jweiss: Did you resolve http://paste.lisp.org/display/94280 ? I'm seeing that now

19:14 oops, my fault, bad project.clj

19:24 vIkSiT: hi all

19:25 anyone else face this problem with lein 1.2.0 and slime 20100404 : make client process failed: Connection refused, :name, SLIME Lisp, :buffer, nil, :host, 127.0.0.1, :service, 4005 ?

19:25 (this is with a lein swank inside the project dir)

19:36 kencausey: vIkSiT: You've confirmed there is actually something listening on 4005?

19:36 vIkSiT: kencausey, indeed. I actually swapped out 1.2.0-beta1 from project.clj to master-SNAPSHOT - and it seems to run fine

19:37 kencausey: I'm having problems getting this to work, but I've complicated it perhaps by running under cygwin. Slime won't install from elpa

19:37 vIkSiT: so I'm guessing there's some incompat b/w my setup and 1.2.0

19:37 *sigh*

19:37 kencausey: I'm too newbie to be much help I'm afraid

19:40 jarodluebbert: can someone tell me what this does to a function argument? [#^String arg]

19:40 gfrlog: that's a type hint

19:40 jarodluebbert: so it doesn't actually modify the argument?

19:40 gfrlog: it just tells the compiler what sort of argument you're expecting

19:40 for optimization

19:40 I don't think it has any functional effect

19:41 if I'm wrong about that, hopefully somebody else will jump in

19:41 jarodluebbert: hmm, thanks

19:41 gfrlog: np

19:43 jarodluebbert: I want to write a function that lists all files in a certain directory like (my-func "."). I'm using (File. dir) in the function but it's throwing an exception

19:43 sorry, this might be easier: http://gist.github.com/513330

19:56 lozh: what are you importing as ds?

19:56 ah, duck streams...

19:57 jarodluebbert: yeah, it's not the (File. dir) part that's throwing the exception, it's because there are directorys in the tree and duck-streams is trying to read the directory in as a file I think

19:57 so I need to recursively do this to read in all files in all sub-directories

20:26 lozh: That's right - not sure how read-lines copes with binary files, either

21:08 vIkSiT: hmm

21:08 in a function like this : http://paste.lisp.org/display/113305

21:08 only my last map statement gets executed.

21:08 any ideas on why?

21:11 rhudson: 'get-and-inseert-data is a function with side effects, I presume?

21:16 One likely issue is that 'map is a lazy function -- certainly in the first two maps, there's nothing to consume the sequence, so the sequence never gets generated.

21:17 wtetzner_: if you want the side effects executed, wrap your call to map with (dorun ...)

21:24 vIkSiT: oh right

21:24 rhudson, wtetzner_ - thanks for the suggestions, I think the dorun would work. and yes, get-... is a fn with side effects

21:24 btw

21:25 does anyone know how to stop/break a slime execution?

21:26 wtetzner_: try ^C

21:26 vIkSiT: no luck

21:37 hmm, so assuming I've got a -main function for a program, and I'd like to populate some global variables I represented by +myvar+ ..

21:37 would a let be the right way to do this?

Logging service provided by n01se.net