text:
# #clojure log - Nov 08 2008

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

3:38 knobo: I have some problems starting clojure. Is there a paste-bin I can use?

3:39 I start clojure like this: java -cp clojure.jar clojure.lang.Repl

3:39 H4ns: lisppaste8: url

3:39 lisppaste8: To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.

3:39 knobo: And I get lot's of error messages. It starts with Exception in thread "main" java.lang.ExceptionInInitializerError

3:40 lisppaste8: knobo pasted "Error booting clojure" at http://paste.lisp.org/display/69939

3:42 knobo: $JAVA_HOME is /usr/lib/jvm/java-6-sun-1.6.0.07/ 3:43 I don't know anything about Java. Maybe I shood learn java before clojure? 3:43 Cark: i don't know anything about java either ....but it's manageable it seems 3:44 H4ns: are you starting java in the directory that clojure.jar is in? 3:44 knobo: yes 3:44 ls -l clojure.jar gives -rw-r--r-- 1 knobo knobo 498538 2008-11-08 09:32 clojure.jar 3:45 H4ns: did you compile clojure yourself? 3:45 knobo: yes, at 09:32 3:45 H4ns: what java version do you use? 3:46 knobo: haha! I did not know... java version "1.5.0" gij (GNU libgcj) version 4.2.4 (Ubuntu 4.2.4-1ubuntu3) 3:47 H4ns: erm 3:47 my guess is that you need sun java 3:47 knobo: Maybe better use sun. 3:48 H4ns: also, you will need to learn java to some extent in order to use clojure. 3:48 Cark: learn to use javadoc and you're all set imho 3:50 knobo: Do I nead to do some kind of "make clean"? 3:50 I also don't know ant 3:51 H4ns: you can remove all .class files 3:52 knobo: Hurra! 3:52 I made it :) 3:52 Cark: bravo ! 3:54 knobo: I can see. I need too learn swing, and other APIs 3:54 libs. 3:55 Cark: i would recommend learning MigLayout along with swing 3:56 knobo: Can I load .jar files dynamicly after cojure has started? 3:56 hmm. well. I'll start by reading some docs. 3:57 Cark: knobo : i have a directory in the classpath with all the jar files i want to use, then just (import) them 3:58 knobo: So (import "MigLayout") should do it then. 3:59 Cark: let me copy past a namespace declaration 4:00 lisppaste8: cark pasted "example namespace" at http://paste.lisp.org/display/69940 4:04 knobo: thanx 4:09 Is the slime patch maintained? 4:11 Cark: i don't know 4:24 knobo: How about using eclipse. Is that what people is doing? 4:25 I would like to know some best pratises 4:30 Cark: i'm using slime 4:31 i hear there's a netbean add-on too 4:31 though i would think that emacs is best suited for sexpr based languages 4:42 knobo: It would be nice if http://clojure.org/api had examples for each function. Like hyperspec have. 4:44 Cark: yep that's a problem ... 4:45 there's the wiki-book with a few examples 4:45 knobo: Why is it a problem. A wiki would solve that (almost). 4:45 :) 4:46 Cark: well clojure is still pretty much a moving target 4:47 examples should show up in the doc strings, that would be perfect, commiters could update it in place 4:48 they're talking about making a test suite too, that would be even better ! 4:49 knobo: Is clojure written in clojure? 4:50 hmm, no it's not.. 4:50 Cark: nope ...much is done in boot.clj, but the basis is java 4:55 knobo: boot.clj is mostly understandable :) 4:56 Cark: it's a good reference 4:56 when you don't know how to use something 4:56 knobo: It solves a lot of the missing examples 6:48 Lau_of_DK: Good afternoon guys 6:49 Cark: hello lau_of_dk 6:57 Lau_of_DK: Anybody here got some interesting projects on Sourceforge (Clojure ofc) ? 7:17 kib2_away: hello, I wanted to know how to add a .jar to my classpath 7:18 Lau_of_DK: java -cp /path/to/your.jar:/path/to/clojure.jar clojure.lang.** 7:18 rhickey_: djkthx: still here? 7:19 kib2_away: Lau_of_DK: thanks ! 7:19 Lau_of_DK: np :) 7:19 Unless your on Windows kib2_away ? 7:19 kib2_away: Lau_of_DK: yes, I'm on windows 7:19 why ? 7:19 Lau_of_DK: Then I think its java -cp "c:\jar1.jar;c:\clojure.jar" instead 7:20 The syntax is a little different 7:20 kib2_away: ok, " are there to handle spaces I think 7:20 like "Documents and Settings/..." 7:20 Cark: most important is the : which becomes a ; 7:21 Lau_of_DK: ok 7:21 kib2_away: I've tried inside my code to use (add-classpath "file://core.jar") but it fails under windows. Do i miss something ? 7:22 maybe my classpath is not well configured 7:22 philed: I'm hoping to use Clojure for my next project, since it ticks most of the boxes I want for the purpose. One thing I'm concerned about is whether there currently is or will be a means to do the equivalent of reflecting into packages and the symbol table as in CL. Any ideas? 7:24 Cark: i'm calling clojure with java -cp c:\path\to\libs\*;c:\clojure\clojure.jar clojure.lang.Repl 7:24 then i only need to (require com.some.lib) 7:24 rhickey_: philed: look at: (find-doc "ns-") 7:25 kib2_away: Cark: nice tip, thanks. 7:25 Cark: err not require but import ! 7:25 kib2_away: Cark: import or use ? 7:26 Cark: import for java stuff 7:26 philed: Unfortunately, I don't have clojure installed on my home machine at the moment. But I'm thinking more like "do-symbols" and "find-symbol" and "find-package" and so forth. 7:26 Lau_of_DK: philed, take a look at this http://paste.lisp.org/display/67122 7:28 lisppaste8: rhickey pasted "ns fns" at http://paste.lisp.org/display/69948 7:28 philed: Very nice. That should be all I need. 7:29 It would be good to get this hooked up to SLIME so we can get some auto-complete working. 7:29 Lau_of_DK: :) 7:30 I think we need to review the wiki's recommendations on setting up slime, for every 1 person who gets it working there seems to be 10 who cannot 7:32 philed: It took me a while. I can't remember what the problem was. But I take it I have it set up correctly: there is no tab-completion available at the REPL, or any information about function arguments in the minibuffer as you type? 7:33 kib2_away: philed: C-c M-i does not do completion in Slime ? 7:34 Cark: philed : i have both 7:34 philed: Ah okay. Something's wrong with my setup then. 7:34 Chousuke: I set up tab completion manually 7:34 but the minibuffer info should be there. 7:35 philed: Yes, I've read a few articles about doing tab-completion yourself, by loading in a database of function definitions and so forth. But I want this done automatically, with updates every time I write a new function. 7:35 Chousuke: no I mean I set up tab completion separately from slime :) 7:35 Cark: swank-clojure provides this, it should work out of the box 7:35 Chousuke: it does update automatically. 7:35 philed: Okay, then I definitely have done something wrong. 7:54 Okay, so does the clojure swank server use the java reflection API to do all the tab-completions and other such stuff? 7:54 Cark: nope 7:55 philed: Any idea how it works then? 7:55 Cark: it does completion for the clojure stuff only 7:56 philed: Okay, so does it work in any way like slime for CL? 7:57 Cark: i don't know ... i'm a lispworks user. 7:57 it uses the namespace api at http://clojure.org/namespaces 7:59 you can check this in swank-clojure\swank\commands\basic\ 7:59 i think adding the java reflection completion would be trivial 8:00 philed: Ack! I don't know what I'm talking about then. I read "the read table is currently not accessible to user programs" on the website and stupidly confused "read table" with "symbol table". 8:00 I had thought Clojure had no support for the equivalent of first-class packages, but it obviously does (and damn well should!) 8:01 Still, surely swank could be extended to use both the ns API and Java reflection? 8:01 Cark: has to because of the lisp1 thing 8:01 philed: Why would lisp1 force it to? 8:02 Cark: because of name clashes 8:03 can you imagine a single namespace a la emacs 8:03 that's ugly 8:03 philed: No I don't mean that. I specifically mean *first-class* packages. That is, packages and symbols that are first-class objects. 8:03 So you can do things like enumerate the symbols interned in a package. 8:04 Cark: you know what, i never understood the meaning of "first class" =P 8:04 rhickey_: philed: Clojure's namespaces are first class but Java's packages are not 8:04 philed: I'm not sure I could give a formal definition. I would say anything which can be bound to a variable is a first-class object. 8:04 rhickey_: but I do think IDEs/Slime could do Java completion too 8:05 there are some context hints (like the presence of . ) that can help 8:05 Lau_of_DK: rhickey_, would you mind setting that up and then updating the wiki accordingly? :) 8:05 rhickey_: but being dynamically typed, a lot of the hooks used by Java IDEs won't work 8:06 philed: rhicker: That sucks. I don't really know much Java, but then, since I'm not going to be writing much Java code, it should be possible to just put lots of metadata around existing java functions so we can get autocompletion and documentation via "find-doc". Unless this has already been done. 8:06 Chouser: nono, that's not rhickey_'s job 8:06 let him get AOT and io streams working. :-) 8:07 Lau_of_DK: I knew it was a long shot :) But they dont call me 'The Delagator" for nothing. No I actually already asked Chousuke to review the wiki, because he seems to have a well-working slime-setup 8:08 rhickey_: Chouser: It looks like cgrand is ahead of me on the io enumerators, so I hope he runs with that, then we can get it done in parallel - trying to get a dialog with him going on the group about it so everyone can follow along 8:08 philed: rhickey: By the way, though I haven't started coding in it yet, I have extremely high hopes for Clojure. The design philosophy matches up pretty much precisely with what I want from a language. 8:08 Great work! 8:08 rhickey_: Chouser: simpler doseq looks nice, I have 2 nits 8:08 philed: thanks! 8:08 Chouser: rhickey_: ok, go for it. 8:08 rhickey_: Chouser: will paste momentarily 8:09 Chouser: I got far enough in implementing that paper's io ideas, that I'm now pretty excited to see it implemented. 8:10 rhickey_: Chouser: yes, will be great addition 8:10 Lau_of_DK: rhickey_, I know this is probably also a long shot, but all these talks your doing around the US, is there any chance you'll have an oppotunity to do any such thing in Europe, preferably Scandinavia, preferably Denmark? :) 8:10 Chouser: Unless I'm missing something it won't be hard to *do*, it's more a matter of doing it well. 8:11 rhickey_: Chouser: yes, lots of little details, EOF, done protocol, timeouts etc 8:11 philed: rhickey_: Are Clojure namespaces hierarchical? 8:11 Chouser: philed: nope 8:11 rhickey_: Like most of Clojure, I'd like it to be part of a unified model, in this case making sure it encompasses queues well 8:12 Chouser: philed: but it's convention to use . to separate parts of the namespace name 8:12 philed: when used with "use" and "require" the name parts are mapped to directory names on disk, just like java packages. 8:12 lisppaste8: rhickey annotated #69926 with "doseq nits" at http://paste.lisp.org/display/69926#2 8:13 Chouser: apply assoc is good 8:13 philed: Any explanation for why? I've done things in CL to get something like hierarchical packages, extending the existing hacks in CMUCL. It's nice to be able to use relative namespace names. 8:14 Lau_of_DK: rhickey_, I know this is probably also a long shot, but all these talks your doing around the US, is there any chance you'll have an oppotunity to do any such thing in Europe, preferably Scandinavia, preferably Denmark? :) 8:14 Chouser: but I don't think I can use destructuring at that point to boot.clj (I tried to at first) 8:14 rhickey_: Chouser: ah!, didn't consider that 8:14 Chouser: so apply emit was my hack attempt to use & in the fn instead 8:15 rhickey_: generally, if you always apply a fn, the sig is wrong 8:15 Chouser: I had to move partition up too, but that seems to be ok. 8:15 rhickey_: apply is fine then 8:16 I'll try your patch today if it's ready - might as well break everything at once :) 8:16 Chouser: Maybe a comment to warn people reading boot.clj looking for examples of how code should look. 8:17 rhickey_: Chouser: yeah, I'd love to just go through it and change all the Java interop to the latest conventions too 8:17 Chouser: heh, ok! You want a fresh patch against 1089? 8:17 rhickey_: but there will always be some trickiness to the bootstrap order 8:17 Chouser: yeah 8:18 rhickey_: Chouser: fresh patch welcome 8:18 Chouser: ok. no need for extra exception throwing as mentioned in the groupthread? 8:18 for "too many bindings"? 8:19 rhickey_: Lau_of_DK: no plans for Europe yet - please send plane tix :) 8:20 philed: rhickey: Maybe I could persuade some of the Foundations of Computer Science people here in Edinburgh to get you over for a talk. Philip Wadler likes Lisps. 8:20 rhickey_: Chouser: no, let's keep it simple, I don;t think people will be inclined to try multiple bindings in if-let 8:21 philed: um, Wadler likes to beat up on Lisps :) 8:21 Lau_of_DK: rhickey_, Im sure air-fare wont be a problem, but if any such practicality is preventing you, feel free to let me know, I'll help resolve it 8:22 philed: rhickey: He does? He's got a copy of the "God codes in Lisp" poem on his blog, so I thought he would probably be into them. But then, being a Haskell guy, he probably hates dynamically typed languages. Haven't chatted with him about Lisp, actually. 8:22 rhickey_: philed: those folks are way into type systems, so Clojure is rather primitive from that point of view 8:23 philed: He gave a talk at a Lisp conf to the effect of - God codes in a strongly typed lambda calculus 8:23 philed: rhickey: Yep. I like type-systems as well from an intellectual point of view, and I think what Ocaml does is pretty amazing (static duck typing). I've also seen some cool tricks with the type systems, but they seem as obscene as template metaprogramming in C++ sometimes. 8:28 arbscht_: Lau_of_DK: while you're at it, sponsor him a trip to new zealand too! :) 8:30 Chouser: and Indiana. :-P 8:33 philed: So going back to hierarchical namespaces: the only behaviour I like (which you can hack into CL) is to have it so that all symbols in a namespace foo are automatically interned in the namespace foo.bar, and having it so that, while in the namespace foo, the namespace bar can be referred to with a relative namespace name, perhaps just "bar". Depending on how the reader works, you can always add this behaviour to CL. Is it p 8:33 ossible in Clojure, or there already? 8:36 Hope this question isn't impertinent by the way. It hasn't been discussed to death already on newsgroups? 8:46 rhickey_: philed: I want to hold off on that until I see a need - with aliases, I don't see it 8:46 complexity/utility ratio is not good 8:49 philed: Would it be possible (for me) to write it as a library on top of Clojure? In CL, all you need to do is rewrite find-symbol and add a macro to define nested packages. It just requires that the reader looks up symbol definitions by using a function like "find-symbol" which can be rebound to a user-defined function. 8:49 Of course, that latter issue is not guaranteed by the CL specification. 8:51 rhickey_: philed: as evidenced elsewhere, I'm not inclined towards language customization outside of macros, esp. reader customization, as such customizations can't be combined 8:57 philed: That's fair. It opens the door to abuse. I think getting hierarchical packages in CL was justified though, since I feel there is a fair amount to be gained from them. In CMUCL, they are available out of the box. 8:57 But again, as a reader customisation. 8:58 rhickey_: Java and C# have much larger libraries and flat namespaces have been sufficient there, IMO 8:59 again, it's not that they are bad, just the complexity/utility ratio 9:01 philed: But those languages rely on OO for much of their modularity, and their model of OO means that classes *are* effectively namespaces, and are frequently nested (right). With generic functions, you don't have this, and besides, aren't you putting much less emphasis on OO with Clojure? 9:04 Chousuke: deep nesting gets confusing pretty quickly :/ 9:04 rhickey_: philed: yes, classes are namespaces, no, not too frequently nested, yes, Clojure is not very OO. That said, a one-line alias or :as at the top of a file le's you get a short name for anything vs everyone (incl. tools) having to understand hierarchical namespaces. It's simply a tradeoff 9:06 philed: rhickey_: Okay, cool. I'll trust your experience on this one and try hacking with flat namespaces. There's always a chance my early exposure to C++ has clouded my judgement on this matter. 9:07 Chousuke: Right, there's be diminishing returns involved. And I have noticed this with my own code, even with only three levels of nesting. 9:09 Chousuke: on thursday I was watching a presentation about distributed systems on .NET, and the guy did a code demo. Everyone (including the speaker himself) laughed a bit when he read aloud code that accessed a property that was nested at least 5 levels :P 9:10 philed: Chousuke: Java and C# have the whole "kingdom of nouns" thing going on which just compounds the problem. 9:24 Chouser: Yegge's got reach, doesn't he. If only Google would let him use Clojure. 9:28 drewr: I don't see why he couldn't. They already have a huge JVM infrastructure. 9:28 Should be easier than the Ruby battle he's been fighting. 9:29 Chouser: Google only allows javascript, java, C, and python (from what I understand) 9:29 he's only allowed to do his Rhino experiments because it's js and java. 9:30 Chousuke: I took a look at the wiki slime set up guide and changed it a bit to match how my setup is done. 9:30 I don't know if it works for others but it works for me :/ 9:30 mostly it was the same though. 9:30 drewr: Chouser: He's said that limitation is based on deployment. Clojure would require little infrastructure change if any. 9:31 Chousuke: I also added a tab completion trick I found on the internet somewhere that I use 9:33 Chouser: with the possible exception of C-like syntax, clojure is so much closer to what he seems to want than javascript it. 9:35 drewr: I get the impression he'd prefer a lisp if it was practical. I think he only puts up with JS because it's the most lispy of the mainstream languages. 9:37 I find it ironic that people complain about lisp's parens. I look at javascript and I am blinded by the braces, especially if I write it in a functional way. 9:39 hola wilkes 9:40 kotarak: drewr: (-> obj .getAThing .makeMore .actions) vs. obj.getAThing().makeMore().actions()... 2 vs. 6, aha, so Java is the actual Lisp... 9:41 wilkes: howdy drewr 9:42 drewr: I made a bit of headway yesterday on the pivotal-tracker client 9:42 drewr: kotarak: :-) 9:43 wilkes: accidently created a DSL 9:43 drewr: I see that. 9:46 philed: kotarak: Still, there is something to be said in the fact that I couldn't write Lisp code without paren matching switched on, while I can write procedural code with C-like syntax without any difficulty.. That said, when you have paren-matching, I have not found Lisp syntax any more of a pain than any other language, and the benefits of code-as-data and syntactic macros make Lisp syntax far superior. Now that mainstream lan 9:46 guages such as C# are taking syntactic abstraction seriously, I think it will be easier to convince programmers of this, especially when working with C# expression objects (and Ocaml expression objects) is so much more painful. 10:13 rhickey_: Chouser: bindings patch applied - rev 1090. Thanks, that's a significant contribution! 10:14 Chouser: great, thanks. 10:14 i assumed there were a dozen or more such macros, so it's not as significant a contribution as I assumed it would be. :-) 10:15 rhickey_: still a lot of work - I appreciate it 10:17 Chouser: you're quite welcome. I'm all about breaking other people's code. 10:18 rhickey_: nice 10:18 aargh, forgot to give you blame, er, credit in the checkin comment 10:20 Chouser: :-) no worries. 10:20 rhickey_: I guess there's a lot todo to bring contrib up to speed too 10:21 Chousuke: doseq etc. are like let now? 10:21 rhickey_: The next phase of AOT is a big one for contrib - moves directories around 10:23 also for AOT the mappings will now be from my.company.lib ns to class lib in my.company package Java-wise 10:23 this won't affect ns/require/use et al, but will lift everything up a directory 10:24 but biggest change is that clojure ns should really be at least one nested, lest it have no Java package, e.g. clojure.core 10:25 thinking about some standard aliases - core/set/xml/zip etc 10:27 Chouser: bah, I forgot to add the comment for (apply emit binds) 10:27 rhickey_: Chouser: when people start noticing that we'll be in good shape 10:28 Chouser: heh 10:32 djkthx: rhickey_: here now 10:33 rhickey_: djkthx: you were doing sieve? 10:34 djkthx: yeah 10:34 rhickey_: I had a faster version, here: http://paste.lisp.org/display/69952, commented on your blog 10:34 djkthx: yeah, why is it faster? 10:35 rhickey_: djkthx: because it uses primitives 10:35 djkthx: ah, gotcha 10:35 cool 10:35 thanks :) 10:35 rhickey_: sure 10:36 Chouser: I was noticing that since doseq uses loop/recur, it could benefit from primitives, except there's no way to specify them. 10:37 would the benefit be to little just because it's always pulling from seqs? 10:37 rhickey_: Chouser: doseq uses numbers? 10:38 or if the seq contents are numbers? 10:38 Chouser: if the seq contents are numbers. range, primes, fibs, etc. 10:39 rhickey_: yeah, time will probably be dominated by seqs 10:40 Chouser: ok. 10:41 rhickey_: numbers will be boxed in seqs anyway, unbox is no big deal 10:43 Chouser: You might get primitive logic in :when and :while, but I can see it might not help much. 10:44 rhickey_: once you are at that point you're looking at amap/areduce anyway 10:45 Chouser: pity. :-) 10:45 rhickey_: tagged numbers needed to do better with Object-based interfaces 11:09 lisppaste8: mibu pasted "line-seq" at http://paste.lisp.org/display/69962 11:10 mibu: I have a question regarding recursive calls. 11:10 What exactly is the semantics of recur? 11:11 Chouser: recur is like a call to the immediately containing function or loop 11:11 except it doesn't consume a stack frame 11:13 mibu: Well in the paste above, line-seq recursively call line-seq. I assume it's possible because defn creates a var of line-seq instead of a let binding. But shouldn't that have worked with recur instead of line-seq? (It doesn't) 11:14 kotarak: The function returns, before the "recursive" call happens because of the lazy-cons 11:16 Chouser: yeah, lazy-cons is the key. Neither of it arguments is evaluated immediately; they're both deferred until needed. 11:16 mibu: ok. so how do I create recursive references when not using defn? for instance in a let binding clause: (let [lines (something) seqqer (fn [seq] (lazy-cons (re-seq #"\\w+" (first lines)) (seqqer (rest lines))))] (seqqer lines)) 11:17 seqqer is not recognized in the fn def. 11:17 kotarak: seqqer (fn seqqer [seq] ...) 11:17 (where seq is a bad local variable, because it shadows the function seq) 11:18 mibu: oh! thanks. 11:18 isn't it a little redundant? 11:19 kotarak: I almost never need it. 11:19 but letrec is on the TODO list 11:21 mibu: why use a different symbol for a recursive let? 11:35 AWizzArd: Moin 11:43 mibu: Is there a last-value-evaluated var in the REPL (like '*' in CL)? 11:43 rhickey_: mibu: *1 *2 *3 11:43 kotarak: *1 *2 *3 *e (<- last one is exception) 11:44 mibu: thanks. 11:45 ah, that's not in the latest release (...0916), right? 11:45 AWizzArd: try the svn 11:45 mibu: I will. 11:47 Chouser: don't use the *latest* svn, though, unless you're feeling adventurous. 11:47 rhickey_: mibu: the last 2 checkins contained significant changes - try rev 1088 for the smoothest ride 11:48 anyone have any issues with clojure ns being renamed clojure.core ? (aside from the breakage) 11:48 mibu: rhickey: thanks. I will. 11:49 kotarak: rhickey_: why not clojure.lang? Would match the java side. (Although that might be a problem)... 11:50 rhickey_: kotarak: I'd rather avoid mixing the generated classes from the two sources 11:50 also would cause a class and a package to be called clojure.lang 11:51 most of what is in there (currently boot.clj) is core library, not language syntax 11:51 so seems easiest to have a different name 11:52 kotarak: just an idea.. Separating the underlyings from the core librarary running on the former is a good argument 12:07 mibu: Is there an active issue tracker somewhere? (todo list, feature requests, known bugs, release schedule, and the like.) 12:08 kotarak: mibu: TODO list: http://richhickey.backpackit.com/pub/1597914 12:08 mibu: thanks 12:09 kotarak: mibu: feature request are discussed on the Clojure list of google groups 12:09 mibu: bugs are dropped here and are immediately fixed by Rich. :) 12:09 mibu: :-) 12:09 kotarak: (of course they can also go to the Clojure list) 12:12 mibu: the group is good to keep track of what's happening right now, but for newcomers (I am one) it's hard to see what was already discussed in the past without reading everything. right now, I'm trying to wrap my head around what's the current status of things and where it's going. 12:14 rhickey_: mibu: I hope to move to a tracker soon, the todo represents those things that made it onto the agenda 12:15 scary - just got rid of clojure namespace 12:15 (and Clojure still works) 12:16 kotarak: Clojure finally transcedented to a higher being and doesn't need such profane things like a namespace anymore. 12:17 mibu: rhickey, is the project right now still rapidly changing or is it converging to something stable enough for production code? 12:17 (I'm good with rapidly changing. I just need to know) 12:18 AWizzArd: I feel its rapidly changing into something stable for production code :-) 12:18 mibu: :-) 12:18 rhickey_: mibu: there are very few breaking changes. A few have built up and I am putting them in now in prep for a 1.0 release. While there is a lot of dev activity, it's mostly enhancements/additions 12:19 kotarak: I had relatively few troubles lately. The biggest fluctuations in my code were during the require/use/ns transitions. 12:19 AWizzArd: As soon we can compile everything into .class files and deliver apps the biggest hurdle for some companies is gone. 12:19 rhickey_: It only seems rapidly changing for those that want to try the latest toys 12:19 AWizzArd: ...and deliver apps without delivering code... 12:20 rhickey_: AWizzArd: coming soon 12:20 AWizzArd: yes, and I am beginning already translations 12:21 mibu: I think it makes sense to begin *now* to work on your products. If it is something that needs several months anyway then everything will be in place as soon you are done. 12:22 mibu: I'm all good with changing tech (what else am I doing here?), but my colleague are not. Changing tech means it's improving and not yet bound by compatibility issues and standards (like CL). 12:22 colleagues* 12:23 AWizzArd: we are not forced to use newer versions.. one could simply stick to one of them and nothing will change 12:24 rhickey_: AWizzArd: true, the only caveat being that right now bug fixes and new features come together 12:25 mibu: awizz: yeah, but when things change fast you want all the latest cool toys at your possesion. otherwise you feel like using tape recorders in a world of Ipods. 12:26 AWizzArd: Yes, that's right. Anyway, Clojure was done mostly right, and I think there won't be dramatic changes that would force us into full rewrites. But standing still like CL mostly is, is also not a good option. 12:30 mibu: I think CL also got the basics right, the only cardinal problem was the libs. Think about CL with a Java like library and it's pretty sweet. Of course, I welcome the much improved changes in clojure. 12:32 AWizzArd: CL still challenges us to not do what it offers: like imperative programming. One of the reasons that CL has not enough libs is that one needs big efforts to make them compatible. 12:32 Java allows more or less only one way to do it. So everyone has to do it the same way, and often ends up with libs that can be shared and used with/by others. 12:36 mibu: now that I think of it, every single successful language in the last years became successful thanks to a batteries included philosophy--large useful well-documented library. It worked for perl, java, python, and I assert it's also true in relative terms to C. 12:39 AWizzArd: Sure, a large library is the most important factor for productivity. The biggest factor for productivity is code reuse. If systam A already has a lib to do some stuff then making just a few calls is simply the easist thing to do. Clojure is prepared here, as Java offers the more or less biggest code base. 12:43 mibu: now that the library factor is covered, I think concurrency is the biggest issue, and immutability pretty much untangles that. Now the last two factors left is documentation and a following. 13:03 1088 rev broke something with regexes. Is it just me? 13:03 (moved from the 0916 release to 1088 svn) 13:05 basically, \ doesn't need to be escaped 13:05 anymore 13:06 mibu: Ah, thanks. That did it. 13:10 People working with code from Eric Rochester's blog will have problems. http://writingcoding.blogspot.com/2008/06/tokenization-part-2.html 13:12 Google's captchas are getting ridiculous. I tried living a note about the change in the above link, but couldn't decipher the captcha... 13:12 * mibu is coming to a realization he is not human. 13:13 mibu: *leaving 13:54 AWizzArd: rhickey_: http://clojure.org/functional_programming .. ca. at the middle of that page a (def vec [1 2 3]) is suggested. Most people will have a problem when they try it in the default namespace. 13:58 rhickey_: a little typo in "defonce". It should be "if" instead of "iff" I guess. 13:59 rhickey_: AWizzArd: page fixed - thanks 14:00 AWizzArd: iff == if and only if 14:00 AWizzArd: I see 14:00 rhickey_: in (defn concat ... ) there is a (if (seq x) ..) was this supposed to be (seq x) or should it be (seq? x) instead? 14:01 (in the now newly named core.clj) 14:01 rhickey_: AWizzArd: wow, you are bleeding edge 14:02 it is correct as is, testing a seq for non-nil idiom == is there more?, seq call only needed because it might not yet be one (i.e. an empty vector) 14:18 Jedi_Stannis: Hi, I'm trying to access javax.swing.GroupLayout.Alignment.TRAILING and the other Alignment constants, but can't fgure out the syntax for it in clojure 14:20 Chouser: javax.swing.GroupLayout$Alignment/TRAILING

