#clojure log - Jan 24 2010

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

0:24 Raynes: Because Clojure isn't CL! :D

0:25 quotemstr: Err, but why the gratuitous incompatibility?

0:29 Raynes: quotemstr: I don't actually know. I just wanted to sound cool.

0:40 hiredman: is it gratuitous?

0:40 clojure is not compatible in general with CL

0:42 quotemstr: I suppose I can just define a mac.h set of macros that make it look like CL. :-)

0:42 mac.h-style, that is.

0:43 hiredman: clojurebot: what about the hyperspec?

0:43 clojurebot: hyperspec is not applicable

3:28 Hali_303: hi! technically what is the difference between a struct and a seq? for example, how to get the keys of a struct? simply using "keys" is not working, as the struct cannot be converted to ISeq

3:29 hiredman: keys of a struct?

3:30 Hali_303: hiredman: well if i do (defstruct person :name :age) then I'd like to create a struct that contains name and age

3:30 hiredman: (struct person 1 2)

3:30 Hali_303: so I know what properties are declared in the struct

3:31 ok I think i was not clear then. I'd not like to create an instance, but create a seq that contains "name" and "age"

3:32 hiredman: I don't know of a way to get the names of the keys out of the definition of the struct

3:33 why do you want that?

3:33 Hali_303: so that I can list all stuff in the struct itself

3:33 hiredman: uh

3:33 Hali_303: hm. maybe I should just use keys on a person_instance then

3:33 hiredman: the struct doesn't have stuff in it

3:34 or

3:34 the definition of a struct does not have stuff in it

3:34 it is a pattern for creating structs that have stuff in them

3:35 Hali_303: hm. then I just don't get what's the purpose of having this in Clojure. this could be simple "emulated" by having a map of properties and then the function struct would just work by having this map and all values as arguments

3:36 hiredman: a struct is a map

3:36 a struct is a map optimized for sharing some set of keys with a bunch of other maps

3:37 Hali_303: ok, but if I have a struct, and I'd like the user to type in all the fields, how do I know what fields to ask for?

3:39 or maybe struct is just there to make things faster when I'm having many maps with the same structure, but otherwise I should store such metadata elsewhere?

3:39 hiredman: that is rather nonsensical, a struct is a datastructure, what does it care about fields in a form?

3:40 structs are not even tagged with the "type" of struct that they are

3:41 Hali_303: hm. that is new to me then. then how does the struct function know what keywords to associate the given values?

3:42 hiredman: you pass in the pattern, but the name of the pattern in not exposed in the resulting struct

3:42 Hali_303: I see

3:43 hiredman: structs are not an object system

3:43 they are types

3:43 they are just a kind of optimized map

3:44 er

3:44 nuts

3:44 "they are not types"

3:44 Hali_303: I see. so if I want to achieve the above functionality, then i should just have a list of "name", "age", etc. use that to create a struct definition, and then use the resulting struct to store instances, right?

3:44 hiredman: resulting structs

3:44 why bother?

3:45 Hali_303: what do you mean?

3:45 hiredman: if you want :name and :age, just pass [:name :age] into the function and get {:name "foo" :age 42} out

3:46 or even {:name nil :age nil} => {:name "foo" :age 42}

3:46 Hali_303: what I'm saying is that I don't know what to pass until runtime

3:46 hiredman: I don't see how that change anything?

3:47 maps, vectors, keywords all can be contructed and manipulated at runtime

3:48 Hali_303: yeah, probably I'm still living in compiled OO world :)

3:49 thank you for the insights anyways, I'll continue fiddling and see what's the result

3:50 hiredman: oo is such a drag :/

4:51 kiba: hello

4:53 I am new to clojure

8:37 avarus: hi

10:54 alexyk: so you guys still do nickserv identify upon each opening of a laptop lid?

10:55 the-kenny: alexyk: hm.. yes. Why are yoy asking?

10:56 alexyk: the-kenny: to see why isn't there a revolt or something :)

10:57 or perhaps programmers enjoy procedures, even annoying and repetitive ones

10:57 the-kenny: My client does the identify-stuff for me.

10:58 angerman: same for me

11:06 * alexyk can't find the nick stuff in colloquy...

