#clojure logs

2010-08-07

03:14neotyk,(doseq [{a :a b :b :or {:a 1 :b 2}} #{{:a 3} {:b 4}}] (println a " " b))
03:14clojurebotnil 4 3 nil
03:14neotykhow do I get 1 4 3 2?
03:20hiredmanyou don't use keywords in the :or
03:20hiredman,(doseq [{a :a b :b :or {a 1 b 2}} #{{:a 3} {:b 4}}] (println a " " b))
03:20clojurebot1 4 3 2
03:33neotykhiredman: thank you
05:56tomojany good blog articles about zippers?
07:34defn(doc dorun)
07:34clojurebot"([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:17BahmanHi all!
10:25raekgood morning, Bahman (SGT)
10:26BahmanHi there raek!
10:26BahmanWhat's SGT?
10:26raekstandard greeting time
10:26raekuser joins => morning, user about to leave => night
10:26Bahman:-)
10:26BahmanIn fact, I'm joining at evening after work.
10:26Bahman:-D
10:27raekyes, local time and greeting time can be very different :-)
10:29BahmanLOL Subtle explanation!
10:42gfrlogwhy can't I "use" a namespace created in the repl?
10:45rhudsonI think the general answer is that use & require are designed for use in programs that are in multiple source files
10:45gfrlogokay
10:45gfrlogso for things loaded dynamically, "require" is implied, and "use" is done with "refer"?
10:46rhudsonIf use mean 'use is more or less 'require plus 'refer, yes
10:47gfrlogand a vanilla 'require does nothing but load a source file
10:47gfrlogokay
10:48rhudsonWell, 'require also allows you to define an alias in the same step.
10:48gfrlogyeah
10:48gfrloghmm
10:48rhudsonIf you say (require 'clojure.xml), you have to call clojure.xml/parse
10:48gfrlogright
10:48rhudsonbut (require '[clojure.xml :as xml]) lets you call 'xml/parse
10:48gfrlogyes
10:49gfrlogso if I wanted to dynamically load source strings that thought they were files and wanted to "require/use" each other....
10:49gfrlogI'd have to create my own 'ns macro?
10:49gfrlogto translate stuff to refer?
10:50rhudsonIf I follow what you're trying to do, yes
10:50rhudson"each other" -- you can't have circular dependencies
10:51gfrlogright
10:51raekthere is also 'alias for doing the :as part...
10:51rhudsonright
10:51gfrlogyou can't have circular dependencies in a traditional project structure either, right?
10:51rhudsonright
10:51gfrlogokay
10:53gfrlogthanks
10:53rhudsonyou're welcome
10:54raeksplitting up multimethod implementations into multiple files is a situation that can be tricky
10:54gfrlogis it possible to interrupt a repl computation without closing the repl?
10:54gfrlogCtrl+C always closes my repl
10:55raekI 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:56raekone approach could be to do the long computation in a future
10:57raek(future (long-computation-is-looong))
10:57raekand if you want to abort it, just do a (future-cancel *1)
11:06gfrloginteresting
11:08raekI guess it depends on what kind of time-consuming evals you do
11:09gfrlogman 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:10raekprinting infinite seqs and circular structures can be limited by rebinding *print-length* and *print-level*
11:10gfrlogis that a buggy library? I've had trouble with it before
11:11raekI know there is a http://github.com/technomancy/clojure-http-client library that seems to be popular
11:11raekcontrib is not a *official* clojure library, just a collection of interesting things
11:11gfrlogright
11:12gfrlogit's nice to have good things in it though
11:12gfrlograther than as separate projects
11:13pdkif 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:15raekgfrlog: could your problem have something to do with exceptions in the agent?
11:16gfrlogI did get a connection time out error in the agent itself
11:16gfrlogbut the contrib functions are responding strangely
11:16gfrloglike done? returns false
11:16gfrlogand the exception didn't come until 5 times longer than my timeouts specified
11:17gfrlogand error? throws the exception that the agent is holding
11:23rhudsonLooks like you need to use 'agent-error (in clojure.core) to check for exceptions
11:24gfrlogyeah :( that doesn't solve the issue of not being able to control the timeout though
11:57edbondis there noop in enlive? I need to remove div#flash only if context map has :error key.
11:57edbondtried [:#flash] (if (context :error) nil) but it removed in either case.
11:59edbondend up with: [:#flash] (if-not (context :error) nil identity)
12:04gfrlogdoes clojure do any kind of uber-compiling that isn't available for dynamically loaded code? or are all methods of code-loading equivalent?
12:04gfrlog(assuming parse-time is negligible)
12:22jlf`technomancy: ping
12:23gfrloghow do I change the *some-value* type variables that some libs use for configuration?
12:23gfrlogI thought they were vars, which I thought meant using set!
12:23gfrlogbut clearly I have no idea what's going on
12:25gfrlogperhaps 'binding?
12:25rhudsonor 'with-bindings
12:27gfrlogI guess 'let could also work
12:28raeklet will not work in that case
12:29raek(def *x* 1) (def f [] *x*) (let [*x* 2] (f)) ; will return 1
12:29raekreplace let with binding and it will return 2
12:30raekvariables are always lexically scoped
12:30raekbut their values can be dynamically rebound
12:37gfrlogI see
12:37gfrlogthanks
12:47daakuis there a way to find out if there are updates available for a project's dependencies via lein?
14:05jstirrell`I'm kinda new at this whole linux thing... what's the easiest way to run a clojure function with cron?
14:09jstirrell`would something like "*/1 * * * * ~/cljproject/lein repl && (namespace/function params)" work?
14:10raekyou cannot pass input to the repl that way
14:11raekyou could use the more manual java -cp <jars> clojure.main -e '(namespace/function) (System/exit 0)'
14:11dnolenjstirrell: 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:11raekmaybe cljr or cake can run a file as a script without having to specify the classpath manually
14:12jstirrell`ok sweet thanks
14:13raekyou can try to run the command in the terminal so see that everything works before writing it to the crontab
14:13raek(edit your crontab with "crontab -e")
14:14jstirrell`k
14:14raek"~/cljproject/lein" will probably fail, unless you happen to have the lein executable in that directory
14:14raekalso, "(namespace/function params)" will fail, since it's not a shell command, but clojure code
14:15jstirrell`yeah that didn't seem right based on the cron examples I was looking at
14:15raekit 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:00rhudsonDunno, but you can use 'declare for forward references
15:02_na_ka_na_declaring is not working
15:02Chousukedon't do circular dependencies
15:02_na_ka_na_maybe I should declare and then require
15:02rhudsonWhat are you trying to do?
15:02raek_na_ka_na_: dependencies between namespaces or vars?
15:02raekdeclare 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_na_ka_na_trying to compile as .. java -cp lib\clojure-1.1.0.jar;src;classes clojure.main -e "(compile 'b)" .. fails
15:04rhudsonYou 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:06rhudsonThen you need to refactor somehow
15:07_na_ka_na_is that because of some design principle/reason or just a limitation ?
15:08rhudsonNot 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_na_ka_na_in Java
15:08clojurebothmm… 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:11raekif the functions are that tightly dependent on each other. maybe they should be in the same namespace?
15:11rhudsonSure. Development can go like that. I've done it.
15:12rhudsonOne thing to consider is taking something in the circle and putting it in a separate ns
15:16rhudsonSay 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:21rhudsonI 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:23rhudsonI 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:25rhudsonYou 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_na_ka_na_rhudson: thanks for taking time to answer
15:28rhudsonsure
15:28raekI'm about to write a patch for clojure issue #404, which branch should I base it on? clojure/master?
15:29raek(that is, http://github.com/clojure/clojure, branch master)
15:32raekhrm, the 1.2.x branch seems to be more recently updated, I'm using that instead
15:36edbondcan't get ring wrap-file to work? Any ideas?
15:54mattikusis emacs still the best editor/ide for clojure?
15:54mattikuswith criterion for best being generally most accepted and widely used?
15:55tomojno
15:55tomojthere was an anti-emacs revolt
15:55mattikusorly?
15:55qbgtomoj: When was this?
15:55tomojI think most of the revolutionaries said that if you are already familiar with emacs, it's the best
15:56tomojbut that we should not recommend emacs to new clojure users who aren't already familiar with it
15:56tomojand should try to avoid giving the impression that to really use clojure, you have to use emacs
15:56tomojbut a majority of clojure users still use emacs, I think?
15:57tomojhttp://briancarper.net/blog/534/emacs-isnt-for-everyone
15:57tomojthat revolutionary is actually an emacs user
15:57raekeven though emacs possibly is the most used now, but I don't see any reason why vim, eclipse, intellij or netbeans shouldn
15:57raek't be used
15:58mattikusi'm a vim guy, but i currently use emacs for my very infrequent clojure stuff
15:59raekI 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:00qbgCCW works, and is somewhat simple, but I feel Emacs is simpler
16:00qbgMaybe because I've used SLIME for so long
16:00qbgAnd my process isn't very advanced
16:01raekalso, 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:02mattikusright
16:02mattikusare people focusing on lein?
16:02qbglein is the current de facto standard
16:02edbondwhat for used clone-for in enlive?
16:02raekleiningen is great for projects (basically, when you have more than one source file)
16:03raekcljr is great for when what you do is not a project
16:03raekI've heard rumors that they might merge some day
16:04mattikusi havent heard of cljr
16:04raekcljr keeps a central repository of installed packages, leiningen keeps dependencies on a per project basis
16:04raekwhich allows different projects to use different versions, etc
16:05raekwith cljr you don't need a project directory structure with a project.clj to start working
16:05raekit makes clojure work more like python and ruby
16:06raekif you want to use compojure, you just run "cljr install compojure"
16:06raekyou can also search for packages
16:07raekthen, you can easily start a repl with "cljr repl/swingrepl/swank", *in any directory*
16:07raekand all the currently installed packages will be on the classpath
16:17mattikusanyone have experience clojure programming with viper mode?
16:24raekwhen running "ant test" on clojure 1.2.x adn master branches, a test in test_pretty.clj fails sporadically
17:04dsantiagoI'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:07qbgDon't import it?
17:07raek(ns-unmap 'user 'Compiler) worked for me, but I don't know anything about the cause of the problem
17:07dsantiagoHm.
17:09dsantiagoI guess I'll just not import it. It has a really long full name, though.
17:09daakuanyone 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:09raekas you said, (:refer-clojure :exclude [Compiler]) doesn't seem to respect the user's wish
17:50daakuis 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:54qbg,(class (into-array Comparable [1 2 3]))
17:54clojurebot[Ljava.lang.Comparable;
17:54qbgThat seems to work
17:56daakuqbg: oh, cool. didn't realize that worked
18:41raekjust sent in my first patch!
18:41raeknow I will get some sleep
19:13kencauseyjweiss: Did you resolve http://paste.lisp.org/display/94280 ? I'm seeing that now
19:14kencauseyoops, my fault, bad project.clj
19:24vIkSiThi all
19:25vIkSiTanyone 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:25vIkSiT(this is with a lein swank inside the project dir)
19:36kencauseyvIkSiT: You've confirmed there is actually something listening on 4005?
19:36vIkSiTkencausey, indeed. I actually swapped out 1.2.0-beta1 from project.clj to master-SNAPSHOT - and it seems to run fine
19:37kencauseyI'm having problems getting this to work, but I've complicated it perhaps by running under cygwin. Slime won't install from elpa
19:37vIkSiTso I'm guessing there's some incompat b/w my setup and 1.2.0
19:37vIkSiT*sigh*
19:37kencauseyI'm too newbie to be much help I'm afraid
19:40jarodluebbertcan someone tell me what this does to a function argument? [#^String arg]
19:40gfrlogthat's a type hint
19:40jarodluebbertso it doesn't actually modify the argument?
19:40gfrlogit just tells the compiler what sort of argument you're expecting
19:40gfrlogfor optimization
19:40gfrlogI don't think it has any functional effect
19:41gfrlogif I'm wrong about that, hopefully somebody else will jump in
19:41jarodluebberthmm, thanks
19:41gfrlognp
19:43jarodluebbertI 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:43jarodluebbertsorry, this might be easier: http://gist.github.com/513330
19:56lozhwhat are you importing as ds?
19:56lozhah, duck streams...
19:57jarodluebbertyeah, 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:57jarodluebbertso I need to recursively do this to read in all files in all sub-directories
20:26lozhThat's right - not sure how read-lines copes with binary files, either
21:08vIkSiThmm
21:08vIkSiTin a function like this : http://paste.lisp.org/display/113305
21:08vIkSiTonly my last map statement gets executed.
21:08vIkSiTany ideas on why?
21:11rhudson'get-and-inseert-data is a function with side effects, I presume?
21:16rhudsonOne 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:17wtetzner_if you want the side effects executed, wrap your call to map with (dorun ...)
21:24vIkSiToh right
21:24vIkSiTrhudson, wtetzner_ - thanks for the suggestions, I think the dorun would work. and yes, get-... is a fn with side effects
21:24vIkSiTbtw
21:25vIkSiTdoes anyone know how to stop/break a slime execution?
21:26wtetzner_try ^C
21:26vIkSiTno luck
21:37vIkSiThmm, 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:37vIkSiTwould a let be the right way to do this?