14:20 $for a nested class, / to access a static member of that class 14:22 Jedi_Stannis: is that document anywhere? I didn't see it anywhere on the website, I knew about / just not$

14:23 rhickey_: Jedi_Stannis: http://clojure.org/java_interop

14:24 Jedi_Stannis: oo, its kinda hidden in the . special form, I was looking for something in bold

14:25 thanks though

14:26 I have GroupLayout imported, but still need to fully qualify for $Alignment to work, is that expected? 14:26 rhickey_: GroupLayout and GroupLayout$Alignment are 2 different classes

14:28 you can import it too (import '(javax.swing GroupLayout GroupLayout$Alignment)) 14:28 Jedi_Stannis: got it 14:28 thanks 15:38 AWizzArd: rhickey_: motivated by the google groups kotarak and I were discussing about why do is a special form and not simply implemented as a function: (defn do [& body]) 15:42 Chousuke: hmmh 15:42 rhickey_: while everything can be looked at as an expression in CLojure, some things are not actually expressions and I have to fake it, like void methods 15:43 those are exactly the kinds of things you'll have in do bodies, in which case there is no realized expression value produced 15:43 if they were fn args I'd have to produce them 15:43 plus there's some overhead to & body and arg packing 15:44 AWizzArd: I see, thanks 16:28 sohail: do you guys use ns for multi-file projects? 16:29 Chouser: depends on why I'm using more than one file 16:29 sohail: Chouser, interesting statement. for me, I'm writing an app that is getting too big for one file now :-) 16:31 Chouser: clojure.contrib.lazy-xml has two files. The secondary file depends on a 3rdparty lib, so the main file uses load in a try block to use the 3rdparty lib if it's there or to fail gracefully if it's not 16:31 sohail: where is clojure.contrib? 16:32 Chouser: clojure.contrib.zip-filter has a set of features just for xml that not all users will need, so it's in a separate namespace, clojure.contrib.zip-filter.xml 16:33 sohail: Chouser, ok none of these sound like: "This file is too damn big." 16:33 Chouser: https://clojure-contrib.svn.sourceforge.net/svnroot/clojure-contrib clojure-contrib 16:34 sohail: yeah, I haven't run into that problem yet. 16:34 sohail: ok so say you had, would you be using ns for that? 16:34 Chouser: I guess it depends on your definition of "damn", or perhaps "big". Have you seen boot.clj? 16:34 sohail: I have 16:34 Chouser: >3600 LOC -- you've got more than that? 16:35 sohail: no 16:35 that's pretty damn big though 16:35 besides, I'm putting a lot of stuff together that really shouldn't be... mixing GUI and non-GUI things 16:35 Chouser: I guess if there are natural divisions, esp. reusable chunks, I might break those into namespaces. 16:36 otherwise I'd tend to keep it in one big file. 16:36 I'd rather have a big file, then have 2 small ones and not be sure where exactly I put a particular function. 16:36 than 16:37 gotta go 16:37 AWizzArd: I sometimes can't decide when something should go into another file. And even in one file I am sometimes splitting functions into 2-3 parts, although these are then used only once, for the main function. 16:37 sohail: where's the ant colony simulation code 16:38 that's gotta be kinda big atleast 16:38 AWizzArd: sohail: check GG or the vid 16:39 sohail: AWizzArd, what is GG? 16:39 and I saw the vid, but it was not obvious how the code was structured 16:39 AWizzArd: google groups 16:39 sohail: the code is attached to the vid, there is some link below the vid itself 16:40 sohail: lol, that's tiny 16:42 AWizzArd: 150 loc for the non-gui stuff, without comments and whitespace-only lines 17:15 knobo: Is it possible to write java objects in clojure? 17:15 sorry 17:15 delete that line 17:15 Is it possible to define java classes 17:15 kotarak: Yes. With gen-class 17:15 (doc gen-class) in the Repl gives more information 17:16 AWizzArd: note it is possible though that gen-class will get replaced by something 17:17 knobo: So I could use clojure when working with tomcat for exaxmple 17:17 AWizzArd: absolutely 17:17 everywhere, where you can also use Java 17:17 knobo: For mobile-phone applications 17:18 AWizzArd: yes 17:18 and soon this will be simpler 17:19 knobo: I feel I am starting to become a member of the society again :) 17:19 AWizzArd: the mobile phone stuff will probably be more available in 2009 as I understand it 17:19 knobo: I have been an outsider, programming in common-lisp 17:20 AWizzArd: I also come from CL 17:20 knobo: I actualy have a paid job programming CL :) 17:20 for now.... 17:20 AWizzArd: same with me :-) 17:21 Clojure will offer most Lispers a way to get a job in which they can do Lisp 17:22 knobo: even openoffice.org 17:23 danlarkin: is there a class that all clojure collections implement? 17:23 AWizzArd: what do you mean? 17:23 danlarkin: you mean class or interface? 17:23 rhickey_: danlarkin: clojure.lang.IPersistentCollection 17:24 danlarkin: rhickey_: thanks :) 17:25 rhickey_: chart courtesy of Chouser 17:33 AWizzArd: rhickey_: is it easy to use the Clojure datastructures in Java too? 17:35 rhickey_: AWizzArd: sure, there are interfaces for everything. Their functional style is not idiomatic Java, though 17:36 AWizzArd: But does one need to do a lot of casting? I don't understand the static type system of Java not well enough. I think Clojures DS all work on Object and could need casting 17:37 -not 17:37 Moin Lau 17:37 Lau_of_DK: Ola AWizzArd 17:38 rhickey_: AWizzArd: yes, they are all Object based, just like pre-generics Java collections 18:00 sohail: hmm.. anyone getting this with latest clojure: Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class clojure.lang.RT at clojure.lang.Script.main(Script.java:71) 18:00 Lau_of_DK: no 18:00 sohail: seems clojure.lang.Repl has disappeared for me too... maybe I need to rebuild it again 18:01 Lau_of_DK: distclean 18:01 sohail: Target "distclean" does not exist in the project "clojure". 18:02 * sohail is using ant 18:02 rhickey_: ant clean ? 18:03 sohail: tried that too 18:04 Lau_of_DK: hehe 18:04 I know, I just meant, clean up the old before you start on the new 18:06 sohail: crap client on phone 18:07 https://clojure.svn.sourceforge.net/svnroot/clojure/trunk is the right branch right? 18:08 rhickey_: sohail: stick with rev 1088, lots of changes in last few checkins 18:09 sohail: rhickey_, ok thanks 18:09 ok this version works 18:10 kotarak: sohail: with the latest check-in clojure is gone. 18:10 sohail: clojure is dead, long live clojure.core 18:10 sohail: kotarak, oh noes 18:10 ah, I see 18:10 so clojure.core.Repl? 18:10 kotarak: sohail: just kidding. Rework of the clojure namespace. 18:11 I think Repl should still be in clojure.lang 18:11 sohail: 's not! 18:11 Lau_of_DK: For an immutable language, the namespace-stuff sure mutates alot 18:12 sohail: haha 18:12 Chousuke: heh 18:12 better mutate now than be stuck with a suboptimal solution forever 18:13 duck1123: that's okay, yesterday I did a pull of one of the emacs libs I use. The maintainer switched hosters, and basically told everyone by deleting all the files with the commit message "it's gone" 18:13 Lau_of_DK: haha 18:14 Chousuke: well that'd at least encourage people to investigate what has happened. 18:14 though the commit message could've been better... 18:14 duck1123: and Lau_of_DK, that's one of the benefits of git. even had I not found where it went, I would've still been able to back it up a revision 18:15 Lau_of_DK: Same with SVN though, right duck1123 ? 18:15 duck1123: what if he shut down the server between the time I pulled and realived what happened 18:16 rare risk, but still... 18:17 Lau_of_DK: Sure, and if you combine that with a sudden Earth/Moon collision, hitting directly on top of your broad band connection, you might also experience great packet-loss, but as you said.. rare risk 18:18 duck1123: I don't need the moon to hit the earth, I have DSL 18:18 Chousuke: well with GIT you could rehost the old repository easily. 18:18 with SVN all the history would be gone, 18:18 Lau_of_DK: oh I see 18:19 Chousuke: the big thing with git is that any clone of a repository is equal with its origin 18:20 Lau_of_DK: same with SVN though, right? 18:20 Chousuke: no 18:20 with SVN, your checkout is still dependent on the repository you checked out 18:21 you can't for example have other people check out your version of the repo 18:21 which, with git, is trivial :) 18:21 Lau_of_DK: I cant have them checkout my version? What can they checkout then ? 18:22 Chousuke: the repository. 18:22 Lau_of_DK: oh I see, so you mean that Git checksout all the versions when you co ? 18:22 Chousuke: well, kind of. 18:22 it *clones* the entire repository 18:23 so if you have repository A and clone it as A', then as long as no modifications are made on either repo, they contain the same data 18:24 including history 18:24 Lau_of_DK: k, but thats still the same as SVN though, just excl. history 18:25 arohner: Lau_of_DK: no. In SVN, there is a master/slave relationship. When you check out, you get a copy of the current revision. Doing anything requires talking to the repo that you checked out from. 18:25 Chousuke: but with git, you could make modifications and someone could clone your A'. 18:25 duck1123: with svn, if you can't reach the repository (due to lunar disaster) you can't make any commits 18:26 Chousuke: without even knowing that A existed 18:26 Lau_of_DK: oh I see, so theres more a bittorrent approach to Git 18:26 Theres no central hosting for Git is there, people use their own servers primarily ? 18:26 Chousuke: there's no "master" in git, other than by policy. 18:27 kotarak: Lau_of_DK: there's github 18:27 duck1123: so my github repository is just a copy of what I have here at home 18:27 Chousuke: you can decide that there's a "central" server, but technically it's just another git repo 18:28 Fanda: hello! 18:28 kotarak: Which basically applies to all newer systems: hg, bzr, darcs... 18:28 arohner: Fanda: hi 18:28 Fanda: just wanted to ask, what sources have you used for learning how to write macros 18:28 i like clojure very much, but macros give me hard time 18:28 arohner: Fanda: some people have recommended On Lisp 18:29 sohail: hey Lau_of_DK, in your qt api thingy, how are you handling designer stuff? 18:29 duck1123: and mr rules them all 18:29 Fanda: i am looking into: Practical Common Lisp 18:29 Lau_of_DK: Fanda, theres actually a section on the Clojure Wiki about that now 18:29 arohner: Fanda: that's another good option 18:29 Fanda: reading the clojure source is also good 18:29 Lau_of_DK: sohail, 2 ways: 1) For everything except Webkit, use 'designer' and import the UI, 2) Webkit: Hardcode 18:29 Anyway, thanks to everybody for your explanations on Git vs Svn 18:30 Fanda: yes, I will read all: On Lisp, PCL and wiki :-) 18:30 sohail: Lau_of_DK, so you mean you have an extra juic step? 18:30 arohner: Fanda: in the source tree, src/clj/clojure/boot.clj 18:30 Lau_of_DK: You mean when I dance, or when I code ? 18:30 sohail: Lau_of_DK, both 18:31 Lau_of_DK: sohail, haha 18:31 What do you mean by juic step ? 18:32 sohail: Lau_of_DK, because designer has the ui files, do you use juic to generate the actual code or do you use the dynamic equivalent? 18:32 I think it's forms 18:32 I haven't used forms 18:32 Lau_of_DK: oh hang on 18:32 Fanda: arohner & all: thanks for pointers about macros 18:33 Lau_of_DK: sohail, for your education: http://paste.lisp.org/display/69450 18:33 Fanda: it is gonna take me a little time to learn just it... just getting impatient here :-) 18:33 Chousuke: Fanda: if you're going to read PCL, this will help as well: http://blog.thinkrelevance.com/2008/9/16/pcl-clojure 18:33 Fanda: yes, that's true - completely forgot about it :-) 18:34 is there any other way than using macroexpand to see what's happening? 18:34 sohail: Lau_of_DK, perfect, that's what I thought 18:34 right now I'm using code 18:34 which is so ugly it's not even funny 18:34 Lau_of_DK: hehe, its swing-like ugly 18:34 arohner: Fanda: macroexpand is your best option 18:35 I'm not sure if there are other options 18:35 are you an emacs user? because slime makes it very convenient 18:35 Chousuke: Fanda: I think most important is to not get overly excited about macros though. 18:36 Fanda: usually, i just use simple editor and repl 18:36 sohail: Lau_of_DK, well I have never explored this part of the Qt framework before so I will be bugging you :-) 18:36 Fanda: I have worked with macros in the interpreted-only LISP 18:36 Lau_of_DK: sohail, bug away :) 18:36 Fanda: macroexpansion at compile time is new to me 18:37 Lau_of_DK: then you should try compilemacro at expansion time 18:37 ..but thats really advanced 18:38 Chousuke: clojure syntax-quote is a bit different from the common lisp quasiquote too. At least, I think so. I haven't yet grasped all of the macro-fu myself either. 18:38 arohner: they're fairly easy to translate between 18:38 there's a 1-1 correspondance for most things 18:38 Fanda: ok, example 18:38 a=1, b=2, c=3 18:39 Chousuke: the namespace-qualifying thing makes a difference though. 18:39 Fanda: (mac a b c) => ((a 1) (b 2) (c 3)) 18:39 yes, namespaces and other symbol lookups make it hard for me 18:39 arohner: so you want the symbols to be bound to sequential integers starting at 1? 18:40 Fanda: just any symbols 18:40 and any numbers 18:42 (def a 1) (def b 2) (def c 3) 18:42 sohail: what does this syntax mean? (QIODevice$OpenMode. something)

