#clojure log - Dec 24 2010

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

0:17 rata_: how do you guys do to detect unwanted references to old data?

1:02 anthony_: How would I reference String[].class in clojure? String[]/class doesn't work.

1:06 Sorry, nevermind. I got it working.

2:01 sivajag: hi all

2:01 does anyone knows how i can find list of functions in a namespace?

2:15 Raynes: sivajag: (ns-interns (the-ns 'clojure.core)) will get you a list of all vars in clojure.core. That includes vars that aren't bound to functions though.

2:29 sivajag: Raynes: thanks

2:29 i can filter out functions

3:01 bendlas: Hey folks

3:02 I had a question about protocols

3:02 they are supposed to solve the expression problem in a save way

3:03 by allowing independent extensions

3:04 but when you extend a protocol two times for the same type, the later extension overwrites the former one

3:05 so in effect they do allow monkey patching, only enforcing a proper dispatch to super()

3:06 or am I missing something?

3:11 wouldn't it have been better to make protocol extensions namespace local and importable?

3:12 like scala does with auto coercions (IIRC)

5:09 Gigaroby: lazy sequences do only work with infinite sequences ?

5:10 or I can use it to postpone the evaluation of a finite sequence ?

5:31 ejackson: Gigaroby: the latter.

5:31 Gigaroby: ejackson, can you give me an example ? all the examples I found was with infinite sequences

5:31 Leonidas: hi, I'm trying to run my application with leiningen, but I fail, since the application needs command line arguments http://paste.pocoo.org/show/309267/

5:32 ejackson: ,(def a (map inc [1 2 3]))

5:32 clojurebot: DENIED

5:32 ejackson: ok, it won't let me do a def, but you get the idea

5:32 map turns [1 2 3] into a seq

5:32 and evaluates lazily

5:32 Leonidas: but when I say "lein run filename" I get this exception: http://paste.pocoo.org/show/309268/

5:36 what am I doing wrong? it seems lein run does something undesirable to the command line arguments...

5:45 anyone has an idea what I'm doing wrong with 'lein run filename' ?

5:48 ejackson: Leonidas: i really dunno, never used lein, and I think the channel is going to be super quiet over the next few days. Perhaps ask again later when the US wakes up ?

5:49 Leonidas: ejackson: yeah, good idea. I think I'll put the question on the clojure mailing list, so people can answer to if when they are awake :)

5:49 ejackson: there you go

6:11 bendlas: Leonidas: try `lein run -m namespace-name`

6:12 `lein help run` says

6:12 USAGE: lein run [ARGS...]

6:12 Calls the -main function in the namespace specified as :main in project.clj.

6:12

6:12 USAGE: lein run -m NAMESPACE [ARGS...]

6:12 Calls the -main function in the specified namespace.

6:12

6:12 zvrba: ah!

6:12 a question: is it possible to save an "image" with clojure as it is with CL or R?

6:14 bendlas: zvrba: not that i know of

6:14 zvrba: :/

6:16 bendlas: clojure can't give you more than java (or CIL) bytecode (for now), as far as executable format is concerned

6:16 zvrba: but image=code+data

6:16 Leonidas: bendlas: I already set :main to the namespace, otherwise it wouldn't run in the first place complaining about :main being unset

6:16 bendlas: and since java doesn't even support precompiled Arrays ...

6:17 zvrba: code is already stored in class files, but the working storage COULD be dumped to disk in some way. i guess.

6:17 bendlas: ah ok

6:17 in that case java takes you far enough

6:17 consider jar's

6:17 zvrba: what about them?

6:18 bendlas: they are code+data

6:18 zvrba: yes

6:18 bendlas: or you want mutable data?

6:18 zvrba: hmmm?

6:18 i just want to save all objects currently in memory, exit the interpreter, restart it and have it reload what was there before

6:18 bendlas: like writing data into the image to persist state?

6:19 right

6:19 zvrba: like.. hm, in CL: (setq *A* 12) .. save image .. exit .. start again .. (+ *A* 15) -> 27

6:19 bendlas: i bet there is some enterprisey java software for that

6:20 zvrba: of course, i'd also like to dump functions i've defined to image

6:20 bendlas: terracotta

6:20 that was it

6:20 zvrba: but then we get to JVM limitations you mentioned, i guess

6:20 bendlas: disregard, terracotta is for IPC

6:21 zvrba: ok, nothing out of the box is available. thanks :-)

6:22 bendlas: yw

6:22 zvrba: why do I ask: i'd like to learn a lisp-like language, and I started with common lisp.

6:22 now i'm looking a bit into clojure.

6:23 i do programming for a living, and I heavily use math

6:23 so i thought i could use LISP as a calculator

6:23 but for this i *really* want my session state saved between interpreter runs (many local vars, helper functions, etc)

6:23 Leonidas: zvrba: common lisp images?

6:23 zvrba: Leonidas: what about it?

6:24 Leonidas: yes, i askes whether there was an equivalent in clojure.

6:24 *asked

6:24 Leonidas: zvrba: they save state between runs. Oh, I see.

6:24 zvrba: but if you need that, why don't you stay with CL?

6:24 bendlas: you can print and read back all basic datastructs without effort

6:25 and you can walk a namespace

6:26 Leonidas: there was a way to freeze processes to disc, at least on linux, maybe you're interested in that?

6:26 bendlas: Leonidas: read; with -m you run an arbitrary file, it doesn't even look at defined :main

6:27 without you give ARGS to defined :main

6:27 Leonidas: bendlas: so I can't just "lein run ARGS" and run :main with the ARGS?

6:28 bendlas: lemme check :)

