2011-09-05
| 00:30 | srid | how do I tell `(sh ...)` to print everything to stdout/stderr (parent process's file handles)? http://richhickey.github.com/clojure-contrib/shell-out-api.html -- I'm trying to use this in cake tasks, and it seems silly to buffer the output of a long running command. |
| 00:36 | Tcepsa | srid: Seems like (binding ...) might be able to help, but that's really just a guess... |
| 01:07 | amcnamara | srid: I believe you can pass *out* to sh's in keyword, something along the lines of (sh :out *out*) |
| 01:07 | amcnamara | http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/*out* |
| 01:07 | amcnamara | err, out keyword |
| 01:30 | amcnamara | how can I extend a type to be callable? clojure.lang.IFn isn't a protocol |
| 01:33 | ambrosebs_ | clojure.lang.IFn has "invoke" |
| 01:33 | ambrosebs_ | hmm |
| 01:34 | ambrosebs_ | not a protocol? |
| 01:34 | amcnamara | nope, its an interface |
| 01:37 | ambrosebs_ | tried something like this? https://github.com/clojure/core.match/blob/master/src/main/clojure/clojure/core/match/core.clj#L636 |
| 01:38 | ambrosebs_ | I wasn't aware that IFn was an interface, but I think that works |
| 01:38 | ambrosebs_ | has IFn changed for 1.3? |
| 01:46 | amcnamara | interfaces can only be used (protocols may be used here as well) when initially defining a type, if extending an existing type only protocols may be used |
| 01:46 | amcnamara | from my understanding this is due to something called the expression problem |
| 01:47 | ambrosebs_ | amcnamara: ah I see |
| 01:47 | ambrosebs_ | that makes sense |
| 01:48 | ambrosebs_ | doesn't sounds possible |
| 01:48 | amcnamara | :( |
| 01:48 | ambrosebs_ | :( |
| 02:03 | amalloy | amcnamara: you can't cause an already-existing type to become callable as a function |
| 02:03 | amcnamara | bummer |
| 02:04 | amalloy | what type do you want to call, anyway? |
| 02:04 | amcnamara | more of a thought experiment |
| 02:05 | amcnamara | I was trying to extend strings to be functions of map keys |
| 02:05 | amcnamara | ("a" {"a" 1}) -> 1 |
| 02:05 | amcnamara | keyword-like |
| 02:07 | amalloy | if you're curious, you can't do this because it would be a performance disaster |
| 02:07 | amalloy | to make IFn a protocol |
| 02:08 | amcnamara | understandable, would be neat if there were a protocol equivalent though |
| 02:08 | amcnamara | PFn |
| 02:10 | amalloy | amcnamara: i have great news for you. you can write PFn yourself, and use it yourself! :P |
| 02:11 | amcnamara | I wouldn't even know where to start digging around the evaluator |
| 02:21 | amcnamara | amalloy: curiously, do you know why IFn has so many prototypes? |
| 02:21 | amalloy | ugh |
| 02:21 | amalloy | so that we can pretend to java that we're statically-typed |
| 02:22 | amcnamara | interesting |
| 02:22 | amalloy | (anyway, performance, basically. there can't really be any other excuse for code like that) |
| 02:22 | amcnamara | yeah, looking at the code for keyword, very tedious |
| 02:23 | amalloy | that's weird. i wonder why Keyword doesn't extend AFn, which should hide away that nonsense |
| 02:26 | amcnamara | perhaps so that keywords can't be apply'd |
| 02:30 | amcnamara | the applyhelper in AFn is also pretty nasty |
| 04:06 | dbushenko | hi all! |
| 04:19 | TheMoonMaster | Is penumbra dead? |
| 04:20 | khaliG | hm fleetdb embedded allows duplicates between sessions.. weird |
| 04:24 | michaelr525 | hey!! |
| 04:25 | khaliG | michaelr525, hey |
| 04:26 | michaelr525 | what's up in clojure land? |
| 04:27 | michaelr525 | :) |
| 04:30 | khaliG | hm nm, I was using init-persistent rather than load-persistent |
| 04:57 | amcnamara | 5am, time for bed. night all. |
| 05:20 | robermann | have you any news about "SICP in Clojure" project? According to its status (http://sicpinclojure.com/?q=content/current-status) it seems quite dead... |
| 05:20 | squidz | Why should I choose clojure over scala when scala has static typing, which is for me a plus |
| 05:21 | squidz | and if sicp-clojure is dying, that is also bad, as I wanted to learn clojure and sicp at the same time :( |
| 05:22 | michaelr525 | hehe |
| 05:23 | michaelr525 | squidz: dynamic typing is much better imho |
| 05:24 | squidz | michaelr525: why is that? I am a java programmer so I am used to it. Plus i think it could provide performance and quality improvements |
| 05:25 | michaelr525 | squidz: you can learn clojure and sicp even better by continuing the project yourself |
| 05:25 | squidz | michaelr525: That's an idea |
| 05:25 | michaelr525 | squidz: well, i am a programmer of many languages and i preffer dynamic typing |
| 05:26 | squidz | why? |
| 05:26 | clojurebot | squidz: because you can't handle the truth! |
| 05:26 | michaelr525 | can you? |
| 05:26 | squidz | not sure |
| 05:26 | squidz | blow my socks off |
| 05:27 | michaelr525 | well, types always get in your way instead of helping you. that's my experience |
| 05:27 | Chousuke | the problem isn't just having static typing or not having it. |
| 05:27 | squidz | Chousuke: ... go on... |
| 05:28 | Chousuke | Rich has several times expressed interest in a predicate-based "type" system for Clojure. Of course, such a thing is far from easy to implement as it must be completely optional |
| 05:28 | michaelr525 | what's that? |
| 05:28 | Chousuke | but if implemented it would be more powerful than most type systems. |
| 05:28 | squidz | why would it have to be optional? |
| 05:28 | Chousuke | squidz: because you don't want to force people to use it |
| 05:29 | Chousuke | typing gets in the way sometimes |
| 05:29 | Chousuke | michaelr525: basically a system for reasoning about code using arbitrary predicates, not just types |
| 05:29 | squidz | in my opinion it should be implemented and forced muahaha. |
| 05:30 | robermann | $cd doc |
| 05:30 | lazybot | clojure.contrib.repl-utils/*local-javadocs*: http://clojuredocs.org/v/330 |
| 05:30 | lazybot | clojure.contrib.gen-html-docs/generate-documentation-to-file: http://clojuredocs.org/v/331 |
| 05:30 | lazybot | clojure.contrib.repl-utils/add-local-javadoc: http://clojuredocs.org/v/332 |
| 05:30 | michaelr525 | squidz: C# went half way towards programmers when they added the `var' keyword |
| 05:30 | Chousuke | there are static type systems that are good but most only harm you. |
| 05:30 | Chousuke | like Java's |
| 05:30 | Chousuke | it's baaaaaaaaad |
| 05:30 | michaelr525 | Types are still there but they are infered most of the time |
| 05:30 | robermann | which project give you 'cd''s beahviour? |
| 05:31 | Chousuke | Haskell's type system is pretty good but I can see it getting in the way at times |
| 05:31 | squidz | I can't imagine how static typing could get in the way??? |
| 05:31 | lazybot | squidz: How could that be wrong? |
| 05:31 | Chousuke | You need a lot of really complicated type trickery to enable things that are straightforward in dynamic languages |
| 05:31 | MasseR | /la/win 32 |
| 05:32 | Chousuke | squidz: are you kidding me? How does Java's static typing not get in the way? |
| 05:32 | squidz | Ive never seemed to have a problem with it, but then again it's all i'm really used to |
| 05:32 | Chousuke | or in general, any sort of static typing without type inference = headache |
| 05:32 | khaliG | michaelr525, have you looked at Qi? |
| 05:33 | Chousuke | squidz: you're perhaps used to only doing things that are natural within the confines of Java's type system |
| 05:33 | Chousuke | which isn't a lot |
| 05:34 | Chousuke | it's entirely possible to have much better static typing in a much more expressive language, too (again, Haskell) |
| 05:34 | michaelr525 | khaliG: what's that? |
| 05:35 | khaliG | michaelr525, http://www.lambdassociates.org/qilisp.htm |
| 05:35 | Chousuke | but even then it gets in the way; With static typing, you can't write "incomplete" programs quite as easily and test code as you write it. |
| 05:35 | michaelr525 | khaliG: should I? |
| 05:35 | khaliG | michaelr525, yep! it's got a lot of cool ideas :) |
| 05:35 | Chousuke | in a dynamic language it is not an issue if you leave a function unimplemeted, as long as you don't call it |
| 05:36 | Chousuke | so you can switch focus to something more important. |
| 05:36 | michaelr525 | khaliG: one day.. when i get some free time.. (currently all free time goes to IRC chats;) |
| 05:36 | khaliG | haha! |
| 05:36 | Chousuke | it's also easy to experiment with different sorts of inputs to different functions as you have no rigid typing requirements |
| 05:38 | squidz | yes but that doesnt seem very formal. In math you have to have a domain defined for functions for example. You can just stick whatever you want in there and see what happens |
| 05:38 | Chousuke | programming isn't math |
| 05:38 | squidz | maybe it seems like a restriction |
| 05:38 | squidz | but i think it could be |
| 05:38 | squidz | programming math that is |
| 05:39 | scottj | math has side effects? |
| 05:39 | squidz | but that goes into other philosophical questions that are maybe too distracting |
| 05:39 | khaliG | i think the better question is, does scala do static typing well? |
| 05:40 | Chousuke | it does it kind of like haskell I think |
| 05:40 | squidz | khaliG: that could be a dealbreaker for sure |
| 05:40 | Chousuke | except it has to work with Java |
| 05:40 | Chousuke | which obviously complicates matters |
| 05:41 | Chousuke | java's type system is dumb :P |
| 05:41 | khaliG | the reason I mention Qi is because i've heard there is a port to clojure on the way, and it does static typing rather well ;) |
| 05:42 | scottj | khaliG: I don't think a clojure port has been started |
| 05:42 | scottj | khaliG: I think shen is targeting other platforms first |
| 05:42 | khaliG | scottj, oh? i was just reading an older google groups post where someone was attempting it - but i can't find the github for some reason :/ |
| 05:43 | scottj | Rich mentioned that cljs with type checking by gclosure might be the first static typing version of clojure |
| 05:44 | squidz | scottj: So do you know if that is a goal that he wants? |
| 05:45 | scottj | squidz: like Chousuke said, Rich welcomes tools that help prevent errors, but he doesn't want it to prevent you from doing something that's correct just because it can't prove it's correct |
| 05:46 | squidz | seems reasonable enough. Does he get on this channel often? |
| 05:46 | squidz | or at all |
| 05:47 | scottj | not often any more |
| 05:50 | squidz | I would like to contribute to the project if I could, but I dont know anything about writing languages |
| 05:50 | squidz | I'll at least make a start by learning clojure and reading through sicp |
| 05:50 | michaelr525 | khaliG: scheme and js first, that's what written on Qi's site |
| 05:51 | scottj | squidz: very few people contribute to the language itself, most things are done in libraries |
| 05:52 | squidz | which libraries? |
| 05:52 | scottj | squidz: are we still talking static typing? |
| 05:52 | squidz | no I mean in general right now |
| 05:52 | scottj | http://www.clojure-toolbox.com/ |
| 05:53 | squidz | ah okay you mean libraries for clojure |
| 05:53 | scottj | oh by project you meant sicp in clojure? |
| 05:54 | squidz | no I meant the language itself |
| 05:54 | squidz | but I guess that working on libraries would do just as much benefit if not more |
| 05:54 | scottj | oh well in that case see contrib |
| 05:54 | squidz | What kind of libraries do you suppose are in need or would be most beneficial right now? |
| 05:56 | squidz | for example, Ive heard that compujure is pretty good, so that probably takes care of webdevelopment |
| 05:56 | scottj | squidz: I don't know, most big areas are well covered probably a specific need you have or improvements to an existing library |
| 05:57 | scottj | first things first, learn clojure :) |
| 05:57 | squidz | yeah lol |
| 05:58 | squidz | but I learn by doing |
| 05:58 | squidz | works wonders for motivation |
| 06:05 | squidz | https://github.com/getwoven/infer looks interesting |
| 06:06 | ejackson | squidz: a lot of that should be in incanter, I think. |
| 06:07 | squidz | yeah, I also just thought it would possibly be better if the combined a few projects. |
| 06:07 | squidz | but easier said than done |
| 06:43 | squidz | ejackson: I see you contributed to incanter |
| 06:49 | robermann | squiz: In my opinion, pragmatically speaking, static typing is very useful when reworking on legacy code if the code isn't well encapsulated: in these cases the compiler can really save you good time. "static typing"'s usefulness is not a language property. |
| 06:59 | ilyak | hi * |
| 06:59 | ilyak | I have a map-of-something |
| 06:59 | ilyak | And I do (if (contains? map-of-something key) (some-fn (get map-of-something key)) |
| 06:59 | ilyak | What's the idiomatic way? |
| 07:00 | ilyak | some-fn function does side-effects |
| 07:01 | michaelr525 | seems right to me, but I'm a noob |
| 07:02 | michaelr525 | you can use when instead of if here, since you have no else |
| 07:03 | michaelr525 | ,doc |
| 07:03 | clojurebot | #<CompilerException java.lang.RuntimeException: Can't take value of a macro: #'clojure.repl/doc, compiling:(NO_SOURCE_PATH:0)> |
| 07:03 | michaelr525 | ,doc contains? |
| 07:03 | clojurebot | #<CompilerException java.lang.RuntimeException: Can't take value of a macro: #'clojure.repl/doc, compiling:(NO_SOURCE_PATH:0)> |
| 07:03 | michaelr525 | ,(doc contains?) |
| 07:03 | clojurebot | "([coll key]); Returns true if key is present in the given collection, otherwise returns false. Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the range of indexes. 'contains?' operates constant or logarithmic time; it will not perform a linear search for a value. See also 'some'." |
| 07:04 | ilyak | ,(contains? :a {:a 5}) |
| 07:04 | clojurebot | false |
| 07:04 | ilyak | oops, I guess I should use something else? |
| 07:04 | ilyak | ,(contains? '(:a 5) {:a 5}) |
| 07:04 | clojurebot | false |
| 07:04 | ilyak | wtf, what for is contains? on maps? |
| 07:04 | michaelr525 | ,(:a {:a 5}) |
| 07:04 | clojurebot | 5 |
| 07:05 | ilyak | oops, wrong order |
| 07:05 | ilyak | ,(contains? {:a 5} :a) |
| 07:05 | clojurebot | true |
| 07:05 | ilyak | right |
| 07:05 | ilyak | sorry for confusion |
| 07:05 | ilyak | michaelr525: I actually have string keys |
| 07:05 | michaelr525 | doesn't matter |
| 07:07 | ilyak | ,("something" {"something" "crazy"}) |
| 07:07 | clojurebot | #<ClassCastException java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn> |
| 07:08 | ilyak | nowp |
| 07:09 | michaelr525 | ah, you mean for that |
| 07:10 | Netpilgrim | ,({"something" "crazy"} "something") |
| 07:10 | clojurebot | "crazy" |
| 07:11 | michaelr525 | cool |
| 07:16 | raek | ilyak: you can also use if-let: (if-let [val (get m key)] (do-something val) (do-something-else)) or (if-let [[_ val] (find m key)] (do-something val) (do-something-else)) if you use nil as a key |
| 07:17 | ilyak | raek: cool, but i'm considering adding some kind of helper into my util.clj |
| 07:42 | lnostdal_ | so odd .. i'm getting "no transaction running", but the code and functions called is within a (dosync ..) |
| 07:43 | lnostdal_ | and the stack-trace has an earlier frame; clojure.lang.LockingTransaction.runInTransaction(LockingTransaction.java:231) |
| 07:45 | lnostdal_ | oh, wait .. i've got some add-watch thing triggering .. hm |
| 07:47 | lnostdal_ | ok, so those run in arbitrary threads unless i'm mutating the ref within an agent (?) .. parsing the doc-string here :) |
| 08:07 | khaliG | is there a nicer way to write - (map #(get %1 "name") (db/query ...)) |
| 08:19 | ilyak | khaliG: Who controls db/query? |
| 08:19 | ilyak | 'cause the best way is (map :name (db/query ...)) but you have to make db/query use keywords |
| 08:19 | wunki | in Python there is a "try -> except -> else" , how could I write this in clojure? |
| 08:20 | khaliG | right, fleetdb doesn't use keywords so i've got a string rather than keyword :/ |
| 08:20 | ilyak | wunki: What does else do in python's try? |
| 08:21 | wunki | if there is *no* exception, it winds up at else |
| 08:21 | khaliG | that sounds dumb |
| 08:22 | wunki | ilyak: http://docs.python.org/tutorial/errors.html#handling-exceptions |
| 08:22 | khaliG | why not put the code that would go in the else after everything else inside the try block, same effect? |
| 08:23 | agz | how I type-hint vector of float vectors ??? |
| 08:23 | lazybot | agz: Yes, 100% for sure. |
| 08:23 | wunki | khaliG: you are right.. totally missed that.. |
| 08:23 | khaliG | oh i wasn't having a go at you, at python instead :P |
| 08:27 | ilyak | so you should use (do (try (catch )) (else-code)) |
| 08:27 | ilyak | or not :) |
| 08:27 | ilyak | what do you want to return? |
| 08:28 | ilyak | that is The question for clojure snippet |
| 10:22 | simard | I'm interested in numerical performance with clojure (ie.: calculating a sequence of matrix operations in reasonable time). Can anyone point me to some resource about this ? Is it realistic to expect such performance from clojure ? I'm comparing a naive implementation of a 1-dimensional FDTD algorithm in clojure with one in octave, and the time of execution difference is around an order or magnitude, maybe more. |
| 10:23 | simard | obviously, behind octave are copious amounts of specialized libraries.. |
| 10:29 | Netpilgrim | simard: I really have no clue about this subject, but I assume the authors of Incanter (http://incanter.org/) would know something about this. |
| 10:36 | simard | Netpilgrim: thank you I'll have a look to it |
| 10:38 | Netpilgrim | Would the use of reduce at https://gist.github.com/1195103 be considered idiomatic, of would a loop be considered better style? |
| 10:40 | Netpilgrim | BTW: I like Gist well enough but their monospace font is one of the worst to distinguish between ones and a small Ls. |
| 10:41 | Netpilgrim | s/a small/small/ |
| 10:51 | Kototama | hi |
| 10:51 | Kototama | can someone tell me what's wrong with the deployment of my compojure project http://paste.lisp.org/display/124485 ?! |
| 10:51 | Kototama | "java.lang.ClassNotFoundException: org.mortbay.jetty.Server" :-) ?! |
| 10:55 | robermann | maybe a JVM version problem |
| 11:00 | robermann | Kototama: by the way they have refactored the code: http://wiki.eclipse.org/Jetty/Getting_Started/Porting_to_Jetty_7/Refactoring |
| 11:01 | Kototama | ah! |
| 11:01 | Kototama | i'll try jetty6 |
| 11:02 | robermann | check this too: http://stackoverflow.com/questions/2451572/jetty-7-mysql-config-java-lang-classnotfoundexception-org-mortbay-jetty-webap |
| 11:02 | robermann | bah, sometimes I don't understand the Java designers :) ! |
| 11:03 | Kototama | exactly what I thought when fighting with streams today |
| 11:04 | robermann | renaming whole packages ! |
| 11:04 | Kototama | well seems the project is part of eclipse now |
| 11:04 | Kototama | the naming convention with enterprise name is odd |
| 11:15 | lnostdal_ | i really don't understand how dosync and add-watch relate.. the add-watch callbacks are queued up and executed at the end of a transaction -- and run in arbitrary threads? |
| 11:20 | raek | lnostdal_: they are executed after the transaction has completed |
| 11:20 | raek | maybe you are looking for validators? |
| 11:20 | raek | they are executed when the transaction is about to finnish |
| 11:25 | Kototama | robermann: what is strang is that the test app from compojure works |
| 11:25 | Kototama | i mean the example project |
| 11:27 | lnostdal_ | raek, ok |
| 11:28 | raek | ,(doc add-watch) |
| 11:28 | clojurebot | "([reference key fn]); Alpha - subject to change. Adds a watch function to an agent/atom/var/ref reference. The watch fn must be a fn of 4 args: a key, the reference, its old-state, its new-state. Whenever the reference's state might have been changed, any registered watches will have their functions called. The watch fn will be called synchronously, on the agent's thread if an agent, before any p... |
| 11:30 | robermann | Kototama: this one https://github.com/weavejester/compojure-example? Are you creating a WAR via lein ring uberwar? |
| 11:36 | Kototama | yes |
| 11:42 | Kototama | seems better if i do not include ring.middleware.keyword-params, and ring.adapter.jetty! |
| 11:42 | Kototama | now the apps is starting but without css |
| 11:48 | Kototama | i got a (mp/wrap-multipart-params |
| 11:48 | Kototama | (POST "/files" {params :params session :session} |
| 11:48 | Kototama | (upload-file (get params "lkif-file") session))) |
| 11:48 | Kototama | in my routes |
| 11:48 | Kototama | but the POST goes to http://localhost:8080/files |
| 11:49 | Kototama | whereas the app is in the localhost:8080/theapp |
| 11:49 | Kototama | how can I make these routes relatives? |
| 11:50 | Kototama | hum maybe it's a problem with the javascript loading a "/files" url :s |
| 11:50 | robermann | mmm (POST "/" ? |
| 11:51 | robermann | the "/" should be referred to the root context |
| 11:51 | Kototama | this http://paste.lisp.org/display/124488 |
| 11:52 | Kototama | ok then it's a problem with the use of the jquery load method which does not refer to this context |
| 11:53 | robermann | I think so |
| 11:53 | Kototama | is there a way to make it context aware :-) ? |
| 11:55 | robermann | by the way, check this: https://github.com/mmcgrana/ring/blob/f2ca099a6102da4e080a29e0a00e208a152debba/ring-jetty-adapter/src/ring/adapter/jetty.clj#L1 it imports some org.mortbay.jetty.* classes, that supposedly does not exist in your classpath |
| 11:56 | robermann | (because they have renamed it) |
| 11:56 | Kototama | yep thanks!, that was the origin of the problem |
| 11:58 | robermann | for jquery, I can only refer you to http://stackoverflow.com/questions/313434/problem-setting-path-to-jquery-in-mvc-app |
| 12:01 | Kototama | ok thanks |
| 12:22 | robermann | I was noting that genclass.clj and core.clj are both in the same namespace clojure.core. So you can have different files in the same namespace, right? One create it via ns , the others modules go into it by in-ns |
| 12:22 | amcnamara | o/ |
| 12:23 | robermann | Is this a way for splicing many features in several structured files, keeping the same namespace? |
| 12:31 | manutter | drat, trying to set up clojure-mode.el on a new system, and marmalade-repo.org is down. :( |
| 12:54 | nizze | Hi! |
| 12:54 | nizze | I'm trying to implement map fuction. |
| 12:54 | nizze | What am I doing wrong here? |
| 12:54 | nizze | http://pastebin.com/Wrkxc5J6 |
| 12:54 | nizze | The TCO appears to be working differently than I expected |
| 12:55 | ilyak | nizze: s/concat/cons? |
| 12:56 | nizze | Why so? |
| 12:56 | ilyak | Also, (=) would likely delazify the coll |
| 12:56 | ilyak | Which you probably don't want |
| 12:57 | ilyak | And also it might be an O(N) operation |
| 12:57 | ilyak | Better use (not-empty) |
| 12:57 | ilyak | nizze: because (f (first coll)) probably returns a scalar |
| 12:57 | ilyak | and concat works on seq* |
| 12:58 | ilyak | what you did is a flat-map |
| 12:58 | ilyak | which is useful but distinct thing |
| 13:11 | squidz | whats the best clojure tutorial out there right now? |
| 13:16 | nizze | ilyak: Thanks! |
| 13:17 | nizze | Hmm what the difference between flat-map and map? |
| 13:18 | Chousuke | nizze: you can't use recur like that anyway |
| 13:18 | nizze | Chousuke: Really? |
| 13:18 | nizze | I assume the recur is not in the tail position |
| 13:18 | Chousuke | recur must be in a tail position. ie. it can't be a parameter to any function |
| 13:19 | nizze | Okay. |
| 13:19 | Chousuke | for an easy non-lazy implementation of map, use a vector as the accumulator |
| 13:19 | Chousuke | and add things to that |
| 13:20 | Chousuke | the lazy implementation is not much harder, but you'll have to understand lazy-seq and use "real" recursion, instead of recur |
| 13:23 | nizze | Chousuke: okay. I assume as a newbie that I do not have to know about lazy seqs |
| 13:23 | Chousuke | nizze: well, you can get away with not knowing how to make your own directly but it's not that hard |
| 13:23 | nizze | I've been doing some Haskell so I know what lazy means. |
| 13:23 | nizze | Okay |
| 13:24 | nizze | Thanks a ton for your help |
| 13:25 | Chousuke | the idea is that you make a function that returns sequence in such a way that it conses an item to a lazy seq that is determined by calling the function recursively |
| 13:25 | Chousuke | eg (defn ones [] (cons 1 (lazy-seq (ones)))) |
| 13:26 | Chousuke | lazy-seq is a macro that defers the evaluation of the recursive call so you don't get an infinite loop... unless you try to evaluate a call to (ones) |
| 13:26 | Chousuke | without using take or something, that is |
| 13:27 | Chousuke | you can think of it as lazy-seq returning a "fake" seq that, when you actually need its item, evaluates the code you gave it. (the recursive call, that is) |
| 13:28 | nizze | WOLO |
| 13:28 | nizze | |
| 13:28 | nizze | WOW! |
| 13:29 | nizze | Paul Graham was not wrong about LISP |
| 13:30 | Chousuke | I think you can actually do (defn ones [] (lazy-seq (cons 1 (ones)))) too for extra laziness |
| 13:31 | Chousuke | where you don't even get the first 1 until you force it |
| 13:31 | Chousuke | it's not magical, but it's sometimes sort of hard to see where the laziness is needed so that you don't end up with infinite loops :) |
| 13:35 | nizze | Chousuke: Clojure seems the most thought out language that I've ever tried |
| 13:35 | nizze | and it seems that it's turtles all the way down as well, something I loved about Smalltalk |
| 13:36 | nizze | Thranks |
| 13:36 | nizze | *Thanks |
| 13:45 | robermann | clojurebot: commands |
| 13:45 | clojurebot | paredit commands is http://mumble.net/~campbell/emacs/paredit.html |
| 14:18 | wunki | how would I check if a value is a boolean? |
| 14:21 | gtrak`` | wunki, primitive or boxed type? |
| 14:22 | wunki | gtrak``primitive? |
| 14:22 | wunki | (or (true? var) (false? var)) |
| 14:22 | wunki | or is that just stupid :) |
| 14:32 | gtrak`` | ,(true? (Boolean. true)) |
| 14:32 | clojurebot | false |
| 14:32 | gtrak`` | wunki, you tell me :-) |
| 14:33 | gtrak`` | where are you getting the boolean from? |
| 14:33 | wunki | input from a .json |
| 14:34 | gtrak`` | so the json parser is going to do the right thing, probably |
| 14:34 | wunki | gtrak`` yes, it creates a true/false correctly |
| 14:34 | gtrak`` | as long as it's not creating new Boolean instances, it looks like true? and false? will do the right thing |
| 14:35 | gtrak`` | and true? and false? use clojure's identical function to check, so there's no extra behavior for non-booleans as far as I can tell |
| 14:36 | wunki | gtrak`` thanks, will implement it this way |
| 14:37 | gtrak`` | they should seriously remove that constructor from java |
| 14:39 | wunki | another rookie question, why should I use `do` https://gist.github.com/9f42f01ba7135b287777 |
| 14:40 | raek | wunki: defn (and fn) has an "implicit do", so you don't need to write that explicitly |
| 14:41 | raek | in certain cases, you do need 'do', like in an if expression |
| 14:41 | raek | or in other places where you can only write one expressoin |
| 14:41 | wunki | raek: ah, clicked, thanks |
| 14:41 | gtrak`` | raek, thanks, didn't know that about fns |
| 14:42 | raek | most special forms (where it makes sense) behave this way |
| 14:42 | gtrak`` | wunki, it's for imperative-style, the do block returns the result from the last member |
| 14:42 | raek | as a convenvience |
| 14:46 | wunki | last question for today (promise), I'm currently building function like this: https://gist.github.com/1e97f9e61f5f0964c2a3 |
| 14:47 | wunki | would you do it like that? |
| 14:48 | gtrak`` | looks good to me |
| 14:49 | gtrak`` | try it |
| 14:50 | wunki | gtrak`` I'm already using it like this, to keep it "DRY" I'm performing some validations on the arg's this way. It works.. but wasn't sure if it could be improved |
| 14:50 | gtrak`` | there's some preconditions support available for that |
| 14:51 | gtrak`` | http://blog.fogus.me/2009/12/21/clojures-pre-and-post/ |
| 14:55 | wunki | gtrak`` thanks for the tip, instapapered :) |
| 14:56 | wunki | I'm releasing all my code (for epis.to) this week, will post it in the channel when done |
| 15:01 | Netpilgrim | wunki: For some reason pre and post conditions do not work when attached to protocol implementations inside a defrecord. They are just ignored, which makes it even more annoying. |
| 15:01 | Netpilgrim | wunki: Just as an BTW because it's not mentioned in Fogus' article. |
| 15:01 | wunki | Netpilgrim: I'm going to need to read more about it, because what you said just whooshed by... |
| 15:02 | Netpilgrim | wunki: No problem. I just got bitten by it the other day, so I wanted to spread the word. :) |
| 15:03 | wunki | Netpilgrim: thanks, I have jolted down your comment for future reference :) |
| 15:03 | gtrak`` | Netpilgrim, you could probably use an extra layer of (fn [] to fix that, right? |
| 15:04 | Netpilgrim | gtrak``: Perhaps. I'll try. For the moment I'm not working on the code because it was part of a procrastination effort. |
| 15:05 | Netpilgrim | gtrak``: And so is hanging out in this channel. :) |
| 15:06 | gtrak`` | it's good to procrastinate useful things |
| 15:07 | Netpilgrim | gtrak``: That's what I keep telling myself. But it can get out of hand, as in “You have to cram for an exam? That's the perfect time to start learning a new programming language”. |
| 15:07 | gtrak`` | story of my life :-) |
| 15:08 | gtrak`` | it gives you a good breadth of knowledge |
| 15:10 | Netpilgrim | gtrak``: True, but I've reached a point where getting a degree has become really more important than accumulating more tangential knowledge. |
| 15:11 | Netpilgrim | gtrak``: That being said I still think that learning a functional language, and Clojure in particular, will be worth the time. I just have to schedule better. |
| 15:11 | wunki | is it possible to catch an exception with :type "x" ? |
| 15:12 | gtrak`` | wunki, not sure what you mean? |
| 15:13 | wunki | I'm raising an exception with :type :invalid |
| 15:13 | wunki | now I would like to catch only that exception |
| 15:14 | gtrak`` | you are explicitly throwing that exception? |
| 15:14 | gtrak`` | generally you catch a specific exception by using a specific class for each exception, or you can add a field to your exception class to help you distinguish, then re-throw ones you can't do anything with |
| 15:15 | wunki | gtrak`` I'm raising them like here: http://mmcgrana.github.com/2010/08/clojure-rest-api.html |
| 15:15 | wunki | middle of the page, `raise :type :not-found` etc. |
| 15:16 | gtrak`` | ah, that's specific to clojure.contrib.condition |
| 15:16 | gtrak`` | there's also error-kit |
| 15:17 | wunki | I'm just copying everything I see on the web, trying to get it to work. Going pretty good this far. But I lack some serious knowledge |
| 15:17 | wunki | like how to catch a specific :type |
| 15:17 | gtrak`` | http://richhickey.github.com/clojure-contrib/condition-api.html |
| 15:18 | gtrak`` | handler-case does it |
| 15:18 | michaelr525 | hey! |
| 15:19 | squidz | is it normal that after evaluating lisp from within emacs, the output isnt put to my slime-repl, but instead the mini-buffer? |
| 15:21 | squidz | and when I compile using C-c C-k, it gives me a compilation finished message in minibuffer, but there is no output to be found |
| 15:40 | squidz | anybody ever experience something similar or know why? |
| 15:44 | amcnamara | squidz: you're probably compiling not evaluating |
| 15:45 | amcnamara | for me, C-x C-e evaluates in slime (I think this is the default, though I may have changed it at some point) |
| 15:45 | squidz | amcnamara: when I use C-x C-e it does the same |
| 15:45 | amcnamara | are you running slime or an inferior lisp? |
| 15:46 | amcnamara | err slime/swank |
| 15:47 | squidz | yes its running |
| 15:47 | amcnamara | odd |
| 15:47 | amcnamara | try evaluating (+ 1 1) |
| 15:48 | amcnamara | or something with non-nil output |
| 15:48 | squidz | it evaluates it, but it only outputs it to the minif buffer in the very bottom, instead of in my slime-repl clojure buffer |
| 15:49 | amcnamara | yeah, that's to be expected, it should still be accessible to your slime environment though |
| 15:49 | amcnamara | try this: (def a "aoeu") c-x c-e, then in slime repl enter a |
| 15:49 | squidz | hmm I wonder why it doesnt seem connected |
| 15:52 | squidz | yeah that works |
| 15:52 | squidz | recognizes it |
| 15:53 | amcnamara | slime eval and slime-repl eval have the same environment (swank) but different output streams |
| 15:54 | squidz | is that by default'ß |
| 15:54 | squidz | ? |
| 15:56 | amcnamara | yeah, I know there's a way for slime to eval to the slime-repl but I don't remember the shortcut |
| 15:57 | amcnamara | also probably depends on how you installed slime and clojure-mode, I know elpa does a lot of configuration for you; my setup doesn't use elpa though |
| 15:57 | squidz | either did I |
| 15:58 | amcnamara | may be worth taking a look if that's the behaviour you want |
| 16:00 | squidz | no, this will be fine. Just wanted to make sure that this is the expected behavior |
| 16:02 | amcnamara | that's how mine works, that's also the behaviour I prefer |
| 16:02 | amcnamara | to each their own |
| 16:15 | Nocab | are there any simple ways to comment out lots of lines |
| 16:15 | amcnamara | &(doc comment) |
| 16:15 | lazybot | ⇒ "Macro ([& body]); Ignores body, yields nil" |
| 16:15 | Netpilgrim | Nocab: (comment <all your lines>) |
| 16:16 | Nocab | right. but Im coming from a VS-as-IDE sorta background. where CTRL K-C would comment whatever was chosen, in whatever construct whatever file you had open had for comments |
| 16:16 | Nocab | similarly CTRL K-U to uncomment |
| 16:17 | Nocab | I was wondering if eclipse had anything similar |
| 16:18 | Nocab | I -can- manually move to the start, add the (comment and go to the end and add a ), or for each line prefix it with ; |
| 16:18 | Nocab | I was just looking for somethiing slightly more automatic, using the intelligence of the editor instead of my fingers :P |
| 16:18 | Nocab | ah well |
| 16:18 | Nocab | I tried cljr |
| 16:18 | Nocab | but I couldnt copy & paste things OUT from it |
| 16:19 | Nocab | and that was a deal-killer. made experimenting and taking out the good code to a .clj file somewhere cumbersome |
| 16:19 | Netpilgrim | Nocab: IIRC Eclipse has this feature and if you have installed Clojure support (Counterclockwise?) it should work, though probably by adding lots of ;; in front of the lines. |
| 16:19 | Nocab | Maybe emacs would have been OK, but Ive been trying to get into eclipse (for android-dev) so I figured eclipse for clojure would be OK as well :) |
| 16:20 | Nocab | Netpilgrim: thanks. guess ILl google more. just figured someone in here would know off hand |
| 16:21 | amcnamara | Nocab: I think many people would like to hear more about clojure dev in eclipse, consider writing a blog post about it. |
| 16:22 | amcnamara | at least _I_ would be interested |
| 16:24 | Netpilgrim | Could someone with slime experience help me with an encoding problem? describe-coding-system shows UTF-8 all the way but if I put non-Latin1 characters in my code, slime-eval-last-expression outputs “Coding system iso-latin-1-unix not suitable for …”. |
| 16:25 | Nocab | amcnamara: uhm. Ill have to disappoint you |
| 16:25 | Nocab | I let my blog rot and die |
| 16:25 | Nocab | and I cant be bothered to setup a new one ;) |
| 16:26 | amcnamara | bummer. |
| 16:29 | Nocab | I used to have 10 domains and sites and way too many projects |
| 16:29 | Nocab | I just overdid it and now I have almost nada ;) |
| 16:30 | Nocab | anyway, the closest Ive come to starting up any website related things right now is documenting whatever thing I work on in a public Google Docs document ;) |
| 16:30 | Nocab | and I guess for the purpose of your enlightment, I wouldnt be able to contrast clojure in eclipse to other things, seeing as Im pretty new to clojure overall |
| 16:34 | Tcepsa | Micah: Have you tried C-/ in Eclipse? I think that's how you can comment multiple lines in Java, but I don't remember whether it works with Clojure... |
| 16:35 | Tcepsa | whoops. s/Micah/Nocab ($#@% autocorrect...) |
| 16:39 | Nocab | Tcepsa: just tried it |
| 16:39 | Nocab | and was to -comment- on it here :P |
| 16:40 | Nocab | my comment: what an ass and US-centric keybinding |
| 16:40 | gtrak`` | Nocab, if you use emacs and paredit, you type '(comment CTRL-RIGHTARROW' and you're done |
| 16:40 | Nocab | there is no way to do that here without pressing shift as well |
| 16:40 | Nocab | gtrak``: thanks. I am still consideirng going the emacs route |
| 16:41 | Nocab | because eclipse takes like 20 seconds to start. on a core i7 with 12 GBs of ram |
| 16:43 | gtrak`` | you can get pretty useful with emacs in a couple of days |
| 16:46 | amcnamara | emacs is hugely configurable, which is particularly useful for me because I don't use a qwerty keyboard, normal shortcuts are usually inconvenient for me |
| 16:46 | amcnamara | I love emacs |
| 16:48 | Netpilgrim | I have found out that I have to also set the slime connection encoding to UTF-8 (it defaults to Latin1). But if I follow the instructions on the swank-clojure github page and try to evaluate an expression with Unicode characters, swank throws a runtime exception (http://pastebin.com/nV4tX4JE). |
| 16:49 | Netpilgrim | Has anyone swank-clojure running with UTF-8? |
| 16:49 | Nocab | s/emacs/eclipse/ |
| 16:49 | lazybot | <Nocab> tries doing evil unicode stuff in eclipse |
| 16:51 | Nocab | and that worked |
| 16:52 | Netpilgrim | Nocab: I don’t know what kind of REPL you have in Eclipse, but it's probably not slime/swank, is it? |
| 16:58 | Nocab | no idea |
| 16:58 | Nocab | it came with clounterclockwise |
| 16:58 | Nocab | I highlight code in the editor and press ctrl-alt-s and it gets run in the repl |
| 17:00 | Nocab | ah well. Im off |
| 17:04 | simard | sorry to ask that (I like lein), but is there a way to reduce the latency whenever I type "lein xyz" ? As an example, it takes 5 seconds between "lein run" and the actual run of my smallest program. |
| 17:09 | gtrak`` | is it possible to set flags in project.clj and read them in the app? |
| 17:09 | ordnungswidrig | simard: cake addresses this. It keeps a running jvm which it connects to |
| 17:10 | gtrak`` | simard, there's a lein int for that |
| 17:12 | gtrak`` | anyway, I want to enable a behavior during development, and disable it during build, what's the right way to do that? (specifically, a cache) |
| 17:13 | simard | ordnungswidrig: oh so that delay is the JVM starting up.. makes sense |
| 17:15 | ordnungswidrig | gtrak``: I use a dynamic var in a config namespace: org.foo.project.config *env* |
| 17:16 | gtrak`` | do you have to switch it on and off manually? that's a pain |
| 17:22 | Netpilgrim | Netpilgrim: Quick update on my encoding problem: Apparently the last swank-clojure release doesn’t have UTF-8 support yet. I overlooked that the github page defaults to the master branch. |
| 17:22 | balint | how do I print something to stderr? |
| 17:23 | balint | I thought this would work: (binding [*out* *err*] (print "This went to std. error")) |
| 17:23 | balint | but it does not |
| 17:25 | michaelr525 | re |
| 17:26 | ordnungswidrig | gtrak``: default is :prod, for development I redefine it at the reply to :dev |
| 17:26 | ordnungswidrig | balint: I think it's the wrong way: (binding [*err* *out*] (print "foo")) |
| 17:27 | gtrak`` | ordnungswidrig, I think until I figure it out, I'm just going to use hg's shelve and unshelve to make it simpler |
| 17:27 | ordnungswidrig | balint: sorry, that was wrong |
| 17:27 | mudge | I want to set *out* to a file, how would I do that? |
| 17:27 | ordnungswidrig | balint: do you use the plain repl or swank? |
| 17:28 | mudge | basically I want all *out* to go into a file and not to the console |
| 17:28 | balint | ordnungswidrig: plain repl |
| 17:28 | gtrak`` | mudge, you can use > |
| 17:28 | gtrak`` | that would be the way to do it in the spirit of unix |
| 17:29 | ordnungswidrig | (with-open [f (clojure.java.io/writer "foo.txt")] (binding [*out* f] (print "foo"))) |
| 17:29 | ordnungswidrig | balint: what is the value that *out* and *err* give you? |
| 17:29 | ordnungswidrig | balma: maybe the repl redirects it for line editing and so on |
| 17:30 | balint | user=> *out* |
| 17:30 | balint | #<OutputStreamWriter java.io.OutputStreamWriter@494b6bed> |
| 17:30 | mudge | gtrak, I am calling my program from within a java program with (.exec (Runtime/getRuntime) "command"), and unix redirection won't work with that |
| 17:30 | balint | user=> *err* |
| 17:30 | balint | #<PrintWriter java.io.PrintWriter@b3e75a5> |
| 17:30 | ordnungswidrig | balint: how do you know, it goes to out, not err? |
| 17:30 | balint | it does not go anywhere |
| 17:31 | balint | ordnungswidrig: I use it like this: ./clj1.2-repl.sh foo.clj 2>/tmp/clojure.out |
| 17:31 | balint | and the file I'm writing to is empty |
| 17:32 | mudge | how do i set *out* to point to a file and not the console? |
| 17:32 | ordnungswidrig | balint: that's not the repl but (binding [*out* *err*] (print "foo")) should do it |
| 17:32 | balint | ordnungswidrig: hmm, that's what I had and it did not print it anywhere |
| 17:33 | ordnungswidrig | mudge: l pasted a snipped just 3min ago. |
| 17:33 | ordnungswidrig | balint: maybe the clj script does some file handle redirection= |
| 17:33 | ordnungswidrig | ? |
| 17:34 | mudge | ordnungswidrig: ah thanks, but that is a local thread binding, I want to set *out* on the root var binding |
| 17:35 | balint | ordnungswidrig: sorry, you were right. I created a clj that does just the above and it works |
| 17:35 | ordnungswidrig | Is *out* defined as dynamic? |
| 17:35 | balint | ordnungswidrig: thank you very much for your help |
| 17:35 | ordnungswidrig | balint: you're welcome |
| 17:35 | mudge | ordnungswidrig: good questions |
| 17:35 | ordnungswidrig | mudge: why must you bind it globally? |
| 17:38 | icey | i have a map that i'd like to add a key to if the key doesn't exist... is conj the correct form for this? i.e. (conj {:owner 2} {:title "stuff"}) == {:title "stuff" :owner 2} and (conj {:owner 2} {:title "stuff" :owner 33}) == {:title "stuff" :owner 33} |
| 17:38 | icey | testing at the repl insinuates this works, but i just want to make sure i'm not going to hurt myself doing it this way |
| 17:38 | mudge | ordnungswidrig: because I want any output of my program to write to a file (and there are parts of my program I can't control) |
| 17:38 | ordnungswidrig | mudge: that sounds terrifying :) |
| 17:39 | ordnungswidrig | mudge: I'd go with (System/setOut my-file-print-stream) |
| 17:39 | mudge | ordnungswidrig: thanks, trying that |
| 17:40 | ordnungswidrig | mudge: this would even work with java code using System/out. You'd need a permission in a SecurityManager enabled environment, though. |
| 17:42 | balint | ordnungswidrig: interesting, it works if I use println but it does not work with print |
| 17:43 | ordnungswidrig | balint: I suppose the stream is not flushed. Try (flush) |
| 17:44 | mudge | ordnungswidrig: thanks, working on it |
| 17:48 | balint | ordnungswidrig: and you are right again :) |
| 17:49 | mudge | balint: it's working for me when I set System/setErr, but not for System/setOut |
| 17:49 | mudge | i also flushed |
| 17:49 | balint | mudge: so you can't use *out* ? |
| 17:50 | balint | with the binding form above? |
| 17:50 | mudge | no, this isn't working: (System/setOut (PrintStream. (FileOutputStream. "/home/nick/jobboard/log.txt"))) |
| 17:50 | mudge | but this works for stdErr: (System/setErr (PrintStream. (FileOutputStream. "/home/nick/jobboard/log.txt"))) |
| 17:52 | mudge | I don't know why it works for stdErr and not for stdOut |
| 17:53 | balint | icey: you can also use (assoc your_map :owner 2) |
| 17:53 | balint | although that would "overwrite" any existing keys |
| 17:54 | icey | balint: actually, i think that makes more sense since i am using dissoc elsewhere to exclude stuff from the map. i can plan around overwriting values since it would consistently do that |
| 17:55 | icey | thanks :) |
| 17:55 | mudge | balint: what code did you use with System/setOut ? |
| 17:56 | balint | mudge: no code, my code is just that much: (binding [*out* *err*] (print "foo") (flush)) |
| 17:56 | balint | icey: maps are themselves functions which return the value belonging to the passed key |
| 17:57 | mudge | balint, okay |
| 17:57 | balint | (def m {:song "i feel loved"}) (m :song) => "i feel loved" (m :year) => nil |
| 17:57 | balint | that can be pretty useful |
| 18:03 | ordnungswidrig | good night everyone |
| 18:03 | jblomo | is there a way to compile clojurescript from more than one directory? |
| 18:43 | gtrak`` | jblomo, symlinks? |
| 18:44 | gtrak`` | without a dependency system, you have to do it the low-tech way... put all your common code in one place |
| 19:02 | scottj | what is the purpose of this intrinsics commit? https://github.com/clojure/clojure/commit/e92978783e1ba7ac0e2617fdabfed576209d7fa4 |
| 19:06 | scottj | jblomo: you mean other than putting the other places on the classpath and requiring them? |
| 19:31 | mudge | System/setOut isn't working for me, it just creates an empty file |
| 19:31 | mudge | Anyone know how to make System/setOut work in clojure? |
| 19:37 | ndimiduk | mudge: https://github.com/nathanmarz/cascalog/blob/master/src/clj/cascalog/playground.clj#L35 |
| 19:40 | mudge | thanks ndimiduk: i want to send output to a file, not *out*, or make *out* go to a file |
| 19:54 | Tcepsa | mudge: Does your code have a single entry point? |
| 19:57 | mudge | Tcepsa, yes |
| 20:01 | Tcepsa | mudge: I was going to suggest that you just wrap that in a (binding ...) like ordnungswidrig had suggested, but that won't redirect third party output; it would only route the output from your code to the file. |
| 20:03 | mudge | Tcepsa, right |
| 20:03 | mudge | odd thing is that this works for *err* (System/setErr (PrintStream. (FileOutputStream. "/home/nick/jobboard/log.txt"))) |
| 20:04 | mudge | but this doesn't work for *out*: (System/setOut (PrintStream. (FileOutputStream. "/home/nick/jobboard/log.txt"))) |
| 20:04 | Tcepsa | mudge: Have you tried them each individually, or did you do them both at the same time? |
| 20:05 | mudge | Tcepsa: tried them individually |
| 20:05 | Tcepsa | hmmm... |
| 20:06 | mudge | looking at the difference between *out* and *err*: *out* is A java.io.Writer object representing standard output for print operations. |
| 20:06 | mudge | Defaults to System/out |
| 20:07 | mudge | and *err* is A java.io.Writer object representing standard error for print operations. |
| 20:07 | mudge | Defaults to System/err, wrapped in a PrintWriter |
| 20:08 | user317 | i am new to how clojure/java deal with packages and dependencies, is there a way to get lein to pull https://github.com/ztellman/lamina automagically? |
| 20:11 | Tcepsa | mudge: Does it create the file if it doesn't already exist when you try to do setOut? |
| 20:12 | Tcepsa | mudge: (Possibly after attempting to print something to it?) |
| 20:12 | mudge | Tcepsa: it creates a new empty file, and in fact (.println System/out "data") will output to the file, but code such as (print "datadd") will not output to the file |
| 20:13 | mudge | Tcepsa: it seems like System/out and *out* are separate, if I change System/out, it doesn't seem to change *out* |
| 20:14 | mudge | user317: you can upload lamina to Clojars and then use the lein deps command to install the library into clojure projects. that's one way to do it |
| 20:14 | Tcepsa | mudge: Oh, that's a great catch! Yes, that's almost certainly what is going on. I bet if you made a call to a third party lib that used System.out.println it would go into the file |
| 20:15 | mudge | Tcepsa: yes! that's probably why it is working for *err*, because my third party software is writing to System/err, not to *err* |
| 20:17 | mudge | Tcepsa: I mean this works: (System/setErr (PrintStream. (FileOutputStream. "/home/nick/jobboard/log.txt"))) |
| 20:17 | mudge | because my third program is writing to System/err and not to *err* |
| 20:17 | mudge | i am starting to think it is not possible to change *out* and *err* |
| 20:17 | Tcepsa | mudge: So I think what you'll need to do is somehow remind *out* to that new System/out _after_ you call setOut |
| 20:18 | Tcepsa | s/remind/rebind |
| 20:18 | lazybot | <Tcepsa> mudge: So I think what you'll need to do is somehow rebind *out* to that new System/out _after_ you call setOut |
| 20:18 | mudge | Tcepsa: yea |
| 20:18 | user317 | mudge, thanks, whats clojars, lamina is not my work though |
| 20:19 | user317 | mudge, looks like this there already :) |
| 20:19 | Tcepsa | (I'm trying to do that now, but getting a ClassCastException... still working on it) |
| 20:19 | mudge | lamina might be on clojars. Clojars is where clojure libraries are kept and where Clojar libraries are installed from.http://clojars.org/ |
| 20:20 | mudge | Tcepsa: great! |
| 20:27 | mudge | Tcepsa: how's it going? |
| 20:27 | Tcepsa | mudge: Okay, I think I got it working! |
| 20:28 | mudge | really!? |
| 20:28 | mudge | do you have a gist? |
| 20:28 | Tcepsa | mudge: At your entry point, first call setOut |
| 20:28 | mudge | yes |
| 20:28 | Tcepsa | mudge: (No gist, but it is pretty straightforward) |
| 20:29 | mudge | okay |
| 20:29 | mudge | what's next? |
| 20:30 | Tcepsa | After that, do (binding [*out* (java.io.PrintWriter. System/out)] (everything-else ...)) |
| 20:31 | Tcepsa | Where everything else is the rest of your entry point code, so that e |
| 20:31 | Tcepsa | all of your code will run with the new binding |
| 20:32 | mudge | okay, trying it |
| 20:33 | Tcepsa | Odd... (printing |
| 20:33 | Tcepsa | bah, tablet keyboard is annoying... |
| 20:34 | Tcepsa | Odd... (println ...) works but (print ...) doesn't seem to show up |
| 20:34 | mudge | Tcepsa: make sure that you flush |
| 20:34 | Tcepsa | Doesn't seem to help |
| 20:35 | Tcepsa | It's like it just eats it; subsequent printlns come out but the text from the print is apparently gone. ~frown~ |
| 20:38 | Tcepsa | Ah, if you flush within the same binding it seems to work, but not if you use different binding calls. That is weird. |
| 20:38 | mudge | hmm |
| 20:39 | Tcepsa | The good news for you is that since all of your code should be called from inside that one binding, you should be fine as long as you flush before leaving it... |
| 20:39 | mudge | Tcepsa: yep |
| 20:40 | mudge | Tcepsa: it looks like binding *out* and *err* to the same file overwrites each other |
| 20:40 | mudge | Tcepsa: oh wait, nevermind, i just didn't bind *err* yet |
| 20:40 | mudge | let me try |
| 20:40 | mudge | it is working with *out* |
| 20:40 | Tcepsa | Yes, that's why I asked whether you were trying them both at the same time or individually; I thought perhaps that err was just getting a lock on the file or something |
| 20:41 | mudge | yea, i'm going to try them both on the same file now |
| 20:41 | Tcepsa | Ah, ok, looking forward to seeing whether that works |
| 20:41 | Tcepsa | Also, Ia |
| 20:43 | Tcepsa | I suspect opening a file with that particular FileOutputStream constructor may truncate the file, discarding anything that had previously been in it |
| 20:44 | mudge | yea, i wonder if there is an append mode, it looks like it is overwriting |
| 20:45 | mudge | yea, overwriting |
| 20:46 | Tcepsa | Yes, see the javadoc for FileOutputStream |
| 20:46 | Tcepsa | And now I need to go AFK. Hopefully that will be enough to get you past this hump at least! |
| 20:47 | mudge | yea, thanks Tcepsa! |
| 20:47 | mudge | yes, i see that there is |
| 20:48 | mudge | tried, it, they are working together now |
| 21:45 | ambrosebs | is there a trick to adding a new test file to clojure (core)? mvn test doesn't seem to pick up a new file at clojure.test-clojure.fn |
| 21:50 | ambrosebs | found it |
| 22:19 | ShereKahn | Hi guys, was just wondering if clojure supports a (loop ..... recur) form in the middle of another (loop recur) with diferent parameters ? |
| 22:20 | ShereKahn | that would be inner loop inside an outer loop |
| 22:20 | tomoj | given (defn fst [& [x]] x) and (defn snd [& [_ x]] x), does e.g. (map-indexed (juxt fst (comp f snd)) coll) make sense? or is there a better way without those? |
| 22:20 | tomoj | (for [[i s] (map-indexed vector coll)] [i (f s)]) has occurred to me |
| 22:22 | brehaut | ShereKahn: like #(loop [x 5] (when (< 0 x) (prn x) (loop [y x] (when (< 0 y) (prn y) (recur (dec y)))) (recur (dec x)))) |
| 22:22 | ShereKahn | yes... but more complext |
| 22:22 | brehaut | ShereKahn are you wanting mutual recursion? |
| 22:23 | ShereKahn | no |
| 22:23 | ShereKahn | actually its some kind of parser |
| 22:24 | ShereKahn | inner loop would match pattern* |
| 22:24 | ShereKahn | were outer loop is actually going over a lost of pattenrs |
| 22:24 | amalloy | $google fnparse |
| 22:24 | lazybot | [brehaut.net: Start Parsing in Clojure: fnparse] http://brehaut.net/blog/2011/fnparse_introduction |
| 22:24 | jblomo | where'd def- go in 1.3? |
| 22:25 | ShereKahn | tried fn parse, does not match my needs actually, It's more a template based system I have in mind. |
| 22:28 | devn | ShereKahn: what are you looking for? |
| 22:41 | gtrak`` | how do you change the working directory in a repl? |
| 22:45 | amalloy | gtrak``: that's not possible on the jvm |
| 22:45 | gtrak`` | ah... damn |
| 22:45 | gtrak`` | well symlinks to the rescue |
| 22:46 | gtrak`` | trying out clojurescript |
| 22:47 | user317 | so i am trying to use this lamina package, and i have (:use [lamina channel lazy-channel-seq]) in my namespace, and [lamina "0.4.0-beta2-SNAPSHOT"] in my project |
| 22:48 | user317 | but when i run lein it tells me it cant find lamina/channel__init.class |
| 22:48 | ShereKahn | devn: I am trying to parse the outputs of some commands from a device. |
| 22:48 | scottj | jblomo: don't think def- was ever in core, just defn-. there was a thread about it core ppl thought meta syntax was sufficient |
| 22:49 | ShereKahn | the basic Idea I got was to split the commands into tokens |
| 22:49 | ShereKahn | and have a list of patterns I would like to match |
| 22:49 | ShereKahn | by tokens I mean splitting on blank and non word chars |
| 22:50 | jblomo | scottj: ^:private you mean? sounds good |
| 22:50 | user317 | nm, i think i just forgot to run lein deps |
| 22:50 | brehaut | ,(re-seq #\w+" "a list of tokens") |
| 22:50 | clojurebot | #<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: Unsupported character: \w+> |
| 22:50 | ShereKahn | in the patterns, I would have the full literal "group" "informatio" |
| 22:50 | brehaut | ,(re-seq #"\w+" "a list of tokens") |
| 22:50 | clojurebot | ("a" "list" "of" "tokens") |
| 22:50 | ShereKahn | brehaut, precisely |
| 22:50 | scottj | jblomo: yeah |
| 22:52 | ShereKahn | but when there is somethingI would like to extract, in the patterns, I would have a list with like (:group-number #"\d+) |
| 22:52 | jblomo | scottj: are you scottjad? |
| 22:52 | scottj | jblomo: yeah, thanks for the response on gh |
| 22:52 | ShereKahn | which would read the nuber and add it to a map |
| 22:52 | ShereKahn | so far so good. |
| 22:52 | ShereKahn | but then the problems comes when I would need to match "sub-pattenrs" |
| 22:53 | ShereKahn | that is a map, with a new list of patterns. |
| 22:53 | ShereKahn | and I would need to match it either once |
| 22:53 | ShereKahn | or multiple times |
| 22:53 | jblomo | scottj: np, i think i have a solution to the settings question using macros in clojruescript |
| 22:53 | jblomo | should be up tonight |
| 22:54 | scottj | cool |
| 22:54 | ShereKahn | this is where I am trying to loop multiple times to parse the sub-rule |
| 22:54 | ShereKahn | hence the original question. |
| 22:54 | ShereKahn | but it seems I have troubles when I have multple levels of sub-rules. |
| 22:55 | ShereKahn | So I was wondering whether loop (..... (loop ,,,, recur) recur) Was actually some construct that would work |
| 22:56 | brehaut | ShereKahn: thats exactly what my snippet did |
| 22:57 | ShereKahn | brehaut: correct me if i am wrong but your snippet is just breaking up a string into its tokens. I am speaking based on that list of tokens and a list of patterns to do some extractions |
| 22:58 | brehaut | ShereKahn: you asked if you could put a loop recur into a loop recur, and thats what i showed. i dont break up strings |
| 22:59 | brehaut | perhaps instead of going off into the woods, you could step back from what you are doing show some example input and output and get some feedback on less iterative approachs to your problem |
| 23:00 | ShereKahn | brehaut, well actually sorry, the first snipped showed that. |
| 23:07 | Tcepsa | ShereKahn: I don't think it is possible to have nested loops like that in the same function, but if you put the inner loop in a separate function and then call that function from the outer loop, I think you can achieve the effect you are talking about. |
| 23:09 | ShereKahn | here's my code, with examples for the templates and the data I try to parse : |
| 23:09 | Tcepsa | ShereKahn: Th |
| 23:09 | ShereKahn | http://pastebin.com/U6xk4Yya |
| 23:10 | ShereKahn | Sorry it's crude, but it's my first real project using clojure ... |
| 23:11 | ShereKahn | I was thinking of scratching that all together, and re-write it using a ref or something so that I could have state, but that so un-lispy ... |
| 23:15 | brehaut | about as unlispy as a 38 line function ;) |
| 23:16 | ShereKahn | hehe :) |
| 23:16 | ShereKahn | yeah I guess so :) |
| 23:16 | brehaut | there shouldnt be any need to store state in a ref however |
| 23:17 | brehaut | and the only tricky thing with using fnparse to consume this is going to be the indentation rules |
| 23:18 | ShereKahn | the thing is, I have a couple of different outputs of the same type, that is why I tried to use patterns to match things rather than the full machinery of fn parse, |
| 23:19 | ShereKahn | in the end all I need is a map with the values inside with some structure |
| 23:20 | Tcepsa | I'll admit that I am not able to follow exactly what each part is doing, so this might be a stupid question, but could you replace either or both loops with a map/reduce constrct |
| 23:20 | brehaut | thats no excuse for doing it that hard way :P nobody awards macho points |
| 23:20 | ShereKahn | and with fn-parse, I could not find an easy way to match the first line and extract the # at the end of the line... but again I did not spend hours on fn-parse... so maybe there is an easy way |
| 23:20 | ShereKahn | well I would welcome any advise of doing it simpler. |
| 23:20 | ShereKahn | :) |
| 23:21 | brehaut | im at work at the moment so i cant dive in to a complicated solution sorry |
| 23:22 | ShereKahn | and for the map/reduce... don't think it's possible given I have 2 lists to traverse in parallel, one where I might need to repeat the paterns multiple times (thikn .* on regexp) |
| 23:25 | ShereKahn | So the initial Idea is that the parser returns a vector of 2 entriees , first is a map of transformed tokens, second is the remaining tokens to be read. |
| 23:25 | ShereKahn | the tricky part is actyally when I have a template inside a template, that I will repeat zero or multiple time |
| 23:26 | ShereKahn | that's where a state might have helped me I think, |
| 23:26 | ShereKahn | to make sure I recur with the right pattern. |
| 23:26 | ShereKahn | anyway thanks for your help guys ... |
| 23:27 | Tcepsa | Good luck! |
| 23:36 | user317 | hmm, i m not getting something about how :use works, i have (:use [lamina]) but i am getting: Caused by: java.io.FileNotFoundException: Could not locate lamina__init.class or lamina.clj on classpath: |
| 23:40 | tbatchelli | is it possible to conditionally import a namespace with 'ns'? (e.g. to import certain namespaces depending on whether particular library is in the classpath), or resorting to the namespace primitives is the way to go? |
| 23:50 | icey | how many people were at the conj last year? |
| 23:51 | scottj | ~200 |
| 23:51 | clojurebot | Huh? |
| 23:51 | icey | wow, that's a pretty good number |