18:42 Chousuke: sohail: inner class

18:42 sohail: I'm not fully up to snuff on my java interop syntax

18:43 Chousuke, what about the trailing dot?

18:43 Chousuke: it's "new"

18:43 that's the same as (new QIODevice$OpenMode something) 18:43 sohail: ah 18:43 * sohail prefers new today 18:51 Fanda: can i have one more question about macros? 18:51 let have: (def a 1) (def b 2) (def c 3) 18:51 (def lst '(a b c)) 18:52 what expression do you write in order to evaluate symbols inside the list 'lst'? 18:52 user=> ~lst 18:52 (a b c) 18:52 user=> (~@lst) 18:52 (a b c) 18:53 user=> (map eval lst) 18:53 (1 2 3) 18:54 danlarkin: Wow, type hints give me a 6x running time decrease 18:54 I didn't expect it to be nearly that much 19:03 verec: rev 1092 throws java.lang.ClassNotFoundException: clojure.core$eval__1 (core.clj:0)

19:03 from

19:03 compiledClass = RT.classForName(name);

19:03 line 3198 in Compiler.getCompiledClass

19:03 ???

19:04 danlarkin: verec: revert to r1088 for a while

19:05 verec: Ah. OK. Thx

19:06 arohner: do type hints work in the middle of function calls?