11:12 alexyk: chouser: did you see this? http://paste.pocoo.org/show/169141/

11:26 so I forgot again to add contrib to repl, and then spent 2 hours computing an evolved data structure there. How can I dynamically add contrib to the classpath from inside repl?

11:28 qbg: add-classpath is there, but deprecated

11:30 Chousuke: you could also print the data structure into a file and restart the repl :)

11:31 qbg: And make sure that contribs are always on the classpath

11:31 Chousuke: that is, if it is printable as such that you can read it back in without loss of information

11:31 qbg: Aren't the Clojure data structures also Serializable?

11:32 alexyk: Chousuke: someone has shown before how to add to classpath dynamically... the structure is too big, I actually need partition-all from seq-utils to use my mongo0stuffing function

11:32 I guess I can just paste partition-all

11:33 Chousuke: (doc add-classpath)

11:33 clojurebot: "([url]); DEPRECATED Adds the url (String or URL object) to the classpath per URLClassLoader.addURL"

11:37 chouser: alexyk: or load-file

11:38 alexyk: chouser: you mean the file with seq-utils?

11:38 chouser: alexyk: yeah, I saw that. amazing. is DateTime from YodaTime? JediTime?

11:38 alexyk: yeah

11:38 alexyk: chouser: DateTime is Joda Time

11:39 it's immutable too

11:39 chouser: yeah. sounds like good stuff

11:41 alexyk: in fact, I did add contrib to classpath, but apparently it's a 1.1.0-master-SNAPSHOT not compatible with the same-named clojure... from 1/14. These two diverged annoyingly lately, hope they converge again with a clear naming!

11:42 since lein repl failed me, I stopped doing lein deps regularly, although that still works

11:44 joegg: (subseq foo >= 4) --> "Get the subsequence of all keys whose position is >= the position where '4' would be, if it were a key." Is that a correct interpretation?

11:46 chouser: joegg: I think your use of the word 'position' may lead you astray in some circumstances.

11:48 joegg: hm... or perhaps not.

11:48 joegg: (subseq (sorted-set (comparator >) 1 10 100) >= 19)

11:48 ,(subseq (sorted-set (comparator >) 1 10 100) >= 19)

11:48 clojurebot: java.lang.ClassCastException: clojure.core$comparator__5224$fn__5226 cannot be cast to java.lang.Number

11:49 chouser: ,(subseq (sorted-set-by > 2 4 6 8) >= 4)

11:49 clojurebot: (4 2)

11:49 joegg: Oh, thanks.

11:49 chouser: ,(subseq (sorted-set-by > 2 4 6 8) > 5)

11:49 clojurebot: (4 2)

11:49 chouser: ,(subseq (sorted-set-by < 2 4 6 8) > 5)

11:49 clojurebot: (6 8)

11:50 chouser: so I think you're right. that's not quite what I expected. "position" does seem to be the right concept

11:50 joegg: Yeah, when it is in increasing order, >= can be misinterpreted to mean "the key is greater than"

11:50 chouser: right

11:50 joegg: But when it is in decreasing order, >= will actually mean "all the keys less than"

11:50 Which threw me for quite a loop while trying to come up with a way of putting subseq into words.

11:51 Besides, "does the right thing when in increasing order, does the opposite of the right thing in decreasing order" :)

11:51 chouser: heh

11:52 joegg: Why did I need to register my nick today? Did something happen in this channel recently that lead to a change?

11:53 chouser: I always register so hadn't notice, but apparently freenode is in a mighty battle against spam

11:53 alexyk: joegg: spam attack apparently

11:54 joegg: Ah, okay.

11:55 In addition to be a new clojurians and a new lisper, I'm also new to irc, so I didn't understand what was being asked of me for a little while. I figured it out, though. :)

11:55 Apparently, based on that last sentence, I'm also new to the rules of english grammar. Sigh.

11:56 chouser: joegg: heh. well, glad you figured out the irc anyway. welcome. :-)

11:59 joegg: Thanks!

12:13 bobo_: any good tutorial on clojure with some nosql storage?

12:15 avarus: bobo_: http://github.com/ragnard/redis-clojure

12:22 bobo_: avarus: thank you, will try it ouy

