#clojure log - Sep 28 2011

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

0:00 technomancy: hahaha http://wondermark.com/302/

0:00 speaking of confusing the crap out

0:00 * brehaut head asplode

0:02 j941: (

0:02 (juxt #((map count ) ))

0:02 is returning nothing (i.e. its not executing )

0:03 (its in a larger context, of course.

0:03 brehaut: &((juxt #(map count %)) [1 2 3])

0:03 lazybot: java.lang.UnsupportedOperationException: count not supported on this type: Integer

0:03 brehaut: err

0:03 &((juxt #(map count %)) [[1 2 3] [2 3]])

0:03 lazybot: ⇒ [(3 2)]

0:04 brehaut: thats the closest i can work out that you might have meant

0:04 and juxt on a single functions is perhaps not the most useful thing ever

0:04 technomancy: wow and this one is like basically a metaphor for emacs: http://wondermark.com/664/

0:04 j941: well.. im planning on adding more

0:04 :)

0:05 zerokarmaleft: heh

0:05 dnolen: technomancy: haha

0:05 brehaut: ahaha

0:06 j941: ok here

0:06 http://pastebin.com/SA184uLy

0:06 its odd, returning one of those cryptic #(ss_sss11_->cl_2_Z looking things.

0:06 brehaut: j941: (require '[clojure.string :as str]) is quite nice too btw; eg str/join str/split

0:07 j941: oh yeah i gotta do that

0:07 Apage43: j941: juxt returns a closure

0:07 j941: im tired of importing methods

0:07 Apage43: more parens.

0:07 j941: whats wrong with a closure?

0:07 brehaut: j941: you're a fan of C family languages?

0:07 Apage43: nothing

0:07 you just have to actually call it

0:07 zerokarmaleft: technomancy: dammit, this is a rabbit hole i don't need right now

0:07 Apage43: ((juxt fn1 fn2) val)

0:07 j941: yeah especially when debuggin

0:08 o ok

0:08 technomancy: zerokarmaleft: what, you haven't discovered wondermark? I must say I envy you; so much to look forward to!

0:08 clojurebot: piranhamoose?

0:08 clojurebot: piranhamoose is unadulterated awesome: http://blog.howfastareyou.net/wp-content/uploads/2009/08/piranhamoose.jpg

0:09 technomancy: clojurebot: absolut botsnack

0:09 clojurebot: forget botsnack is Thanks! Can I have chocolate next time

0:09 * technomancy facepalms

0:09 cark: mhh is it possible to "override" protected methods or not with proxy ?

0:09 j941: beautiful ! it worx!

0:09 technomancy: clojurebot: forget forget botsnack |is| Thanks! Can I have chocolate next time

0:09 clojurebot: I forgot that forget botsnack is Thanks! Can I have chocolate next time

0:10 technomancy: you're going to blow your stack one of these days, I'm telling you

0:10 brehaut: hes already pretty garbled since i did some apparently nafarious (use … earlier

0:10 ,(inc 1)

0:10 clojurebot: #<ExecutionException java.util.concurrent.ExecutionException: java.lang.IllegalStateException: replace already refers to: #'clojure.string/replace in namespace: sandbox>

0:11 technomancy: heh

0:12 brehaut: im going to blame arrows again

0:14 j941: so we can map a list into a map ?

0:14 btw im gonna thank you guys on my thesis. this is the last table for my phd thesis !

0:15 tryin to go [1 2 3] -> {:a 1 :b 2 :c 3)

0:15 brehaut: j941: how do you mean?

0:15 amalloy: &(zipmap [:a :b :c] [1 2 3])?

0:15 lazybot: ⇒ {:c 3, :b 2, :a 1}

0:15 brehaut: ,(zipmap [:a :b :c] [1 2 3])

0:15 clojurebot: #<ExecutionException java.util.concurrent.ExecutionException: java.lang.IllegalStateException: replace already refers to: #'clojure.string/replace in namespace: sandbox>

0:15 j941: oh awesome

0:15 amalloy: brehaut: irc.freenode.WrongBotException

0:16 brehaut: (dec brehaut)

0:16 lazybot: You can't adjust your own karma.

0:16 amalloy: (dec clojurebot)

0:16 lazybot: ⟹ 1

0:16 brehaut: lol

0:17 amalloy: brehaut: did i tell you, when i was writing http://4clojure.com/problem/107 i got jealous of haskell again? just write a function of two args, don't worry about this manual currying nonsense

0:17 brehaut: its easy to get jealous of haskell

0:17 (from a distance anyway)

0:17 amalloy: *nod* that's why i never use is

0:18 j941: so... from a distance... what do the haskell tempations lead to?

0:18 brehaut: j941: jenga towers of monads

0:18 napping: what's hard about a curried function of two arguments?

0:18 j941: monads ?

0:19 i thought those were okay

0:19 amalloy: napping: nothing is, really

0:19 brehaut: they are powerful and useful

0:19 j941: everyone talks about em like they are gods gift to programers

0:19 ok ... but...

0:19 napping: everyone talks like people talk like they are god's gift to programmers

0:19 brehaut: but, if you have to stack them high, things get unwiedly

0:20 amalloy: it's just (fn foo [a b] ...) instead of (fn foo [a] (fn [b] ...))

0:20 simpler

0:20 j941: like objects in java

0:20 napping: aren't there macros for that?

0:20 amalloy: *shrug* you can write them

0:20 j941: does zipmap destructure for you ?

0:20 amalloy: but it doesn't actually simplify the code much since you have to specify # args

0:21 brehaut: i need to find time do some 4clojure stuff

0:22 napping: you've seen the Racket syntax?

0:22 alandipert: once you're hooked, the time will find you

0:22 j941: brehaut sounds like u do plenty of clojure

0:22 brehaut: j941: not really, i dabble in my spare time

0:22 j941: really how u know it so well.

0:23 oh oops i saw 4clojure, not clojure.

0:23 brehaut: theres a bunch of people in this channel who would probably laugh at that assessment

0:23 j941: not me

0:23 napping: http://docs.racket-lang.org/guide/define.html

0:24 (defn [[f x] y] body), basically

0:24 j941: (->> (map #(clojure.string/split % #"_"))) (->> zipmap [:a :b] )

0:24 napping: doesn't work so nicely with (defn name [params*] ...)

0:25 j941: ClassCastException

0:25 was hoping the list would get destructured into the first two keys

0:31 brehaut: &(let [lines (map #(clojure.string/split % #"_") ["1_2" "b_c" "3_4"])] (map (partial zipmap [:a :b]) lines))

0:31 lazybot: ⇒ ({:b "2", :a "1"} {:b "c", :a "b"} {:b "4", :a "3"})

0:32 brehaut: no need to go threading macro happy ;)

0:32 j941: o ok

0:33 i am threading obsessesd

0:33 brehaut: if you did, it would be ##((->> ["1_2" "b_c" "3_4"] (map #(clojure.string/split % #"_")) (map (partial zipmap [:a :b])))

0:33 blast

0:33 &(->> ["1_2" "b_c" "3_4"] (map #(clojure.string/split % #"_")) (map (partial zipmap [:a :b])))

0:33 lazybot: ⇒ ({:b "2", :a "1"} {:b "c", :a "b"} {:b "4", :a "3"})

0:33 brehaut: amalloy: whats lazybots inline eval symbol?

0:34 j941: threading is like pipes. and i like the feeling of "history | grep 'ls'

0:34 amalloy: ##

0:34 but you have to have a well-formed sexp :P

0:34 napping: is it safe to do (for [x @my-ref] body) in a dosync?

0:34 j941: so can i persist a list by just doing (def a ll) if ll is a function?

0:35 brehaut: amalloy: oh haha :)

0:35 j941: nope

0:35 clojurebot: I don't understand.

0:35 j941: (def a (ll))

0:35 dnolen: nappy: laziness in a dosync is probably not a good idea

0:35 j941: that does it. wanted to store my list in memory

0:35 dnolen: napping: oops, sorry mistyped.

0:36 napping: Laziness is what I was worried about

0:37 amalloy: well, everything is "safe" depending on what behavior you want

0:38 napping: I want the ref lookup to happen in the transaction, and then filtering to happen sometime

0:40 Apage43: i suspect that form will work

0:40 amalloy: probably, but it's easier to try it than to speculate

0:41 napping: I don't know how to test whether it's delayed too long

0:41 amalloy: &(let [r (ref [])] (dosync (let [result (for [x @r] x)] (alter r conj 1) result))

0:41 lazybot: ⇒ () ; Adjusted to (let [r (ref [])] (dosync (let [result (for [x (clojure.core/deref r)] x)] (alter r conj 1) result)))

0:41 napping: hmm, maybe a ref-set later in the same transaction

0:43 (def x (ref '(1 2 3))) (dosync (let [z (for [v @x] v)] (ref-set x '(4 5 6)) z))

0:43 produces (1 2 3)

0:44 amalloy: napping: i just did that for you, up above

0:45 technomancy: I wonder if we could get a security audit done on clojars.

0:45 (after we switch from sha1 to bcrypt for password hashes, of course)

0:55 brehaut: question time. xml-rpc has an 'array' notation, necessary-evil currently deserializes it to a vector and only serializes vectors back to 'arrays'; It seems fairly obvious that i should also make PersistentList serialize to arrays, but should LazySeq also be included there?

0:56 Ive explicitly avoided having lazyseq serialisation to avoid realizing infinite seqs and forcing the user of the library to make a decision about how those lazy values are handled.

0:56 im not sure if thats the right decision tough

0:56 though*

1:00 amalloy: brehaut: it seems kinda rude not to handle lazy seqs

1:00 brehaut: its a bit annoying yeah

1:00 alandipert: brehaut: i vote all things seq-able... hopefully users understand there's no such thing as infinite xml

1:00 (thank goodness!)

1:01 brehaut: the thought of an endless stream of xmlrpc xml is horrifying

1:01 * brehaut shudders

1:01 amalloy: (repeatedly #(vomit xml))

1:02 brehaut: lol

1:02 thanks for the feedback. i shall fix that in the next release

1:02 (not that anyone in their right mind is using xmlrpc)

1:07 j941: how can i make a pre condition that asserts that the "type" of something is list

1:07 :pre isList(l)

1:07 ibdknox: ,(doc list?)

1:07 j941: i mean "pre isList(l)

1:07 clojurebot: "([x]); Returns true if x implements IPersistentList"

1:07 brehaut: :pre (list? l)

1:08 j941: wow thats cool

1:08 brehaut: (apropos '?)

1:08 &(apropos '?)

1:08 ibdknox: lol

1:08 lazybot: java.lang.Exception: Unable to resolve symbol: apropos in this context

1:08 brehaut: &(clojure.repl/apropos '?)

1:08 lazybot: java.lang.ClassNotFoundException: clojure.repl

1:08 brehaut: fine

1:08 j941: there are lots of useful predicates like that

1:10 im sure theres some good joke code to me made with the rational? predicate

1:10 &(rational? 'brehaut)

1:10 lazybot: ⇒ false

1:11 amalloy: j941: you almost certainly don't want to assert that it's a list

1:11 j941: why

1:12 amalloy: because you want to treat vectors and seqs the same, probably

1:12 j941: in any case ([a]) throws an exception

1:12 &([a])

1:12 lazybot: java.lang.Exception: Unable to resolve symbol: a in this context

1:12 napping: &(list? (filter (constantly true) '(1 2 3)))

1:12 lazybot: ⇒ false

1:12 j941: &([1 2])

1:12 lazybot: java.lang.IllegalArgumentException: Wrong number of args (0) passed to: PersistentVector

1:12 j941: oh ok

1:13 how can i assert its an iSeq

1:13 :pre .....

1:13 clojurebot: Gabh mo leithscéal?

1:13 brehaut: &(seq? (list 1 2 3))

1:13 lazybot: ⇒ true

1:13 j941: o ok

1:13 amalloy: brehaut: boooooo

1:13 &(seq? [1 2 3])

1:13 lazybot: ⇒ false

1:14 brehaut: boo?

1:14 clojurebot: book is http://www.pragprog.com/titles/shcloj/programming-clojure

1:14 amalloy: j941: you could write java instead? encumbering every list-handling function with "hey, first check that this is a list" is not a productive way to spend your time in a loosely-typed language

1:14 brehaut: thanks bot

1:14 j941: hahah

1:14 yeah your write

1:14 right

1:15 java just iterator pattern :)

1:15 for (a : mySeq) {...}

1:15 works on everything

1:15 amalloy: brehaut: well. aside from the dangers of telling people what they ask for instead of what they need to know, i think someone who wants to check whether something is "a list" probably is willing to accept vectors

1:15 napping: not a good way to spend time in any decent statictly-typed language either. That's what type inference is for.

1:16 j941: im starting to like clojure.

1:16 too bad they dont have jobs for it. i guess it will always be a guilty pleasure .

1:16 brehaut: j941: make your own job

1:17 amalloy: sure, point taken

1:17 its clearly time for me to go be productive elsewhere

1:17 j941: yup.

1:17 amalloy: j941: who is "they"?

1:17 j941: the man lol

1:18 amalloy: at least three people you've talked to in the last half hour make a living working on clojure

1:18 j941: thats true.

1:18 its actually pretty popular esp in bigger cities. im in CT though.

1:19 i think the supply is prob less than demand so in that sense, its prob better then python.

1:23 brehaut: why on earth have i written (String. …) in some code. fail.

1:24 j941: im conflicted about functions. too many functions -> boilerplate

1:24 i like bigger methods in clojure. big, domain specific blocks of code.

1:25 the idea of needing a name for every method is a remnant of OO over modelling,

1:29 ( map (partial zipmap [_ :p _ :c _ _ :f])

1:29 doesnt like the _'s

1:30 ( map (partial zipmap [_ :b _ :c _ _ :f])

1:30 seems good 2 me :(

1:30 &( map (partial zipmap [_ :p _ :c _ _ :f])

1:30 lazybot: java.lang.Exception: Unable to resolve symbol: _ in this context

1:46 j941: how can i create a submap from a map ?

1:46 {:a 1 :b 2 :c 3} -> {:a 1}

1:47 seems like "filter" would do the trick. but not sure how.

1:50 napping: maybe

1:50 it can probably be done more efficiently

1:50 j941: remove

1:50 (remove #(= (:name %) "eric") mylist)

1:51 ibdknox: ,(doc select-keys)

1:51 clojurebot: "([map keyseq]); Returns a map containing only those entries in map whose key is in keys"

1:51 napping: but you could filter by a set of the names you want to keep

1:51 j941: (remove #(= (:name %) "eric") mylist)

1:51 oh ok

1:52 ibdknox: ,(select-keys {:a 1 :b 2 :c 3} [:a])

1:52 clojurebot: {:a 1}

1:53 aamar: Any recent opinions on profiling code? clojure.contrib.profile vs. jvisualvm vs. other?

1:53 j941: duh just found it

1:53 !

1:53 thanx

1:59 scottj: aamar: yourkit is the best I've seen

2:01 aamar: scottj: ah, a commercial option... $500. interesting.

2:02 I'll try it out; thanks for the tip.

2:02 scottj: yeah use the evaluation version

2:03 I think they have a free version somewhere for open source projects

2:39 pyr: ibdknox: great news!

2:52 ibdknox: still doesn't work for me

2:53 ibdknox: pyr: forgot to push to clojars

2:53 just pushed it up

2:54 pyr: nope i had lein i nstalled it

2:54 ibdknox: hm

2:54 pyr: i use (pe/on (dom/query "a.something") :click ...)

2:54 ibdknox: and that does what?

2:54 pyr: nothing

2:55 ibdknox: hm

2:55 pyr: if i only (pjs/log "foo") in the event handler, nothing happens

2:55 ibdknox: do the a.something's exist already?

2:55 pyr: yes

2:55 ibdknox: if they don't it won't work

2:55 hm

2:56 pyr: hmm lemme check though

2:56 ibdknox: it works in the todo example if I change it to (dom/query "li")

2:56 pyr: erf

2:57 ibdknox: but only for the ones that already exist, since it doesn't try to run that query over and over again

2:57 for every possible hit target

2:58 pyr: is there the equivalent of $() ?

2:58 so i can start my handlers when i'm sure everything is ready ?

2:58 ibdknox: (dom/query) is more or less equivalent

2:58 oh

2:59 you mean $(document).ready?

2:59 pyr: yeah

2:59 ibdknox: no, but if you order your handlers after the append call it should be fine

2:59 pyr: google closure intentionally doesn't have a document.ready solution

3:01 pyr: ah, alright

3:01 still no luck, must be doing something wrong

3:03 ibdknox: this is exactly what I'm using: https://gist.github.com/7a5b6722ccbaf7645525

3:03 pyr: indeed i was :)

3:04 alright, great, having events on queries again is really nice

3:05 i don't think i'm missing anything now

3:07 ibdknox: sweet :)

3:09 pyr: ibdknox: it fixes a pain, since to have events i had to have a bunch of partials

3:09 and including partials in partials is cumbersome

3:09 ibdknox: mm

3:09 ideally there would be named elements in a partial

3:09 and you could bind events to those

3:09 that's the goal

3:09 not sure how to do that yet though

3:11 but that's it for me for tonight :) Good luck!

3:12 pyr: thanks :)

3:35 rata_: hi

3:37 iAmerikan: I'm checking out clojure, and was wondering if anyone could point out my issue here? http://snips.tk/nyd3/

3:38 napping: &(let [num 3] (if (= (rem num 5) 0) "buzz" num))

3:38 lazybot: ⇒ 3

3:38 hiredman: iAmerikan: think it through

3:38 napping: function returns value of last expression

3:38 raek: iAmerikan: in functional programming languages, the expression is the building block rather than the statement

3:39 rata_: what do you think about allowing nested #(...) fns and using %%, %%1, %%2, and so on, as in (update-in m [k1] #(for [e %] (update-in e [k2] #(map f %%))))?

3:39 raek: but clojure does provide an "imperative" construct that allows you to evaluate two expression in the place of one

3:39 hiredman: raek: horrible

3:39 opqdonut: rata_: horrible

3:40 napping: tasty deBruijn indices

3:40 rata_: why?

3:40 raek: namely 'do'. it evaluates all expressions and returns the value of the last one

3:40 clojurebot: why not?

3:40 raek: defn has an "implicit do", which means that your example is thr same as (defn fizz-buzz [num] (do (if ...) (if ...)))

3:41 iAmerikan: oooh

3:41 opqdonut: napping: except those are not deBruijn indexes, right?

3:41 napping: could be deBruijn levels, I guess

3:41 raek: i.e. the value of the first conditional expression is evaluated and discarded. then the second is evaluated and returned

3:41 napping: but the number of % is how many binders out to go

3:41 opqdonut: deB would be: %1 referring to the first argument of the innermost #(), %%1 to the next #() etc

3:41 napping: was that not the proposal?

3:41 opqdonut: maybe I misread

3:42 or -understood

3:42 raek: iAmerikan: you can use 'cond' if you want something prettier than nesting a bunch of ifs

3:42 napping: anways, deBruijn levels are the ones that count the other way, and are maybe not much better

3:42 raek: that's probably the wrong way to go

3:43 iAmerikan: I'll look into it, thank you, I'm extremely new to functional programming, and still a novice w/ OOP/procedural

3:43 napping: iAmerikan: try the "str" function

3:43 raek: (cond (zero? (rem num 3)) "fizz", (zero? (rem num 5)) "buzz", :else num)

3:43 napping: call it with a few argumnets, and nills thrown in

3:45 iAmerikan: can I save to .clj then run clj foo.clj to run it?

3:45 while I'm here can anyone suggest a clojure resource for beginners?

3:45 rata_: napping, opqdonut: it could be both ways (not at the same time obviously)

3:46 raek: iAmerikan: I recommend taking a look at leiningen.

3:46 iAmerikan: Thank you

3:46 napping: rata_: http://www.e-pig.org/epilogue/?p=773

3:47 "M’colleague Bob Atkey once memorably described the capacity to put up with de Bruijn indices as a Cylon detector, the kind of reverse Turing Test that the humans in Battlestar Galactica invent, the better to recognize one another by their common inadequacies. He had a point."

3:47 opqdonut: :)

3:48 raek: lein new fizzbuzz, put stuff in fizzbuzz/src/fizzbuzz/core.clj, put (ns fizzbuzz.core) at the top of that file, make a function called (defn -main [] ...) that contains code you want to test, run with "lein run fizzbuzz.main"

3:49 iAmerikan: but it is often more rewarding to develop in a repl. use "lein repl" in the project to get one, (require 'fizzbuzz.core) to load you file and (in-ns 'fizzbuzz.core) to move the repl into it

3:53 iAmerikan: clojure does not come with a standard 'clj' script (unlike python and ruby, for example). there are tools that make it simpler to do "one-off scripts", but the project approach is simpler to use when you need to split up your code into more than one source file.

3:54 so IMHO it's good to get acquainted with it as soon as possible

3:54 iAmerikan: Thank you again :D

3:59 hiredman: clojurebot should load a fresh clojure runtime for the sandbox every 10 minutes now, I think I figured out all the security problems I had with with reloading RT with a security manager in place

4:01 Zolrath: I'm looking for a postgresql library for clojure, is ClojureQL a good choice? Hasn't been updated in a while.

4:01 rata_: is there anyone from congomongo here?

4:02 hiredman: Zolrath: clojureql is not a postgresql library

4:02 you'll want the postgres jdbc driver

4:03 Zolrath: no? the site says it compiles to SQL92 so its compatable with MySQL and PostgreSQL

4:03 hiredman: right, it generates sql statements, which you have to ship off to an sql server

4:03 so nothing to do with postgres

4:04 Zolrath: ahhhh okay

4:04 hiredman: I recommend you just use clojure.java.jdbc together with the postgres jdbc driver

4:04 Zolrath: Realistically if theres a better option for another db I'd be open to that too

4:05 hiredman: nah

4:05 postgres is great

4:05 Zolrath: I was using congomongo but I realize for this project a normal relational database would be better

4:08 Blkt: good morning everyone

4:13 Zolrath: hiredman: Thanks for your help!

4:15 rata_: Zolrath: why did you realize a relational database would be better? did you need the expressive power of SQL?

4:17 Zolrath: rata_: Well maybe it's just my lack of knowledge of mongodb but I'm trying to make a project that loads entries via AJAX

4:17 rata_: ok

4:18 Zolrath: and the ids of mongodb dont really lend themselves to incrementing an id to get the next entry

4:20 rata_: I think there's a way to have "normal" autoincrementing ids in mongodb

4:20 Zolrath: I actually have the logic and data in mongodb already so that would be awesome if so

4:21 The only thing I saw seemed like it was something you'd have to run on the data every time there was a new entry, but I could have been interpreting it wrong

4:22 cark: it would take a lot for me to consider a nosql solution

4:22 there's so much you cannot do with those

4:23 and so little benefit

4:23 rata_: cark: speed is not a benefit for you?

4:23 Zolrath: http://shiflett.org/blog/2010/jul/auto-increment-with-mongodb <- this is the first google hit, but haven't read it enterily yet

4:24 cark: sur speed is good, but sql databases are already fast enough for me =P

4:24 sure*

4:24 what's your project ?

4:25 rata_: my project or Zolrath's?

4:25 cark: yours, what project do you need a nosql database's speed for ?

4:26 napping: is there a fancier version of cond?

4:26 rata_: napping: even fancier?

4:27 napping: letting you bind the true result, for one

4:27 cark: i have a project in production with several hundreds page views per second, postgres seems to be faring pretty good

4:27 and that's only the gui side of things

4:29 rata_: cark: I'm working on a project for which I don't know how much page views per second I'll have, but I think that the faster the db goes, the cheaper the server on which you have to run it

4:29 raek: napping: only if-let. (but that's for only one clause, of course) I think I once wrote a macro that looked like cond but expanded into nested if-let forms instead of if forms

4:29 napping: I might also have a use for one that makes if-not forms

4:29 cark: rata_: and you're ready to loose referencial integrity, and do the bookkeeping manually for this ?

4:30 it all depends on how you value your time

4:30 Zolrath: Am I correct in thinking that ids are the way to go for this auto-pagination type project? I was trying to think of a way to do it using the mongodb I already have but couldnt think of anything that made sense

4:31 cark: what do you mean by auto-pagination ?

4:31 rata_: cark: until now, it's a "query-only" db with weekly updates or so

4:32 cark: ah i guess for simple use cases it fits the bill

4:32 rata_: yes

4:33 Zolrath: I want to make it so when you go to the page it loads the most current entry and as you scroll down it loads the earlier entries

4:33 cark: tho project have a tendency to grow in complexity over time... then you're stuck with a nosql database

4:33 Zolrath: but if you go to a url with the direct link to a specific entry it would load that entry

4:33 and allow you to scroll up for newer entries

4:33 and down for older

4:34 cark: Zolrath: to me, autoincrement fields are only for identity

4:34 you need to have a date inserted field, then sort on that

4:34 Zolrath: I have a date field, hm

4:34 cark: and then the usual select * from x limit offset thing

4:35 or whatever the mongodb equivalent is

4:35 Zolrath: I've actually never done any ajax loading before so this whole thing is an adventure

4:35 cark: are you using jquery or maybe clojurescript ?

4:36 Zolrath: I'm trying this with clojurescript

4:37 cark: ahwell didn't give it a test run yet =/

4:37 Zolrath: I was going to attempt using pinot/goog.dom but I imagine it would be easier if I go with jquery and its horde of plugins?

4:37 rata_: Zolrath: in mongo it'd be db.collection.find().sort({date: 1}) or something like this

4:38 cark: no idea, i'm pretty sure clojurescript is up to the task

4:38 i always went the jquery route until now, next new project will probably be clojurescript

4:38 rata_: cark: if the project grows, I can leave this part as mongodb and use a relational database for the users part... this part is just public information I web-scrapped

4:39 Zolrath: I was trying to find an article out there that broke down how systems like this work so I could go at this with some knowledge

4:39 cark: rata_: ok =)

4:39 Zolrath: Right now I just have functions that will fetch an entry based on a fields value, or just all of them sorted by date

4:40 But I'm not really sure how to call that information from the clojurescript in reference to the data already loaded

4:40 cark: Zolrath: i recently converted an application to use a service based architecture in the spirit of wxhat you're doing

4:40 i have the web server producing json on different http requests

4:41 always encapsulated in the same message structure

4:41 then a single web page on the client side

4:41 which requests information from the correct url depending on what it needs

4:42 Zolrath: Hm, since I'm going Clojure/Clojurescript can I do the same idea via passing clojure maps between them?

4:42 cark: that's a full application with maybe 50 "pages" all collapsed in a single javascript file

4:42 that's what i would do

4:43 Zolrath: Right now I have all entries pass a normalized map with the same fields

4:43 cark: you may want to have something around that

4:43 so that you can pass errors etc

4:44 or go the rest way, and just rely on http status ... i didn't go that route

4:44 Zolrath: I hope to have it allow you to go to

4:45 localhost:8080/entry/09/23/2011 and have it load that entry

4:45 cark: hum a date is a single piece of data

4:45 Zolrath: then allow you to scroll up/down from there depending on if there are entries either way

4:45 cark: i would do localhost:8080/entry/09-23-2011

4:45 Zolrath: ah okay, that works

4:46 cark: woah the scroll up thing might prove difficult

4:46 but it would be neat if you make it =P

4:46 Zolrath: yeah I was trying to figure out how to get the previous/next entry in the db without ids

4:47 I can sort it by date, but how do I match that with where I am/what the next entry is

4:47 cark: well i don't know about mongodb

4:50 Zolrath: Thats why I was thinking about using an id field as I could go Hey Im on entry 32 try loading 31

4:52 I can't really reason a way to Say Hey I'm at 9-28-2011, lets sort by date, find all entries earlier than that entry, return the oldest?

4:52 Though I guess that way might work..

4:58 clgv: Zolrath: a timestamp can be a good id as well if your problem environment assures its uniqueness

4:58 cark: if you do not plan to delete much from the database i guess the id thing could work

4:59 but that's forcing one database request per item

4:59 Zolrath: yeah each entry will have a unique timestamp

4:59 cark: maybe more than one, if there are some deleted items

5:01 Zolrath: cark: Hm, would something like finding the first 5 entries with dates later than the current one be a better option then?

5:01 cark: would be so easy with sql : item = select from table where date = x, page before = where date < item order by date desc, page after : where date > item order by date

5:02 Zolrath: To be honest I still have research to do as how the actual ajax calls happen

5:02 cark: Zolrath: sure you want to batch as much as possible, from the database, through your application, via ajax

5:03 Zolrath: how it actually passes what the oldest/newest entries loaded so far are to the query

5:03 cark: you don't want to get too chatty when coping with internet latencies

5:04 Zolrath: well you can start by passing test data, see how the ajax stuff works

5:04 my first ajax call was requesting a string that said "hello"

5:05 on this last project i was talking about =)

5:08 Zolrath: haha yeah I so far had it pull the title from the first entry

5:08 in the database

5:08 and that works

5:08 cark: =)

5:09 Zolrath: But I have no idea how to bind calling more entries to screen position or anything like that

5:10 especially based on information contained within the entry pulled

5:14 I'll make trying to get something based on the last entry the next challenge, before really figuring out how to tie that into the screen position

5:21 cark: Thanks for all your input! I'll hopefully be able to show you something "working" soon!

5:22 cark: hehe great =)

6:11 shtutgart: Clojurescript newbie: I've created the script as described here (https://github.com/clojure/clojurescript/wiki/Emacs-%26-inferior-lisp-mode) and started it. I can see the prompt, but after sending some input repl hangs forever: http://dpaste.org/1nY07/

6:20 robermann: hello, maybe I'm missing something: this (http://pastebin.com/PVZqGLdb) is my partial resolution of a 4clojure problem (http://4clojure.com/problem/118). My problem is that it seems I'm not able to write a lazy recur/loop, not even using lazy-seq. Am I missing any fundamental concept?

6:21 my resolution works for the first two problems, but the third goes on and on in timeout

6:21 clgv: robermann: loop-rcur is not lazy

6:21 robermann: ah ok

6:22 clgv: robermann: you might use lazy-seq as standalone

6:25 robermann: http://pastebin.com/KSbXE48c

6:26 robermann: thanks, but before check it I'll try to resolve it by my own. I was checking http://clojure.org/special_forms#recur , but I cannot find where it say itsn't lazy. How could I infer that a form is not "lazy-able"?

6:27 clgv: robermann: "(almost) only lazy-seq is lazy"

6:28 robermann: I thought that (recur (next col) (lazy-seq (conj res (f cur)))))))) would recur in a lazy loop

6:28 clgv: loop-recur: is just a form to enable tail-recursion

6:28 clojure's function calls are not lazy evaluated

6:28 only lazy sequences are

6:28 robermann: mmm correct

6:29 now makes more sense :)

6:29 thank you

6:29 clgv: let me rephrase: loop-recur is a form to enable optimized tail-recursion

6:30 robermann: and works as a function call, evaluating immediately

6:30 clgv: yes. it does

6:30 robermann: ok

6:31 Chousuke: you need to use regular recursion when you create lazy seqs, not recur

6:32 then just wrap the recursive function call in a lazy-seq form

6:32 you can't do that with recur because it's not the tail position, but due to the laziness there is no stack growth issue

6:32 clgv: does the 4clojure problem list grow over time?

6:33 Chousuke: by the time the thunk gets evaluated, the original function call has returned.

6:35 robermann: Chousuke: are you referring to clgv's solution right?

6:35 Blafasel: Trying to put a clojure environment on most of my machines here: How do you suggest doing that? For example, my fedora here packages 1.2.1. Would you use that or go with the .jar? Is there something like rvm or a tool of sorts to keep my environment current?

6:36 clgv: robermann: I guess he didnt read it, since he describes it ;)

6:36 Chousuke: robermann: yes.

6:36 clgv: ok, my error

6:37 Chousuke: I think you can actually do (cons (f (first coll)) (lazy-seq (my-sad-map (rest coll)))) too

6:39 clgv: you forgot an f^^ otherwise you have to have another (possible anonymous) closure with f

6:40 Chousuke: right

6:40 I think that implementation of map will always force the evaluation of the first element of the seq though :/ because (when (seq coll) ...) is outside the lazy-seq form

6:42 clgv: Chousuke: yeah I thought about moving it into lazy-seq. but to demonstrate lazy-seq it also works^^

7:00 robermann: clgv or Chousuke: could I use "next" instead of "rest"?

7:00 clgv: why?

7:00 clojurebot: http://clojure.org/rationale

7:01 robermann: ah ok, I found "rest versus next" on your book :)

7:02 (to be honest I read it, but just I forgot all those useful informations)

8:04 chrido: hi, does anybody know how to get syntax-highlightning with *.cljs files in LaClojure/IntelliJ?

8:31 fdaoud: ,(let [teams (range 1 9)] (map list (take 4 teams) (reverse (drop 4 teams))))

8:31 clojurebot: ((1 8) (2 7) (3 6) (4 5))

8:31 fdaoud: better way to do that?

8:35 nachtalp: fdaoud: you don't need to use drop

8:35 fdaoud: ,(let [teams (range 1 9)] (map list (take 4 teams) (reverse teams)))

8:35 clojurebot: ((1 8) (2 7) (3 6) (4 5))

8:36 fdaoud: nachtalp: like that?

8:36 nachtalp: ,(let [teams (range 1 9)] (take 4 (map list teams (reverse teams))))

8:36 clojurebot: ((1 8) (2 7) (3 6) (4 5))

8:36 nachtalp: or like that

8:37 fdaoud: ah, I like yours better

8:37 nachtalp: fdaoud: reverse is not lazy, however...

8:38 fdaoud: nachtalp: yeah I was wondering about that..

8:39 nachtalp: thanks

8:39 nachtalp: fdaoud: glad to help :)

8:40 fdaoud: nachtalp: appreciate it.. one more question?

8:40 nachtalp: fdaoud: sure

8:40 fdaoud: how do you flatten by one level only?

8:41 have [ [ [1 8] [2 7] [3 6] [4 5] ] [ [9 16] [10 15] [11 14] [12 13] ] ]

8:41 want [ [1 8] [2 7] [3 6] [4 5] ] [ [9 16] [10 15] [11 14] [12 13] ]

8:41 sorry

8:41 want [ [1 8] [2 7] [3 6] [4 5] [9 16] [10 15] [11 14] [12 13] ]

8:42 clgv: fdaoud: apply concat

8:42 nachtalp: ,(reduce concat [ [ [1 8] [2 7] [3 6] [4 5] ] [ [9 16] [10 15] [11 14] [12 13] ] ])

8:42 clojurebot: ([1 8] [2 7] [3 6] [4 5] [9 16] ...)

8:43 clgv: or you use mapcat when generating those two lists via map

8:43 nachtalp: apply makes more sense

8:46 fdaoud: clgv: mapcat does the trick :)

8:46 thank you both!

8:47 so much nicer than a ton of Java code..

8:52 clgv: fdoud: I guess you can skip the reverse by a clever use of partition and map

8:56 fdaoud: clgv: ?

8:57 clgv: fdaoud: with the following you get pairs of the ranges you want to combine: ##(->> (range 16) (map inc) (partition 4) (partition 2))

8:57 lazybot: ⇒ (((1 2 3 4) (5 6 7 8)) ((9 10 11 12) (13 14 15 16)))

8:58 clgv: it shouldnt be that hard to continue from that to your goal

9:01 fdaoud: clgv: ok but I don't see how that skips the reverse?

9:02 clgv: fdaoud: right, I expressed that wrong - you only have to reverse what you actually use

9:02 fdaoud: clgv: ah, I understand