19:06 i.e. (foo #^java.lang.String bar)?

19:08 and, on a javadoc, what does "..." mean in the type signature?

19:08 danlarkin: arohner: I don't think it works that way, only in function arg lists that I know of

19:09 arohner: huh. Didn't know java supported that

19:27 oh, that was fun.

19:27 in this instance (I'm not sure about all), ... meant "array of"

19:27 and if you want an array of strings, (into-array string) is not what you want

19:27 you want (into-array [string])

19:28 otherwise you get an array of chars

20:17 AWizzArd: Is there a string-reverse? (str-reverse "123") ==> "321"

20:19 rhickey_: AWizzArd: (str (reverse "123")) ?

20:19 AWizzArd: I know how to do this without a str-reverse, I'm just curious if there is something like that.

20:19 rhickey_: no dedicated function

20:20 AWizzArd: (str (reverse "123")) ==> "(\\3 \\2 \\1)" for me

20:20 (reverse "123") ==> (\3 \2 \1)

20:20 Chouser: (apply str (reverse "123"))

20:21 AWizzArd: Chouser: yes, I am doing this so far

20:21 Chouser: you could lobby Stuart Sierra to add it to clojure.contrib.str-utils

20:21 AWizzArd: ok

20:24 How would you name it if you had to chose a name for it?

20:24 rhickey_: ick

20:25 AWizzArd: What does it stand for?

20:25 rhickey_: do we need such specialized fns?

20:25 AWizzArd: not necessarily

20:25 depending on how regular people reverse strings

20:26 but one could argue if people would expect (reverse "123") to return "321" or (\3 \2 \1)

20:27 Chouser: reverse returns a seq.

20:27 (reverse [1 2 3]) doesn't return a vector, so why should (revers "123") return a string?

20:27 AWizzArd: right

20:27 although it's probably what most people would think about it first

20:28 if reverse were a multimethod one could dispatch for the argument type

20:29 whatever, (apply str (reverse my-string)) is fair enough

20:43 scgilardi: rhickey_: I'd be happy to update the former contents of boot.clj to the lispy Java interop syntax if that would be helpful and isn't already being tackled.

20:45 rhickey_: scgilardi: at some point that would be great - but right now I've got it my hands deep in - just booted Clojure with no source - all from classfiles!!

20:45 hands deep in it

20:45 scgilardi: rhickey: ok, cool. Nice! another milestone passed.

20:46 rhickey_: boots like lightning

20:47 scgilardi: you might want to think about how lib will work when we have pre-compiled libs, some sort of try the class first, then the source

20:51 scgilardi: yes, ok. maybe a new flag to force a compile or recompile as well. I haven't looked at the newest yet, is there a new routine to load a class file compiled from Clojure?

20:58 scgilardi: rhickey_: is that a limitation to preserve programmer sanity or something more fundamental to how things work?

20:59 scgilardi: ok I understand

21:14 sohail: runonce

21:14 is it even possible with STM?

21:14 I think it isn't

21:14 so maybe Stuart shouldn't be using refs and friends for runonce

21:20 rhickey_: woo hoo!! AOT rocks!

21:20 AWizzArd: grats

21:21 rhickey_: clojure.jar with no source inside

21:21 Chouser: nice

21:21 scgilardi: and we were here when...

21:21 don't be goin' closed source on us.

21:22 rhickey_: source on the side

21:22 scgilardi: special source

21:22 rhickey_: sadly, clojure.jar crosses 1mb mark

21:23 would still fit on floppy if they existed

21:23 AWizzArd: perhaps one day there could be deployment tools, like those for CL that can strip out parts that will not be used in the app itself

21:24 Chouser: my clojure.jar is half that

21:24 rhickey_: Chouser: right, precompiling doubles it

21:24 Chouser: even without the source, huh?

21:24 rhickey_: I haven;t worked on size at all

21:25 Chouser: sure

21:25 rhickey_: including source only adds 150k

21:25 AWizzArd: but it seems to reduce loading times a little :-)

21:25 Chouser: hm. .jar's can be zipped, can't they?

21:25 anyway, shouldn't matter much.

21:26 rhickey_: reduces load times a lot - hard to measure, but it may be 5-10x reduction over Java baseline

21:26 gotta run

21:26 AWizzArd: Chouser: .jar's already are zipped

21:27 Chouser: AWizzArd: ah

21:28 scgilardi: I know the latest svn is marked interim, do not use, but I gather it's possible to use. For me, it fails with ExceptionInInitializer in Repl.java. What's the trick?

21:29 AWizzArd: n8 n8

21:38 scgilardi: sohail: could it perhaps be done with a counter instead of a boolean? Would it be possible for one of the parallel invocations to know that he was the one that accomplished the transition from 0 to 1 on a runcount and proceed with the run?

21:40 sohail: scgilardi, or just use a mutex and boolean :-)