12:43 Scriptor: hi everyone

12:44 I've been thinking of trying clojure, but kinda intimidated by maybe having to learn another editor all over again

12:44 how important is having emacs when you want to develop in clojure?

12:45 clojurebot: with style and grace

12:47 somejan: You at least need something that checks parens (including [ and ] )

12:47 Scriptor: does that just mean highlighting matching parens?

12:48 somejan: well, some way to find out if you've mismatched parens, and to find out /which/ paren is wrong

12:49 Scriptor: ah

12:49 somejan: The indenting based on paren structure emacs does is also nice, but I guess you could use whatever indenting support your editor has

12:50 And you'll probably have to do without syntax highlighting, at least I don't think many editors support clojure syntax highlighting

12:50 but it's up to you if you find that a problem

12:51 there are plugins for Eclipse and IDEA, but I haven't tried them

12:52 Scriptor: I've tried installing the one for vim, but without much luck

12:52 might try again ow

12:52 *now

13:03 somejan: Does anyone know if it's possible to reload a modified java class from within the clojure REPL? Or does the jvm not support that?

13:11 chouser: Scriptor: there's no need to learn emacs. if you like IDEs, I'd recommend NetBeans

13:12 somejan: a stock jvm doesn't really support that. Clojure goes to some lengths to allow you to redefine things without actually trying to load a new version of a named class.

13:14 Scriptor: chouser: thanks, I prefer vim though, is vimclojure the only option for that?

13:23 kotarak: vc is not enough?

13:24 avarus: chouser: I have tried enclojure yesterday with the latest stable netbeans and it fails with nullpointerexception...are you running it with 6.8?

13:24 it installs fine but after I create a new project -> nullpointer exception

13:33 chouser: avarus: no, I don't particularly like IDEs in general, so haven't gotten very far with enclojure.

13:33 avarus: same here :(

13:34 I started with clojure yesterday and I thought I'd give enclojure a try

13:34 is there any editor that has some highlighting for clojure?:)

13:34 chouser: I mostly use vim with just syntax coloring and indentation support, without the interactive stuff.

13:35 avarus: k

13:35 Scriptor: chouser: where did you get the syntax coloring?

13:38 chouser: Scriptor: vimclojure includes that

13:41 avarus: I watched a video from peepcode yesteday (and I hate the example project), but they used textmate that seemed to support the syntax

14:04 grammati: ,(doc deftype)

14:04 clojurebot: "clojure.contrib.types/deftype;[[type-tag constructor-name docstring? attr-map?] [type-tag constructor-name docstring? attr-map? constructor] [type-tag constructor-name docstring? attr-map? constructor deconstructor]]; Define a data type by a type tag (a namespace-qualified keyword) and a symbol naming the constructor function. Optionally, a constructor and a deconstructor function can be given as well, the defaults being

14:05 joshua-choi: I've got a question on Clojure's reader's treatment of the slash symbol: is '/ hardcoded on the reader level to always be 'clojure.core//?

14:06 chouser: nope

14:07 Chousuke: hmm

14:07 the symbol / is special-cased though.

14:07 joshua-choi: Yeah, that's what I thought

14:08 I can't figure out a way to redefine '/ in any namespace other than clojure.core