6:28 Leonidas: bendlas: if you want, I can send you a link to my git repo where I am trying to get it running

6:30 bendlas: sry, i see it now

6:30 lein run -m main args

6:30 works anyway

6:30 Leonidas: bendlas: when I use -m namespace ARGS I get this: http://paste.pocoo.org/show/309274/

6:31 bendlas: \i is probably because by ARGS start with an i letter :/

6:31 bendlas: hmm

6:34 (ns main)

6:34 (defn -main

6:34 ([echo] (println "You said" echo))

6:34 You said xyz

6:34 lein run -m main xyz

6:35 swap last two lines; works for me

6:36 Leonidas: Exception in thread "main" java.io.FileNotFoundException: Could not locate main__init.class or main.clj on classpath: (NO_SOURCE_FILE:1)

6:36 oh, wait a moment...

6:37 bendlas: but the case w/o -m is indeed funky

6:37 Leonidas: bendlas: ok, *that* works for me as well.

6:39 bendlas: https://github.com/Leonidas-from-XIV/karmawhore <- please see here. It seems it does weird things to [& args].

6:42 bendlas: (defn -main

6:42 ([& echo] (println "You said" echo))

6:42

6:42 % lein run -m main xyz abc def

6:42 You said (xyz abc def)

6:42 ffirst

6:43 gets first character of first arg string

6:44 Leonidas: try

6:44 (defn -main [& args]

6:44 (let [file-name (first args) ...

6:45 instead of (ffirst args)

6:47 Leonidas: bendlas: oh, ok, I think I start to understand. So it does not do (-main *command-line-args*) but rather (apply -main *command-line-args*), right?

6:47 bendlas: and since you don't use (rest args) you might just aswell write

6:47 (defn -main [file-name] ...

6:47 yep

6:48 LauJensen: bendlas: Why arent you in #clojureql?

6:48 bendlas: LauJensen: :D

6:48 hi

6:48 too

6:48 Leonidas: LauJensen: what is #clojureql?

6:48 bendlas: yeah, the plan was to do some command line parsing later.

6:48 LauJensen: Leonidas: Its the channel where we discuss development on #clojureql, something which bendlas frequently contributes to

6:49 Leonidas: LauJensen: oh, ok, thanks :) "ql" didn't sound like development for me.

6:49 LauJensen: Leonidas: http://github.com/LauJensen/clojureql

6:50 Leonidas: bendlas: ok, now it runs. Kinda. With -m karmawhore it looks just fine, but without -m, but with a command-line-argument, it tries to load that as a class.

6:51 bendlas: yes, gotta ask technomancy if that's intended

6:53 Leonidas: bendlas: thank you!

6:54 bendlas: you're welcome

6:55 LauJensen: btw, did you have to do anything special to your clojure-mode, so that it doesn't indent with mixed tabs/spaces

6:55 LauJensen: bendlas: I have some special indenting settings, but not related to your problem - I recommend reinstalling from scratch, which is what I did recently

6:57 bendlas: just did that a week ago, now running on clojure-mode 1.7.1 from elpa

6:58 LauJensen: Im on 1.8 I think, straight from github

6:58 1.8.0

6:59 bendlas: will try

7:00 tabs also suck for mixed emacs/eclipse editing

7:24 oh, there is an untabify command in emacs

7:38 hmm lisp-indent-line causes the misbehavior

7:39 LauJensen: could you quickly tell me your

7:39 - M-x version

7:39 - M-: indent-line-function <-- in clojure-mode

7:49 OK, i went with an untabify on save hook as per http://stackoverflow.com/questions/3313210/converting-this-untabify-on-save-hook-for-emacs-to-work-with-espresso-mode-or-al

7:50 for the records

8:48 zvrba: bendlas: hm, that with printing/reading back basic data structures is interesting!

8:49 (sorry, i got on-the-door delivery i had to take care of)

8:54 bendlas: yeah, consider

8:54 ,(read-string (with-out-str (pr {"A nested map of" ['symbols :keywords] 5 '(4/3 3.56) nil #{"and" :a 'set}})))

8:54 clojurebot: {"A nested map of" [symbols :keywords], 5 (4/3 3.56), nil #{:a set "and"}}

8:56 bendlas: ,(ns-interns *ns*)

8:56 clojurebot: {}

8:56 bendlas: lets you walk the current namespace

8:57 looks like clojurebot has no def d vars in

8:57 ,*ns*

8:57 clojurebot: #<Namespace sandbox>

8:59 bendlas: ,(find-ns 'clojure.string)

8:59 clojurebot: nil

9:00 bendlas: ,(take 5 (ns-interns (find-ns 'clojure.core)))

9:00 clojurebot: ([sorted-map #'clojure.core/sorted-map] [read-line #'clojure.core/read-line] [re-pattern #'clojure.core/re-pattern] [keyword? #'clojure.core/keyword?] [asm-type #'clojure.core/asm-type])

9:00 bendlas: haha, spamming the bot while everyone is asleep ;)

9:01 Raynes: &(ns-interns *ns)

9:01 sexpbot: java.lang.SecurityException: You tripped the alarm! ns-interns is bad!

9:01 Raynes: &(ns-interns *ns*)

9:01 sexpbot: java.lang.SecurityException: You tripped the alarm! ns-interns is bad!

9:01 * Raynes hugs sexpbot

9:02 bendlas: :)

9:06 zvrba: bendlas: that was interesting, thanks!

9:07 bendlas: np

10:14 Gigaroby: guys can you have a look at this and tell me if the style is good ? http://pastebin.mozilla.org/898423

10:16 zvrba: diagonal-up-busy? and diagonal-down-busy are almost identical.

10:16 mrBliss: Gigaroby: some small things I would do: (= x 0) => (zero? x), (if (not (nil? x)) ..) => (if x ..), (if test nil x) => (when-not test x)

10:17 zvrba: why not abstract out the only differing part (inc/dec) into parameter and have a single function

10:17 Gigaroby: cause

10:17 there are

10:17 a few differences

10:18 ah

10:18 zvrba: such as?

10:18 Gigaroby: wait

10:18 lol

10:18 no you're righ

10:18 *right

10:18 i'll do it now

10:18 thanks mrBliss, zvrba

10:18 zvrba: are let-bidnings in clojure just sequential var/value pairs, w/o any delimiters?

10:19 mrBliss: zvrba: correct

10:19 Gigaroby: mrBliss, when not will still return null ?

10:19 mrBliss, meant nil

10:19 mrBliss: Gigaroby: (when test x) returns x when test is true, otherwise nil

10:20 zvrba: same thing for Clojure's cond

10:21 Gigaroby: mrBliss, so (if x ..) if x is nill will be logically false ?

10:21 zvrba: mrBliss: oh :(

10:21 mrBliss: Gigaroby: (if test x y) will do x when test is nil or false

10:22 zvrba: less parens

10:22 Gigaroby: mrBliss, thanks, very useful as useful : I love this channel lol

10:22 mrBliss, as usual*

10:22 mrBliss: Gigaroby: that's what I'm here for :-)

10:22 Gigaroby: mrBliss, my mind at 2 am of christmas is not that good lol

10:22 zvrba: mrBliss: less parens = more dependent on indentation / easier to get lost in long chains. like, "wait, am i now at even or odd position"?

10:23 + parens help smart editors to indent code properly

10:23 mrBliss: zvrba: you can delimit them with commas since they are whitespace

10:24 zvrba: but I see your point

10:24 Gigaroby: zvrba, I think that too many parens are difficolt to be human-readable

10:24 clojurebot: ΜΟΛΩΝ ΛΑΒΕ

10:25 zvrba: actually, I like the parens of CL. it's very uniform, and I don't have to think too much.

10:25 anyway.

10:26 Gigaroby: i disagree. it's like saying too many {} make code unreadable, so you end up with python. good luck with copy/pasting pieces of code between different nesting levels.

10:26 Raynes: zvrba: Not many people share your love of parentheses.

10:28 mrBliss: zvrba: Lisp's parentheses make me feel safe. Certainly in combination with Emacs, you just know your indentation is right.

10:28 Gigaroby: zvrba, fair enaugh I use both java and python lol

10:28 zvrba: mrBliss: indeed.

10:32 Raynes: then designing a language that completely eliminated the parentheses would be the "right thing"TM. what Clojure does is just destroying uniformity. just my $.02

10:33 Raynes: Seems a little dramatic, but fair enough. Each to his own.

10:33 dnolen: zvrba: I'm writing a bit of Scheme and CL now. Uniformity is nice, but typing less parens and having structural delimiters is nice as well. let and condp are particularly tedious.

10:33 sorry I mean cond

10:36 Gigaroby: mrBliss, gotta a question about lazy sequences

10:36 mrBliss, the values in the list are not calculated until evaluation right ?

10:36 mrBliss: Gigaroby: sort of

10:37 Gigaroby: mrBliss, cause if you look at my last function should create a lazy sequence

10:37 mrBliss, but when I do it with very big boards (suppose 20)

10:37 mrBliss, take 20 secs to generate one solution

10:38 mrBliss, but it does not take 20 secs to generate the list ...

10:38 mrBliss: I don't quite understand. But I see (lazy-seq) somewhere, which looks a bit odd

10:39 Gigaroby: mrBliss, why looks like odd ?

10:39 mrBliss: &(doc lazy-seq)

10:39 sexpbot: ⟹ "Macro ([& body]); Takes a body of expressions that returns an ISeq or nil, and yields a Seqable object that will invoke the body only the first time seq is called, and will cache the result and return it on all subsequent seq calls."

10:39 mrBliss: You should put the cons in the lazy-seq

10:40 Look at the source of this function for example: http://clojuredocs.org/clojure_core/clojure.core/partition-by

10:40 Gigaroby: mrBliss, it is all enclosed into the lazy-seq

10:42 mrBliss: I'll try to fix your solution-list

10:42 Gigaroby: mrBliss, ty

10:43 &(+ 1 2)

10:43 sexpbot: ⟹ 3

10:52 Raynes: chouser: Can I steal the print-method method for PersistentQueues from TJoC if I explicitly give it credit in a footnote? In my book, that is. :>

10:53 mrBliss: Gigaroby: http://pastebin.mozilla.org/898441 I didn't test it (I don't even know if it compiles correctly), but at least it gives you an idea.

10:54 Gigaroby: mrBliss, thanks a lot I'll have a look

10:57 mrBliss, you think is good to do only pure functions ( except for I/O obviously ) or use mutable state for the queens object ?

10:58 mrBliss: Gigaroby: first try it in a purely functional style, but when performance is really bad, you can go to the 'dark side' of mutability.

10:58 Gigaroby: mrBliss, well I don't need performance, I don't have to work with it xD

11:00 mrBliss: Gigaroby: then you should certainly do everything in a functional style, except for IO (which is obviously impossible ;-)

11:20 Gigaroby: mrBliss, is there any multiline comments ?

11:20 mrBliss: Gigaroby: no

11:20 Gigaroby: mrBliss, enclose all in "" like python will do the trick ?

11:21 mrBliss: Gigaroby: http://groups.google.com/group/clojure/browse_thread/thread/50b5631189d524ca/8f9d9a5bab7a8a2d?lnk=gst&q=multiline#8f9d9a5bab7a8a2d

11:23 Gigaroby: mrBliss, thanks

11:30 sivajag: This is interesting

11:30 It's nothing like #Clojure, which is a #Lisp variant and, therefore, insane." -- lazygosu.org

11:31 Raynes: There is nothing you can do to make the blind men see.

11:31 mrBliss: "For Developers Who Give Up Easily"

11:32 sivajag: :)

11:33 Raynes: I'm inclined to add to my book: "It's nothing like Gosu, which is a statically typed imperative language, and therefore extremely boring and repetitive."

11:33 sivajag: can't believe it is going to be 2011 and we have people argue for "Having an accurate list of methods pop up after I hit '.' makes me roughly infinitely more productive, give or take."

11:33 haha raynes

11:34 mrBliss: I assume the name is pronounced as "Go sue", a reference to Oracle ;-)

11:35 Raynes: I find it difficult to be impressed with any language that feels the need to insult other languages as way to get people to use it. Gosu is doing that at every turn.

11:38 mrBliss: It targets developers that are not interested in learning a new language, so why should they learn Gosu, when they won't need it for their jobs? (last negative remark from me ;-)

12:12 Gigaroby: good night and merry christmas guys

13:44 sandery: I just upgraded to 1.3 and the repl is acting all weird, not resolving names correctly and so forth. anyone knows what's up with that?

13:52 zvrba: isn't 1.3 just alpha?

15:21 timmorgan: In the Slime debugger, the backtrace always reports "no locals" when I toggle a frame (I tried them all)

15:21 I'm using Clojure 1.2.0 -- any ideas?

15:36 dsop: hmm how to compare records with =? (= RECORD1 RECORD2) doesnt seem to work

15:40 timmorgan: dsop: maybe try ==

15:48 no I guess not

15:51 Actually (= r1 r2) seems to work for me

15:53 chouser: should be =

15:53 dsop: timmorgan: turns out that it was an error in a number in the record

15:55 Clinteger: lol

15:55 dsop: = works fine

15:56 Clinteger: well deftest just tells you {:a 2.12 :b "c"} != {:a 2.12 :b "c"}

15:58 chouser: lazytest and Clojure 1.3 both have features that address that problem.

18:04 Leonidas: sorry, I keep on forgetting... what was to name of the function to divide a sequence by a predicate? (what-is-this odd? (range 10))

18:08 mrBliss: Leonidas: partition-by

18:09 Leonidas: mrBliss: thanks

18:19 mrBliss: oh, wait, this partitions every number in its own seq, I just want 2 seqs, depending on the predicate

18:20 mrBliss: clojure.contrib.seq/separate does that

18:22 Leonidas: mrBliss: ok, maybe it was that, I can't really remember

18:28 mrSpec: Hello! I'm playing with clojure & converting some java examples, Could you help me with http://paste.lisp.org/display/118027? How can I write this in Clojure?

18:32 mrBliss: mrSpec: I'm gotta go now, but have a look at http://clojuredocs.org/clojure_core/clojure.core/proxy

18:32 mrSpec: ok, thx

19:20 hippiehunter: is anyone else using appengine-magic with the 1.4.0 appengine sdk?

Logging service provided by n01se.net