21:40 scgilardi: from java.util.concurrent yep.

21:41 sohail: i'm sure java has some more efficient interface to pthread_once

21:42 scgilardi: sounds right. I haven't thought through all the options for updating a ref in a transaction. Everything I've done has worked with commute.

21:42 sohail: scgilardi, I think the counter wouldnt work either

21:43 scgilardi: it seems that if the update were done in a dosync before running the function, a call to ensure could allow one thread to know it was the one that made the 0 to 1 transition.

21:43 sohail: whats dosync anyway

21:44 scgilardi: in fact, that's the same as a false to true transition, so a counter isn't necessary, it's just necssary to know that the ref was false before (this thread) changed it.

21:44 sohail: well if there are no side effects then it doesnt matter really

21:45 scgilardi: dosync wraps Clojure's ref operations

21:45 it seems that runonce would only be useful when there are side effects.

21:45 sohail: yep :-)

21:46 I don't have my head quite wrapped around STM but my understanding is that each transaction occurs within a timeline, so two could occur at the same time in the same timeline

21:47 only one will succeed of course, but the effects are that it ain't runonce!

21:48 scgilardi: If only one thread will run the function and that thread will only run it once, it seems to me that it is exactly runonce.

21:48 sohail: I think it is still possible for two threads to run the function