14:08 chouser: ,(binding [*ns* (the-ns 'foo)] (read-string "`/"))

14:08 clojurebot: java.lang.Exception: No namespace: foo found

14:08 chouser: ,(binding [*ns* (in-ns 'foo)] (read-string "`/"))

14:08 clojurebot: (quote foo//)

14:08 Chousuke: ,foo//

14:08 clojurebot: Invalid token: foo//

14:08 Chousuke: ,clojure.core//

14:08 clojurebot: #<core$_SLASH___4534 clojure.core$_SLASH___4534@77cddd>

14:08 kotarak: I would think messing with / is a bad idea.

14:09 joshua-choi: I'm writing a Clojure parser in Clojure, so I need to know how this works

14:09 Chousuke: so yeah, clojure.core// is a special case

14:09 kotarak: Then looking at the special casing in the reader would be of intereset.

14:10 joshua-choi: Yeah, I'm having trouble with reading LispReader.java���I'm actually not very good at reading regular expressions and Java code...:(

14:10 In any case, I did find a special case for / in LispReader.java

14:10 But Chouser's example seems to show that it's redefinable into other namespaces

14:11 Chousuke: I would say that's a bug

14:11 joshua-choi: Hmm

14:11 Chousuke: ,'foo// ;does not work

14:11 clojurebot: Invalid token: foo//

14:11 joshua-choi: Well, there are two issues

14:11 Chousuke: however

14:11 joshua-choi: One is the bare slash symbol: /

14:12 Chousuke: ,`/

14:12 clojurebot: clojure.core//

14:12 joshua-choi: The other is the qualified slash symbol: a//

14:12 Chousuke: that works in the foo namespace and produces foo//, but only because the symbol / is read first and ` then expands it programmatically

14:12 kotarak: ,`a//

14:12 clojurebot: Invalid token: a//

14:12 joshua-choi: I also couldn't find a way to qualify the slash symbol with any namespace other than clojure.core; that might be hardcoded too

14:12 Hmm

14:12 Chousuke: there are no checks in place ensuring consistency of symbols

14:13 ,(symbol "foo bar")

14:13 clojurebot: foo bar

14:13 joshua-choi: Yeah, the symbol function is weird

14:13 ,(symbol "a/b" "c")

14:13 clojurebot: a/b/c

14:13 joshua-choi: ,(symbol "a" "b/c")

14:13 clojurebot: a/b/c

14:13 Chousuke: it trusts you not to create invalid symbols with it

14:13 joshua-choi: Yeah

14:14 The thing is: what are the official rules when it comes to the slash symbols?

14:14 Chousuke: but you could use it in a macro to create code that would be unreadable.

14:14 joshua-choi: clojure.org/reader just says that "/ means the division operator."

14:14 Chousuke: yeah, and that would be clojure.core//

14:14 joshua-choi: Yeah

14:14 Chousuke: so I guess you'll have to assume / is reserved

14:14 joshua-choi: But does that mean that / cannot be defined in any other namespace too?

14:14 Okay

14:15 What about the qualified clojure.core//?

14:15 ,'a//

14:15 clojurebot: Invalid token: a//

14:15 joshua-choi: Is that hardcoded too?

14:15 Chousuke: that's hard-coded too.

14:15 joshua-choi: Okay, good

14:15 Then I know what to do know; thanks for the help

14:15 s/know/now ugh

14:24 kotarak: Does anyone here have contact to Alex Osborne?

14:25 * Raynes yells "ALLLLEEEEEEEX" at the top of his lungs.

14:25 Raynes: Nope, can't hear me. Sorry. :|

14:28 kotarak: Raynes: maybe Australia is too far. ;)

14:29 Raynes: kotarak: It's... It's just too far. :(

14:46 LauJensen: Just pulled the latest clojure/contrib from github, ant compiled them, then I pulled swank, lein compiled and not Swank cant started because swank.swank/start-server and /ignore-protocol-version aren't defined - How do I get around this?

14:47 dnolen: LauJensen: are you using lein from source?

14:48 LauJensen: Not following

14:48 dnolen: like are you line from source or did you create a lein jar

14:48 ?

14:49 LauJensen: git pull && lein jar

14:49 dnolen: LauJensen: hmm, I thought in order to build lein from source you needed a stable version of lein.

14:50 LauJensen: Sorry, I thought you meant swank

14:50 For lein I just downloaded the shell script and ran self-install, thats a while ago now

14:51 dnolen: things might be out of date then, I only know how to use lein from source really.

14:54 LauJensen: any tips you need to pass on before I pull it ?

14:55 dnolen: lein-swank needs to be built from source and placed in lein/lib/ replacing whichever lein-swank is there.

15:15 somejan: I made a running-sum function, that lazily generates a seq with the running total of the input seq

15:15 avarus: wow :)

15:16 somejan: but it is 7 lines long, and in a functional language supporting lazy sequences, I think it should be more like a 3-liner or something. http://pastebin.com/m3a479ac

15:16 is there a way to do this much shorter?

15:49 LauJensen: ~source reductions

15:49 That also looks lazy somejan

15:57 qbg: Does the appearance of &env in defmacro mean that we might get first class environments?

16:02 the-kenny: Looks like vijual isn't very fast with draw-directed-graph-image...

16:03 357 edges is too much

16:09 (I just wanted to do this for fun.. but it doesn't look very good)

16:32 Uh, I broke vijual

16:51 quidnunc: Is swank-clojure HEAD supposed to be working with clojure HEAD?

17:35 Raynes: I just love null.

17:36 hiredman: nil

17:54 neotyk: Hi

17:54 congomongo: how do I (insert! ...) ignoring reesults?

17:55 docs says: To insert as a side-effect only specify :to as nil.

17:55 but trying {:to nil} throws exceptions

21:33 chouser: anyone have a link to ctx?

21:43 nevermind

21:44 joshua-choi: I have a question on the Clojure parser: namely, its ability to resolve namespace aliases in symbols and keywords

21:44 How does it do it? It must maintain some sort of state when it parses Clojure forms

21:45 But aliases are created by functions, so I don't know how it would figure it out before it even finishes reading; does it do two passes?

21:48 mquander: clojure newbie q: what is the most clojureish way to interpolate various values into the middle of a string? is there a more idiomatic way than (str "first-part:" v1 "another-part:" v2 "yet-another-part:") etc

21:49 tolstoy: (format "something %s or %s" "foo" "bar")

21:49 ,(format "something '%s' or '%s'!" "foo" "bar")

21:49 clojurebot: "something 'foo' or 'bar'!"

21:50 mquander: ty time to go read about java string.format then

21:51 somnium: joshua-choi: how do you mean? the reader doesn't evaluate symbols

21:51 ,(read-string "(foo s2/zonk :boom ::bam)")

21:51 clojurebot: (foo s2/zonk :boom :sandbox/bam)

21:51 joshua-choi: @somnium: I didn't realize that. But what about double-coloned keywords?

21:52 The reader must know the current namespace's name to resolve them

21:52 tomoj: aw, I thought symbols evaluated to themselves?

21:52 somnium: I guess it checks *ns*

21:52 joshua-choi: But *ns* cannot be known until forms are read anyway, since it depends on ns or in-ns or whatever...right?

21:52 somnium: hmm

21:53 joshua-choi: Also, double-coloned keywords resolve namespace aliases when they are prefixed

21:53 ,::a/b

21:53 Well, if there was a namespace aliased to a, then it would resolve to it

21:54 chouser: ,(do (in-ns 'foo) ::bar)

21:54 clojurebot: :sandbox/bar

21:54 hiredman: tomoj: uh, symbols definitely do not resolve to themselves

21:55 joshua-choi: Can the sandbox alias namespaces?

21:56 ,(do (require '[clojure.core :as c]) ::c/a)

21:56 chouser: joshua-choi: try that at your repl. you'll see the same thing.

21:56 hiredman: the do somehow messes it up

21:57 ,(require '[clojure.core :as c])

21:57 clojurebot: nil

21:57 hiredman: ,::c/a

21:57 clojurebot: :clojure.core/a

21:57 joshua-choi: Righto, the reader seems to store namespace aliases...apparently

21:57 hiredman: eh? no

21:57 joshua-choi: Hmm

21:58 hiredman: the reading happens in a context

21:58 joshua-choi: When the reader reads a file that contains

21:58 (require '[clojure.core :as c]) ::c/a

21:58 It cannot determine the context of ::c/a without parsing���and *evaluating*���the require call

21:58 I think

21:59 hiredman: the code in lireader makes reference to Compiler.currentNS()

21:59 lispreader

21:59 tomoj: hiredman: oops, I meant keywords

21:59 I was thinking ruby for a second

22:00 hiredman: joshua-choi: ::c/a is evaluated in the context of the read

22:00 joshua-choi: Hmm, I'm not sure I understand

22:00 somnium: is ::a/b a valid keyword? it seems like namespacing a namespaced keyword

22:00 hiredman: clojure generally reads a file form by form

22:00 well

22:00 joshua-choi: But does it evaluate form by form?

22:00 hiredman: reads and evalutes

22:00 ,(doc load-file)

22:00 clojurebot: "([name]); Sequentially read and evaluate the set of forms contained in the file."

22:01 hiredman: ^-

22:01 joshua-choi: That is interesting, and unfortunate

22:01 hiredman: somnium: it resolves through aliased namespaces

22:01 joshua-choi: how so?

22:01 joshua-choi: Well, unfortunate for me :P

22:02 It means that, for my Clojure in Clojure parser, I cannot read a series of forms and turn them completely into their equivalent Clojure data structures without evaluation

22:02 I suppose that I can make unresolved-namespace-qualified keywords a different data structure...

22:03 hiredman: *shrug*

22:03 joshua-choi: But that is very interesting: I did not realize that the reader actually evaluates each form before the next form in a given Clojure file

22:03 That explains a lot

22:03 hiredman: nono

22:03 the reader does not evaluate

22:03 joshua-choi: I mean the complier

22:04 But the reader cannot resolve namespace-qualified keywords without the compiler and its knowledge of the current namespace

22:04 hiredman: well

22:04 joshua-choi: I was under the impression that the Clojure reader was stateless, but this is not so; it's okay though

22:05 hiredman: I am pretty sure Compile.currentNS() is just *ns*

22:05 * hiredman has quiet figured out searching in emacs

22:06 joshua-choi: Yeah, but the fact that the reader needs to know *ns* means that it (or rather, the compiler) has to evaluate previous forms, or the namespace that the reader is called in

22:06 It makes sense

22:08 ,(defn a [] (in-ns 'foo) ::bar)

22:08 clojurebot: DENIED

22:08 joshua-choi: Dang

22:21 mquander: when i am in a slime buffer and i c-x c-e to eval (ns fresh-ns) it sets *ns* to fresh-ns and further evaluations from that buffer seem to correctly use fresh-ns

22:22 however, if i then go to the REPL and check *ns*, it's still whatever it was before

22:22 Raynes: ATTENTION: I hate JavaMail.

22:22 mquander: if i eval (ns fresh-ns) in the REPL, it sets it in the context of the REPL, but i wonder doing it from the other buffer didn't do the same

22:23 can someone identify the odd misconceptions i have about the connection between the REPL and my evaluated expressions :|

22:24 oh, and i just noticed that my repl prompt is the current namespace. i'm a quick one

22:27 mrmargolis: Is there some sort of trick for running the clojure-contrib tests? "ant test" works for clojure core but doesn't appear to actually run tests for clojure-contrib. Not seeing anything else that works in build.xml.

22:34 nevermind. I didn't set my clojure.jar path.

22:39 alexyk: I need to define a short defn which will pass all its args to another, adding one more. How do I define its arg list so it's easily passed on?

22:40 chouser: (defn foo [& args] (apply bar new-arg args))

22:40 alexyk: thx!

22:41 chouser: hm... or even better, (def foo (partial bar new-arg))

22:41 alexyk: o!

22:59 chouser: I got: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Keyword, trying to do: (apply fetch args :as :cursor). since [& args] makes them a seq, perhaps I have to conj the rest?

23:00 chouser: alexyk: apply wants the last arg you give it to be the seq it should expand

23:00 if you need to add args to the right-hand-side, you'll have to muck around a bit. use 'concat' or something

23:01 hiredman: you can just throw in a nil

23:01 alexyk: chouser: ah ok, so if I give two more they should go first and args last?

23:01 chouser: (apply fetch (concat args [:as :cursor])) or something.

23:01 alexyk: fetch converts to a map so the order doesn't matter

23:02 chouser: ah, ok. so yse, (apply fetch :as :cursor args)

23:02 alexyk: cool

23:02 chouser: or (partial fetch :as :cursor)

23:06 g'night!

23:06 alexyk: night!

23:07 hiredman: turns out need to append at right; if I do (apply fetch args :as :cursor nil), this is what you mean? will args be flattened?

23:08 args is a seq already...

23:09 hiredman: alexyk: sorry, came in half way through

23:09 args will not be flattened in that case

23:09 but apply won't complain about not being able to turn stuff into an ISeq

23:10 alexyk: so (apply fetch (concat args [:as :cursor])) is the prettiest we got?

23:16 somnium: maybe (def foo (apply partial fetch args))

23:17 ,(let [f (apply partial + (range 5))] (f 42 72))

23:17 clojurebot: 124

23:23 alexyk: mm ok

23:23 somnium: btw this is all adding to comnomongo :)

23:24 another refinement: in these args, there may be two, :progress <number>, which I then need to extract. How do I check if a seq contains such a pair?

23:26 somnium: ,(some #(= '(3 4) %) (partition 2 (range 6)))

23:26 clojurebot: nil

23:26 somnium: (some #(= '(4 5) %) (partition 2 (range 6)))

23:26 ,(some #(= '(3 4) %) (partition 2 (range 6)))

23:26 clojurebot: nil

23:26 somnium: bah

23:27 alexyk: somnium: they may be in a wrong-parity position...

23:28 also I'm not knowing the number in advance

23:28 so I guess I'll get the :progress and then check the num

23:28 i.e. is it a num

23:28 somnium: ,(let [r (partition 2 (range 6))] (println r) (some #(= '(4 5) %) (partition 2 (range 6))))

23:28 clojurebot: true

23:28 ((0 1) (2 3) (4 5))

23:29 somnium: hmm, his *out* is slow

23:31 ,(partition 2 (interleave (range 6) (rest (range 6))))

23:31 clojurebot: ((0 1) (1 2) (2 3) (3 4) (4 5))

23:31 somnium: maybe something like that and check for pairs?

23:31 looking forward to the additions, already well behind on merging stuff :)

23:32 alexyk: yep

23:35 is this how I check which position is an element in in a seq:

23:35 ,(some (fn [[e pos]] (when (= e :progress) pos)) (map (fn [x y] [x y]) '(:a :b :progress) (iterate inc 0)))

23:35 clojurebot: 2

23:35 alexyk: surely there's some find or something :)

23:36 I can replace the map my interleave ok

23:37 somnium: there's indexed in c.c

23:37 alexyk: indexed?

23:37 somnium: (doc indexed)

23:37 clojurebot: "clojure.contrib.seq-utils/indexed;[[s]]; Returns a lazy sequence of [index, item] pairs, where items come from 's' and indexes count up from zero. (indexed '(a b c d)) => ([0 a] [1 b] [2 c] [3 d])"

23:37 alexyk: yeah... still ass-backwards use of some, seems like

23:37 somnium: some is just a very poorly named fn

23:37 alexyk: where's some (find seq elem)??

23:38 meaning English some? :)

23:38 return pos if found, nil if not, for chrissake

23:39 somnium: you can do (comp first filter) if it makes you feel better :)

23:39 alexyk: well...

23:39 (doc find)

23:39 clojurebot: "([map key]); Returns the map entry for key, or nil if key not present."

23:40 alexyk: something completely different

23:42 ,(find (apply hash-map (interleave [:a :b :c] (iterate inc 0))) :b)

23:42 clojurebot: [:b 1]

23:42 alexyk: ,((apply hash-map (interleave [:a :b :c] (iterate inc 0))) :b)

23:42 clojurebot: 1

23:44 alexyk: how do I take two last elements of a seq?

23:44 tolstoy: anonymous funs implement callable and runnable, right?

23:45 Can't seem to get the ScheduleExecutorService to work.

23:46 Ah. integers are not longs.

23:51 alexyk: how do I maintain a counter in a (while ...)

23:52 tolstoy: alexyk: Use for instead? Or map? Or loop?

23:53 alexyk: tolstoy: I have a fast tight while... will loop be as fast?

23:54 tolstoy: probably not.

23:54 For some reason, I'm thinking that "maintain a counter" is non-functional, so not really all that easy to do.

23:55 Whenever I start thinking things like that, I know I'm thinking in Java (or Cish).

23:55 alexyk: tolstoy: yeah... someone has shown me an atom-based way which I forgot

23:56 tolstoy: Are you wanting to process a list and count up only some of the items?

23:57 alexyk: tolstoy: no, it's a database cursor

23:57 the while is: (while (.hasNext cursor) ...) ; somnium would recognize this one :)

23:58 tolstoy: Can't use reduce?

23:59 somnium: you can use loop, better if you want to keep an index I guess

Logging service provided by n01se.net