21:48 you need the stm guy, rich to tell you it ain't so!

21:51 Jedi_Stannis: is there a way to eval in the current scope? I have a gui program that is trying to call eval on the text in a text field, but it can't find the function I have defined. the same function works fine from the repl

21:56 Chouser: (binding [*ns* (find-ns 'user)] (eval ...))

21:57 oh, maybe not

21:59 yeah, I think that's it.

21:59 Jedi_Stannis: chouser: nope, that worked

21:59 thanks

22:30 julian_morrison_: hi, folks

22:30 Chouser: hi

22:31 julian_morrison_: does anyone know how to use (with-open x y ...) in a macro? defmacro qualifies the x and then complains about letting a qualified symbol

22:32 duck1123: ~x

22:32 I've been fighting that all weekend

22:32 julian_morrison_: and to access it from inside after expansion?

22:33 supposing it's JDBC and the x will end up being the conn

22:33 duck1123: you use x at first, ~x later

22:33 julian_morrison_: can you paste an example?

22:38 duck1123: one sec

22:38 julian_morrison_: I'm trying to (defmacro connected ([& body] `(with-open conn (DriverManager/getConnection ...) ~@body))) and then (connected (.createStatement conn))

22:39 do I need to use vars and bindings?

22:39 look at with-model

22:40 julian_morrison_: Ah. Thanks, that's about perfect.

22:41 duck1123: looks like we were doing very similar things.

22:41 you were probably thinking about bindings due to clojure.contrib.sql

23:13 danlarkin: wow, 2x running time difference between passing around a hash-map of args versus each function having n number of arguments

23:14 duck1123: wow

23:14 how many args?

23:15 danlarkin: 4

23:16 duck1123: is there a fn that'll take a seq and filter out the dups?

23:16 danlarkin: I think it's all the object creation the JVM has to do, it isn't very fast at that type of thing I think

23:16 duck1123: nvm, found it

23:23 danlarkin: is there a better way to express this: (if (nil? (first coll)) 'foo (first coll))?

23:25 Chouser: (if-let x (first coll) x 'foo)

23:26 soon to be (if-let [x (first coll)] x 'foo)

23:26 ...assuming it's ok to treat "false" like "nil"

23:27 danlarkin: in this case it is indeed

Logging service provided by n01se.net


text:
# d-Dimensional Classical Heisenberg Model with Arbitrarily-Ranged Interactions: Lyapunov Exponents and Distributions of Momenta and Energies

## Details

[Not all characters may be displayed correctly. To be sure please proceed with the journal link.]

We numerically study the first-principle dynamics and thermostatistics of a d-dimensional classical inertial Heisenberg ferromagnetic model ( d=1,2,3 ) with interactions decaying with the distance rij as 1/rαij ( α≥0 ), where the limit α=0 ( α→∞ ) corresponds to infinite-range (nearest-neighbour) interactions, and the ratio α/d>1 ( 0≤α/d≤1 ) characterizes the short-ranged (long-ranged) regime. By means of first-principle molecular dynamics we study: (i) The scaling with the system size N of the maximum Lyapunov exponent λ in the form λ∼N−κ , where κ(α/d) depends only on the ratio α/d ; (ii) The time-averaged single-particle angular momenta probability distributions for a typical case in the long-range regime 0≤α/d≤1 (which turns out to be well fitted by q-Gaussians), and (iii) The time-averaged single-particle energies probability distributions for a typical case in the long-range regime 0≤α/d≤1 (which turns out to be well fitted by q-exponentials).

Through the Lyapunov exponents we observe an intriguing, and possibly size-dependent, persistence of the non-Boltzmannian behavior even in the α/d>1 regime. The universality that we observe for the probability distributions with regard to the ratio α/d makes this model similar to the α -XY and α -Fermi-Pasta-Ulam Hamiltonian models as well as to asymptotically scale-invariant growing networks.

A. Rodríguez, F. Nobre, C. Tsallis, d-Dimensional Classical Heisenberg Model with Arbitrarily-Ranged Interactions: Lyapunov Exponents and Distributions of Momenta and Energies, Entropy Vol. 21(1) 31 (2019)

format: plain


text:
# When is it ok to remove the intercept in a linear regression model?

I am running linear regression models and wondering what the conditions are for removing the intercept term.

In comparing results from two different regressions where one has the intercept and the other does not, I notice that the $R^2$ of the function without the intercept is much higher. Are there certain conditions or assumptions I should be following to make sure the removal of the intercept term is valid?

• What would the intercept mean in your model? From the information in your question, it seems it would be the expected value of your response when sqft=0 and lotsize=0 and baths=0. Is that ever going to occur in reality? Feb 27, 2012 at 2:59
• the intercept has no meaning. so when writing up a formula for the expected value of a house, can I leave this out? Feb 27, 2012 at 3:02
• Instead of the y= a + b1 x1 + b2 x2 + b3x3, can I omit a? Feb 27, 2012 at 3:03
• NB: Some of these comments and replies address essentially the same question (framed in the context of a housing price regression) which was merged with this one as a duplicate.
– whuber
Feb 27, 2012 at 4:51
• A side point: $R^2$ does not have such good properties when you don't include an intercept in your model, so it's not the best statistic to use for your comparison. Feb 27, 2012 at 7:43

The shortest answer: never, unless you are sure that your linear approximation of the data generating process (linear regression model) either by some theoretical or any other reasons is forced to go through the origin. If not the other regression parameters will be biased even if intercept is statistically insignificant (strange but it is so, consult Brooks Introductory Econometrics for instance). Finally, as I do often explain to my students, by leaving the intercept term you insure that the residual term is zero-mean.

For your two models case we need more context. It may happen that linear model is not suitable here. For example, you need to log transform first if the model is multiplicative. Having exponentially growing processes it may occasionally happen that $R^2$ for the model without the intercept is "much" higher.

Screen the data, test the model with RESET test or any other linear specification test, this may help to see if my guess is true. And, building the models highest $R^2$ is one of the last statistical properties I do really concern about, but it is nice to present to the people who are not so well familiar with econometrics (there are many dirty tricks to make determination close to 1 :)).

• -1 for "never", see example 1 of Joshuas' answer Dec 2, 2013 at 20:43
• @Curious, "never" is written with "unless" examples below just show the exceptions when it is legal to remove intercept. When you don't know the data generating process or theory, or are not forced to go through the origin by standardization or any other special model, keep it. Keeping intercept is like using the trash bin to collect all the distortions caused by linear approximation and other simplifications. P.S. practically the response shows that you read just shortest :) Thanks a lot to Joshua (+1) for the extended examples. May 6, 2014 at 9:56
• You missed the point of Joshua Example 1 and seem to still ignore it completely. In models with categorical covariate the removal of the intercept results in the same model with just different parametrization. This is a legitimate case when intercept can be removed. May 26, 2014 at 15:04
• @Curious, in Joshua example 1, you need to add a new dummy variable for the level of the categorical variable you previously considered as baseline, and this new dummy variable will take the value of the intercept, so you are NOT removing the intercept, just renaming it and reparameterizing the rest of the parameters of the categorical covariate. Therefore the argument of Dmitrij holds.
– Rufo
Apr 15, 2019 at 15:17

Removing the intercept is a different model, but there are plenty of examples where it is legitimate. Answers so far have already discussed in detail the example where the true intercept is 0. I will focus on a few examples where we may be interested in an atypical model parametrization.

Example 1: The ANOVA-style Model. For categorical variables, we typically create binary vectors encoding group membership. The standard regression model is parametrized as intercept + k - 1 dummy vectors. The intercept codes the expected value for the "reference" group, or the omitted vector, and the remaining vectors test the difference between each group and the reference. But in some cases, it may be useful to have each groups' expected value.

dat <- mtcars
dat$$vs <- factor(dat$$vs)

## intercept model: vs coefficient becomes difference
lm(mpg ~ vs + hp, data = dat)

Coefficients:
(Intercept)          vs1           hp
26.96300      2.57622     -0.05453

## no intercept: two vs coefficients,
## conditional expectations for both groups
lm(mpg ~ 0 + vs + hp, data = dat)

Coefficients:
vs0       vs1        hp
26.96300  29.53922  -0.05453

Example 2: The case of standardized data. In some cases, one may be working with standardized data. In this case, the intercept is 0 by design. I think a classic example of this was old style structural equation models or factor, which operated just on the covariance matrices of data. In the case below, it is probably a good idea to estimate the intercept anyway, if only to drop the additional degree of freedom (which you really should have lost anyway because the mean was estimated), but there are a handful of situations where by construction, means may be 0 (e.g., certain experiments where participants assign ratings, but are constrained to give out equal positives and negatives).

dat <- as.data.frame(scale(mtcars))

## intercept is 0 by design
lm(mpg ~ hp + wt, data = dat)

Coefficients:
(Intercept)           hp           wt
3.813e-17   -3.615e-01   -6.296e-01

## leaving the intercept out
lm(mpg ~ 0 + hp + wt, data = dat)

Coefficients:
hp       wt
-0.3615  -0.6296

Example 3: Multivariate Models and Hidden Intercepts. This example is similar to the first in many ways. In this case, the data has been stacked so that two different variables are now in one long vector. A second variable encodes information about whether the response vector, y, belongs to mpg or disp. In this case, to get the separate intercepts for each outcome, you suppress the overall intercept and include both dummy vectors for measure. This is a sort of multivariate analysis. It is not typically done using lm() because you have repeated measures and should probably allow for the nonindepence. However, there are some interesting cases where this is necessary. For example when trying to do a mediation analysis with random effects, to get the full variance covariance matrix, you need both models estimated simultaneously, which can be done by stacking the data and some clever use of dummy vectors.

## stack data for multivariate analysis
dat <- reshape(mtcars, varying = c(1, 3), v.names = "y",
timevar = "measure", times = c("mpg", "disp"),
direction = "long")
dat$$measure <- factor(dat$$measure)

## two regressions with intercepts only
lm(cbind(mpg, disp) ~ 1, data = mtcars)

Coefficients:
mpg     disp
(Intercept)   20.09  230.72

## using the stacked data, measure is difference
## between outcome means
lm(y ~ measure, data = dat)

Coefficients:
(Intercept)   measurempg
230.7       -210.6

## separate 'intercept' for each outcome
lm(y ~ 0 + measure, data = dat)

Coefficients:
measuredisp   measurempg
230.72        20.09

I am not arguing that intercepts should generally be removed, but it is good to be flexible.

• +1. I didn't take people to be rigidly saying 'never', but it's always nice to have another perspective & this is a very clear & thoughtful response. Welcome to CV, it'll be great to have you as part of the community. Jul 18, 2012 at 14:20
• @Joshua: Sorry that I am asking a question on a almost 2 year old post, but are there any references on your first example? I am thinking of running a no-intercept model on my data where the predictor variable is categorical, and I am interested in knowing whether each level is significantly different from 0. Thanks!
– Alex
May 2, 2014 at 19:40
• @Alex Any good regression text ought to do (chapter 8 of Applied Multiple Regression/Correlation Analysis for the Behavioral Sciences 3rd ed. covers this some)--- you just need it to talk about contrasts and how to dummy code categorical variables. One way to think about it is that you are estimating separate intercepts for each group, rather than leaving the intercept out. May 10, 2014 at 22:39
• @Joshua , your first example has caused some confusion elsewhere on this site. My understanding here is that you are suggesting a handy trick to show parameter estimates without needing to mess with adding the value for the intercept, and that you are not suggesting that the usual course is to use a model with the intercept removed to conduct anova. In R, in just about every case, one would use a model with an intercept to conduct a traditional anova. Oct 2, 2018 at 19:04
• @SalMangiafico Yes, that's correct. I'm not advocating removing the intercept as a standard model approach. Aug 19, 2020 at 7:35

There are good answers here. Two small things:

1. Regarding a higher $R^2$ when the intercept is dropped, you should read this excellent answer by @cardinal. (In short, statistical software sometimes uses a different definition for $R^2$ when the intercept is forced to 0. So the reported $R^2$ for models with and without an intercept might simply not be comparable.)
2. Several people make the point that you should be certain the intercept must be 0 (for theoretical reasons) before dropping it, and not just that it isn't 'significant'. I think that's right, but it's not the whole story. You also need to know that the true data generating function is perfectly linear throughout the range of $X$ that you are working with and all the way down to 0. Remember that it is always possible that the function is approximately linear within your data, but actually slightly curving. It may be quite reasonable to treat the function as though it were linear within the range of your observations, even if it isn't perfectly so, but if it isn't and you drop the intercept you will end up with a worse approximation to the underlying function even if the true intercept is 0.
• @AdamO makes a similar point to #2 here: positive linear regression coefficient, but develops the idea much more fully. Mar 12, 2014 at 18:20
• "if it isn't and you drop the intercept you will end up with a worse approximation to the underlying function even if the true intercept is 0" Wouldn't this be the case for many other terms as well? For example, the function $y=x^3+x+1$ has no quadratic term, but the model family $y=mx+b$ will fit worse than one without a quadratic term. This just seems to be a symptom of underfitting generally, and not a unique property of the intercept term.
– Him
Apr 27, 2020 at 17:27
• @Scott, when you have a cubic term, the $x^2$ is a kind of intercept (see here: Does it make sense to add a quadratic term but not the linear term to a model?). Apr 28, 2020 at 4:29
• "even if it isn't perfectly so, but if it isn't and you drop the intercept you will end up with a worse approximation to the underlying function even if the true intercept is 0." If dropping the intercept would result in a lot worse estimate/prediction then the intercept term will often not be insignificant. When the intercept term is insignificant then this means that the noise is probably larger than the value of the intercept term. The estimate of the intercept might fit the noise rather than the true underlying intercept and this can increase the expected squared error. Sep 14 at 8:45
• @SextusEmpiricus statistical significance isn't the same as predictive accuracy. It's a fallacy to assume that whatever is significant will enhance your out of sample predictive accuracy & that whatever is nonsignificant will lead to overfitting & detract from predictive accuracy. Sep 14 at 11:26

You shouldn't drop the intercept, regardless of whether you are likely or not to ever see all the explanatory variables having values of zero.

If you remove the intercept then the other estimates all become biased. Even if the true value of the intercept is approximately zero (which is all you can conclude from your data), you are messing around with the slopes if you force it to be exactly zero.

UNLESS - you are measuring something with a very clear and obvious physical model that demands intercept be zero (eg you have height, width and length of a rectangular prism as explanatory variables and the response variable is volume with some measurement error). If your response variable is value of the house, you definitely need to leave the intercept in.

• Can you please explain, why we need the intercept for house price prediction? why would all the X be zero for any house?
– Elf
Apr 2, 2019 at 6:27
• A bit late here, but I'm guessing because it's unlikely the value of a house would ever be 0, regardless of it's characteristics. Feb 4 at 13:40
• Land alone is worth something, so even a dimensionless house is valuable. Aug 31 at 18:55
• "If you remove the intercept then the other estimates all become biased" This is not specific for the intercept. The same is true for other regressor terms. If we leave out other regressor terms that are approximately zero then we also introduce bias. It also doesn't matter so much because bias is not the main parameter that we care about. Often we find it more important to reduce the expectation of the square of the error or the expectation of some other non-linear cost function. Sep 14 at 8:39

OK, so you've changed the question a LOT

You can leave out the intercept when you know it's 0. That's it. And no, you can't do it because it's not significantly different from 0, you have to know it's 0 or your residuals are biased. And, in that case it is 0 so it won't make any difference if you leave it out... therefore, never leave it out.

The finding you have with $R^2$ suggests the data are not linear. And, given that you had area as a predictor that particular one is probably definitely not linear. You could transform the predictor to fix that.

• What about when we wish to test for cointegration using Engle/Granger 2-step? en.wikipedia.org/wiki/Cointegration
– Jase
Dec 15, 2012 at 11:42
• "you have to know it's 0 or your residuals are biased" many people miss this crucial point and say that the beta will be biased, but that's wrong because the betas are not in any way dependent on the intercept. Mar 3 at 7:34
• @baibo the betas/coefficients might become biased when the regressors correlate with the (removed) intercept term. When you fit a model $y = bx$ while the true model is $y=a+bx$ then the estimate of $b$ will become biased. An obvious example is in the image here: stats.stackexchange.com/a/325395/164061 Sep 14 at 8:31
• "you have to know it's 0 or your residuals are biased" What is the problem with this? Do we care about this bias when the goal is to make a best prediction, for instance based on reducing the expectation of the squared error? Sep 14 at 8:34

Most multiple regression models include a constant term (i.e., the intercept), since this ensures that the model will be unbiased--i.e., the mean of the residuals will be exactly zero. (The coefficients in a regression model are estimated by least squares--i.e., minimizing the mean squared error. Now, the mean squared error is equal to the variance of the errors plus the square of their mean: this is a mathematical identity. Changing the value of the constant in the model changes the mean of the errors but doesn't affect the variance. Hence, if the sum of squared errors is to be minimized, the constant must be chosen such that the mean of the errors is zero.)

In a simple regression model, the constant represents the Y-intercept of the regression line, in unstandardized form. In a multiple regression model, the constant represents the value that would be predicted for the dependent variable if all the independent variables were simultaneously equal to zero--a situation which may not physically or economically meaningful. If you are not particularly interested in what would happen if all the independent variables were simultaneously zero, then you normally leave the constant in the model regardless of its statistical significance. In addition to ensuring that the in-sample errors are unbiased, the presence of the constant allows the regression line to "seek its own level" and provide the best fit to data which may only be locally linear.

However, in rare cases you may wish to exclude the constant from the model. This is a model-fitting option in the regression procedure in any software package, and it is sometimes referred to as regression through the origin, or RTO for short. Usually, this will be done only if:

1. it is possible to imagine the independent variables all assuming the value zero simultaneously, and you feel that in this case it should logically follow that the dependent variable will also be equal to zero; or else
2. the constant is redundant with the set of independent variables you wish to use.

An example of case (1) would be a model in which all variables--dependent and independent--represented first differences of other time series. If you are regressing the first difference of Y on the first difference of X, you are directly predicting changes in Y as a linear function of changes in X, without reference to the current levels of the variables. In this case it might be reasonable (although not required) to assume that Y should be unchanged, on the average, whenever X is unchanged--i.e., that Y should not have an upward or downward trend in the absence of any change in the level of X.

An example of case (2) would be a situation in which you wish to use a full set of seasonal indicator variables--e.g., you are using quarterly data, and you wish to include variables Q1, Q2, Q3, and Q4 representing additive seasonal effects. Thus, Q1 might look like 1 0 0 0 1 0 0 0 ..., Q2 would look like 0 1 0 0 0 1 0 0 ..., and so on. You could not use all four of these and a constant in the same model, since Q1+Q2+Q3+Q4 = 1 1 1 1 1 1 1 1 . . . . , which is the same as a constant term. I.e., the five variables Q1, Q2, Q3, Q4, and CONSTANT are not linearly independent: any one of them can be expressed as a linear combination of the other four. A technical prerequisite for fitting a linear regression model is that the independent variables must be linearly independent; otherwise the least-squares coefficients cannot be determined uniquely, and we say the regression "fails."

A word of warning: R-squared and the F statistic do not have the same meaning in an RTO model as they do in an ordinary regression model, and they are not calculated in the same way by all software. See this article for some caveats. You should not try to compare R-squared between models that do and do not include a constant term, although it is OK to compare the standard error of the regression.

Note that the term "independent" is used in (at least) three different ways in regression jargon: any single variable may be called an independent variable if it is being used as a predictor, rather than as the predictee. A group of variables is linearly independent if no one of them can be expressed exactly as a linear combination of the others. A pair of variables is said to be statistically independent if they are not only linearly independent but also utterly uninformative with respect to each other. In a regression model, you want your dependent variable to be statistically dependent on the independent variables, which must be linearly (but not necessarily statistically) independent among themselves.

• What article are you referring to? Dec 10, 2014 at 16:31

Short answer: (almost) NEVER. In the linear regression model $$y = \alpha + \beta x + \epsilon$$, if you set $$\alpha=0$$, then you say that you KNOW that the expected value of $$y$$ given $$x=0$$ is zero. You almost never know that.

$$R^2$$ becomes higher without intercept, not because the model is better, but because the definition of $$R^2$$ used is another one! $$R^2$$ is an expression of a comparison of the estimated model with some standard model, expressed as reduction in sum of squares compared to sum of squares with the standard model. In the model with intercept, the comparison sum of squares is around the mean. Without intercept, it is around zero! The last one is usually much higher, so it easier to get a large reduction in sum of squares.

Conclusion: DO NOT LEAVE THE INTERCEPT OUT OF THE MODEL (unless you really, really know what you are doing).

Some exceptions: One exception is a regression representing a one-way ANOVA with dummies for ALL the factor levels (usually one is left out) (but that is only seemingly an exception, the constant vector 1 is in the column space of the model matrix $$X$$.) Otherwise, such as physical relationships $$s=v t$$ where there are no constant. But even then, if the model is only approximate (speed is not really constant), it might be better to leave in a constant even if it cannot be interpreted.

There are also special models which leave out the intercept. One example is paired data, twin studies.

Full revision of my thoughts. Indeed dropping the intercept will cause a bias problem.

Have you considered centering your data so an intercept would have some meaning and avoid explaining how some (unreasonable) values could give negative values? If you adjust all three explanatory variables by subtract the mean sqrft, mean lotsize and mean bath, then the intercept will now indicate the value (of a house?) with average sdrft, lotsize, and baths.

This centering will not change the relative relationship of the independent variables. So, fitting the model on the centered data will still find baths as insignificant. Refit the model without the bath included. You may still get a large p-value for the intercept, but it should be included and you will have a model of the form y=a+b(sqrft)+c(lotsize).

I just spent some time answering a similar question posted by someone else, but it was closed. There are some great answers here, but the answer I provide is a bit simpler. It might be more suited to people who have a weak understanding of regression.

### Q1: How do I interpret the intercept in my model?

In regression models, the goal is to minimise the amount of unexplained variance in an outcome variable:

y = b0 + b1⋅x + ϵ

where y is the predicted value of your outcome measure (e.g., log_blood_hg), b0 is the intercept, b1 is the slope, x is a predictor variable, and ϵ is residual error.

The intercept (b0) is the predicted mean value of y when all x = 0. In other words, it's the baseline value of y, before you've used any variables (e.g., species) to further minimise or explain the variance in log_blood_hg.

By adding a slope (which estimates how a one-unit increase/decrease in log_blood_hg changes with a one unit increase in x, e.g., species), we add to what we already know about the outcome variable, which is its baseline value (i.e. intercept), based on change in another variable.

### Q2: When is it appropriate to include or not include the intercept, especially in regards to the fact that the models give very different results?

For simple models like this, it's never really appropriate to drop the intercept.

The models give different results when you drop the intercept because rather than grounding the slope in the baseline value of Y, it is forced to go through the origin of y, which is 0. Therefore, the slope gets steeper (i.e. more powerful and significant) because you've forced the line through the origin, not because it does a better job of minimizing the variance in y. In other words, you've artificially created a model which minimizes the variance in y by removing the intercept, or the initial grounding point for your model.

There are cases where removing the intercept is appropriate - such as when describing a phenomenon with a 0-intercept. You can read about that here, as well as more reasons why removing an intercept isn't a good idea.

This question has already many answers and basically they relate to the two cases (the first and second point below). But the answers make not clear why it is the case. While pondering about this and thinking about why the intercept would be different from other regressors (why should we never exclude the intercept term but is this not the case for other regressors?), I came to the idea that the intercept is not different. The intercept does have a special role like computations of the $$R^2$$ value and making the mean of residuals zero, but that does not make it that you can not remove it like you can with other regressor terms.

It can be ok to remove the intercept when ...

1. When you have categorical variables. In that case the intercept is already in the column space of the regressors.

2. When you theoretically know that it should be zero.

Example: fitting an exponential decay for which the function is $$y(t) = y_0 e^{-ct}$$.

In some way you could see the $$y_0$$ as an intercept, because it behaves like an intercept when you plot the logarithm of $$y$$. But this function is different from $$y(t) = y_0 e^{-ct} + b$$ where this $$b$$ might be some baseline. Even when it is possible, due to measurement error, that the intercept/baseline $$b$$ is not zero, then one might whish to not include it (see next point).

3. Not only when the intercept is theoretically exactly zero but also when the intercept is small.

The variance in the estimate of the intercept might introduce an increased variance in the estimates or predictions. A model without the intercept could have better performance.

In this way the intercept is like any other regressor variable that we might choose to eliminate based on some bad performance in a cross validation. If you do model selection and believe that regressor variables can be eliminated, the the same must be true for the intercept term.

Because I am too lazy to prove this rigourously, I made an example in R code that demonstrates this

set.seed(1)

### this function makes a linear fit
### either with or without intercept
### and it returns the squared error of the estimates
sim = function(intercept = TRUE){

### the data
x = -10:10
u = 0.1+x
y = u+rnorm(length(x))

### fitting
if (intercept == TRUE) {
mod = lm(y ~ 1+x)
} else {
mod = lm(y ~ 0+x)
}

### return the error in the estimates
sum((predict(mod)-u)^2)
}

### perform simulations
r1 = replicate(10^4,sim(TRUE))
r0 = replicate(10^4,sim(FALSE))

### with intercept 1.981789
mean(r1)
### without intercept 1.206731
mean(r0)

Sidenote: Not including the intercept (or any other parameter), just to reduce the variance is a bit rigorous. Alternatives to not including the intercept could be some regularisation.

The reason why we say that we should never exclude the intercept is, I guess, not because there is some theoretical reason that should give the intercept some advantage that other regressor terms do not have. But instead, it is because in practice the intercept is non zero and large enough to be important for the estimates.