#clojure log - May 10 2009

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

0:04 gcv: ah -- the swank-clojure-find-package looks suspicious

0:28 ataggart: how do I create a "block" for an if? e,g. (if predicate then-do-a-bunch-of-stuff)

0:28 make it a separate function?

0:30 aha, just below the documentation for if

0:30 (do ...)

1:39 gcv: wow, figured it out... the answer is to start swank-clojure before opening up a .clj source file.

1:40 swank-clojure-slime-mode-hook in swank-clojure.el uses (set (make-local-variable ...)) to define the way to figure out the current package. If a buffer already has a .clj file open, then this hook does not run, and so slime tries to figure out the current namespace using a Common Lisp regexp.

1:47 actually correction. the hook does run, but if slime isn't running, slime-find-buffer-package-function is unbound, and so it never gets set for when slime loads.

2:36 cads: hi, in clojure.set, I'm trying to do (defn subset? ... ([s1 s2 & sets] (let [bubbled-sets (bubble-max-key count (conj sets s2 s1))] (apply and (map subset? bubbled-sets (rest bubbled-sets)))))))

2:37 it compiles okay

2:38 hiredman: erm

2:38 cads: I've omitted the code for the other argument cases here

2:38 but when I try to start clojure, I get an error

2:38 hiredman: ,^and

2:38 clojurebot: java.lang.Exception: Can't take value of a macro: #'clojure.core/and

2:38 hiredman: you cannot apply a macro

2:38 cads: Caused by: java.lang.Exception: Can't take value of a macro: #'clojure.core/and

2:38 yea

2:38 hiredman: (reduce #(and % %2) ...)

2:39 replaca: unless you use stuart's "secret

2:39 " apply macro function

2:39 hiredman: replaca: ick

2:39 replaca: :-)

2:39 cmvkk: shouldn't there be a non-macro function that does the same thing as and?

2:40 replaca: that's why it's secret

2:43 cads: why's and a macro

2:43 cmvkk: so that it can short circuit.

2:43 so that if one argument returns false, the remaining arguments won't be evaluated at all.

2:43 cads: yeah but then you can't and a list of truth values?

2:43 hiredman: ,(and nil (println :foo))

2:43 clojurebot: nil

2:43 hiredman: sure you can, just use reduce

2:43 cmvkk: so where's the 'every' function, that's what I want to know.

2:43 we have 'some'

2:43 cads: can I get short circuiting with something like reduce?

2:43 hiredman: ...

2:43 cads: am I going to have to use a maybe monad? :D

2:43 _mst: ,^every?

2:43 clojurebot: nil

2:43 replaca: cads: no, but it's not too hard to write a version that does something like that

2:43 hiredman: ,(doc every?)

2:43 clojurebot: "([pred coll]); Returns true if (pred x) is logical true for every x in coll, else false."

2:43 _mst: hurrah :)

2:43 cads: it's a special case of reduce that passes a logical value, anyways

2:43 ah

2:43 hiredman: ^ is reader syntax for (meta ...)

2:43 cmvkk: hmm

2:43 _mst: ah, yes. I'd mistaken it for magic bot syntax :)

2:43 cmvkk: i guess (every? identity ...) is mostly the same as (apply and ...) when you don't care about short circuiting.

2:43 hiredman: ~def every?

2:44 there is no reason every? couldn't short circuit, and it may well do so

2:44 _mst: there's also (not-any? pred col) which presumably short-circuits...

2:45 cmvkk: hmm that's true.

2:45 actually, if you passed it a lazy-seq I bet it would.

2:45 hiredman: uh

2:45 I guess it does short circuit

2:45 cmvkk: well then.

2:46 hiredman: ~botsnack

2:46 clojurebot: thanks; that was delicious. (nom nom nom)

2:46 cads: how do I print out the source code of a public function?

2:46 hiredman: ~def source

2:46 better check to if that worked, crontrib source lookup is new

2:47 cmvkk: seems to have worked.

2:47 cads: ,(source 'every?)

2:47 clojurebot: java.lang.Exception: Unable to resolve symbol: source in this context

2:47 durka42: don't quote the function name

2:47 it's in clojure.contrib.rep-utils

2:47 and clojurebot won't do it because he won't do IO

2:47 cads: ,(do (use 'clojure.contrib.repl-utilities) (source every?))

2:47 clojurebot: java.lang.Exception: Unable to resolve symbol: source in this context

2:47 cads: ok

2:48 hiredman: cads: clojurebot just sent a url leading to the source of every?

2:48 just click on it

2:50 cads: ~def every?

2:51 that short circuits even with the recur there, right?

2:52 hiredman: yes

2:52 because and is like do, but it stops if something is false or nil

3:09 djkthx: is there a way to get read-line to work properly in the slime repl?

3:09 when i use it in slime, it never stops accepting input

3:11 hiredman: ,(doc read-line)

3:11 clojurebot: "([]); Reads the next line from stream that is the current value of *in* ."

5:33 cads: I'd like to contribute some functions to clojure.set, are there existing tests and stuff I could add to?

5:34 kotarak: cads: tests (if there are any) are probably in contrib in test_clojure

5:35 hiredman: make sure you get a CA in

5:43 cads: what's CA?

5:44 I'm thinking cellular automaton :)

5:47 hiredman: contributor agreement

5:47 http://clojure.org/contributing

9:09 jal648: greetings all, I'm hoping to demo a bit of clojure at my work tomorrow, and I was going to use the ants.clj demo.

9:10 I have a quad core machine, and was hoping I could show all the cpu's being used. My question is, should I expect to see all four used when I'm running the ants demo?

9:10 Chouser: yes

9:10 jal648: Hmm, it did not seem to...

9:11 I launched the code through the REPL, that shouldn't matter though right?

9:11 Chouser: right

9:12 I haven't actually tried on a 4-core. Now that I have one, I should try it... just a sec.

9:14 hm, that's hardly using any CPU at all

9:16 jal648: I was wondering if perhaps the demo is out of date.

9:16 Chouser: seems likely, but I would expect that to cause an error, not just a low CPU usage.

9:17 I think there may just be insufficient work to keep all my cores busy.

9:17 jal648: I haven't been paying as much attention to the community the last few months, do you know if there's a different example out there that shows off the concurrent stuff?

9:19 maybe I'll just try increasing the number of ants...

9:27 Chouser: yeah, using 8 for nants-sqrt helps, as does changing ant-sleep-ms to 10

9:27 but it's still not pegging all 4 cpus

9:28 each of the 4 are averaging 40% for me

9:30 jal648: I did 20 nants-sqrt and made the dimensions 120, I'm showing around 220% cpu usage which is enough for the demo I think

9:30 Chouser: so they're all being used, just not fully

9:31 ok

9:31 jal648: yeah thanks for the help!

11:44 durka42: whoops

11:45 contrib.javalog doesn't compile

11:45 [java] java.lang.NoSuchFieldException: GLOBAL_LOGGER_NAME (javalog.clj:49)

11:46 oh, java 6

11:46 my bad

11:46 there should be a warning about that somewhere more obvious than the top of javalog.clj

11:48 and i am using java 6...

11:56 sorry about the noise

11:56 apparently ant ignores the settings in Java Preferences and reads $JAVA_HOME instead

12:09 eee: hi

12:10 I'm trying to get intuition as to when to do things with java calls? My guess is that when you can't find it in the API, you can use contrib or the java way.

12:10 for example

12:11 seems like an obvious thing to want to test a set for "hasKey" (python)

12:11 do you just use .contains ?

12:11 i know someone wrote "includes?" in the contrib

12:12 i just wanna check membership and I can't find the answer easily on the web

12:15 i guess it's "(contains?)

12:15 ,(contains? #{'3} '3)

12:15 clojurebot: true

12:16 eee: ,(.contains #{'3} '3)

12:16 clojurebot: true

12:16 eee: so there are two ways that work

12:16 at least

12:17 ,(contains? '(3) 3)

12:17 clojurebot: false

12:17 eee: ,(contains? '(3) '3)

12:17 clojurebot: false

12:17 eee: ,(contains? ('3) '3)

12:17 clojurebot: java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn

12:17 eee: ,(contains? '('3) '3)

12:17 clojurebot: false

12:18 eee: ,(contains? '("3") "3")

12:18 clojurebot: false

12:18 eee: ,(.contains '("3") "3")

12:18 clojurebot: true

12:19 eee: ??? so the clojure way doesn't always work?

12:19 liebke: ,(doc contains?)

12:19 clojurebot: "([coll key]); Returns true if key is present in the given collection, otherwise returns false. Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the range of indexes. 'contains?' operates constant or logarithmic time; it will not perform a linear search for a value. See also 'some'."

12:20 eee: ,(doc some)

12:20 clojurebot: "([pred coll]); Returns the first logical true value of (pred x) for any x in coll, else nil. One common idiom is to use a set as pred, for example this will return true if :fred is in the sequence, otherwise nil: (some #{:fred} coll)"

12:20 liebke: eee: Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the range of indexes

12:20 that's the problem you were having

12:21 eee: so what's the most generic way to find membership

12:21 in clojure

12:21 for any collection

12:23 that defn of contains seems out of whack with java's .contains

12:23 liebke: most generic way? I'm not sure, but you can use some: (some #(= 3 %) [4 5 3])

12:24 eee: well, it seems like the java method works

12:24 ,(.contains '("3") "3")

12:24 clojurebot: true

12:24 eee: ,(some '("3") "3")

12:24 clojurebot: java.lang.ClassCastException

12:24 eee: oh it needs a function

12:24 i see

12:25 liebke: I think the most generic way to do it, is .contains. It's alright to use java in clojure after all :)

12:25 eee: to me, it's all right for esoteric stuff. for fundamental, primitive stuff, it seems wacky

12:26 because you waste time looking

12:26 like in lisp . . .i think there was "member?"

12:26 or something

12:26 (pmember

12:26 liebke: that's why clojure uses java types, so you can use java transparently

12:27 eee: i see

12:27 so that'sa requirement on new collections if people were to write them

12:27 must implement collection interface

12:28 so I can count on this: http://java.sun.com/docs/books/tutorial/collections/interfaces/collection.html

12:29 ,(doc do)

12:29 clojurebot: java.lang.Exception: Unable to resolve var: do in this context

12:30 eee: what happened to do?

12:30 ,(doc doall)

12:30 clojurebot: "([coll] [n coll]); When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. doall can be used to force any effects. Walks through the successive nexts of the seq, retains the head and returns it, thus causing the entire seq to reside in memory at one time."

12:31 eee: ,(doc do)

12:31 clojurebot: java.lang.Exception: Unable to resolve var: do in this context

12:32 chrizel: maybe because do is a special form?

12:32 ,(doc let)

12:32 clojurebot: "([bindings & body]); Evaluates the exprs in a lexical context in which the symbols in the binding-forms are bound to their respective init-exprs or parts therein."

12:32 chrizel: ok O_o

12:33 eee: so (do) returns the last thing it doesn, right

12:33 ??

12:33 chrizel: ,(doc if)

12:33 clojurebot: "([tst & etc]); "

12:33 eee: that's what I was checking

12:33 chrizel: yes, do is for side effects

12:33 like progn in common lisp or begin in scheme

12:34 eee: now that's cool. I wish you were the docs

12:34 then I learn three languages at once!

12:34 chrizel: :-D

12:50 eee: do redefinitions take a long time? I know they are not idiomatic ... but like (def foo (conj foo blah))

13:00 (doseq i ,'(["a" "b"]) (print i))

13:00 ,(doseq i ,'(["a" "b"]) (print i))

13:00 clojurebot: java.lang.IllegalArgumentException: doseq requires a vector for its binding

13:00 eee: ,(doseq i ,(vec '(["a" "b"]) (print i)))

13:00 clojurebot: java.lang.IllegalArgumentException: doseq requires a vector for its binding

13:00 eee: why that not work?

13:00 i made it a vec

13:02 Chouser: ,(doseq [i ["a" "b"]] (print i))

13:02 clojurebot: ab

13:02 eee: oh, it changed so that the i goes inside a vec

13:02 Chouser: yes

13:03 eee: ,(doseq [i ,'(["a" "b"])] (print i))

13:03 clojurebot: [a b]

13:03 eee: someone's docs are old

13:03 on the web

13:04 does that mean you can have as many bindings and seqs as you want?

13:04 well then you'd have to decide

13:04 what to do when lengths were different

13:06 Chouser: yes, it acts like 'for'

13:06 nested.

13:06 eee: ,(doc for)

13:06 clojurebot: "([seq-exprs body-expr]); List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero or more modifiers, and yields a lazy sequence of evaluations of expr. Collections are iterated in a nested fashion, rightmost fastest, and nested coll-exprs can refer to bindings created in prior binding-forms. Supported modifiers are: :let [binding-form expr ...], :while test, :when test.

13:06 Chouser: (doseq [a [1 2 3] b [4 5 6]] (prn [a b]))

13:06 ,(doseq [a [1 2 3] b [4 5 6]] (prn [a b]))

13:06 clojurebot: [1 4] [1 5] [1 6] [2 4] [2 5] [2 6] [3 4] [3 5] [3 6]

13:07 eee: oh ok

13:07 woah

13:07 Chouser: it's got all the other 'for' features too. :while, :when, etc.

13:07 eee: ,(doc prn)

13:07 clojurebot: "([& more]); Same as pr followed by (newline). Observes *flush-on-newline*"

13:07 eee: ,(doc pr)

13:07 clojurebot: "([] [x] [x & more]); Prints the object(s) to the output stream that is the current value of *out*. Prints the object(s), separated by spaces if there is more than one. By default, pr and prn print in a way that objects can be read by the reader"

13:08 eee: i didn't know println was the long way

13:08 either

13:08 Chouser: well, it does different things

13:08 ,(println "hello")

13:08 clojurebot: hello

13:08 Chouser: ,(prn "hello")

13:08 clojurebot: "hello"

13:09 eee: i like the latter

13:09 for what i'm doing

13:09 Chouser: ok

13:09 eee: would have avoided confusion for me

13:09 (,prn ,'(["a"]))

13:09 ,(prn ,'(["a"]))

13:09 clojurebot: (["a"])

13:09 eee: ,(println ,'(["a"]))

13:09 clojurebot: ([a])

13:09 eee: yup

13:10 ,(println ,'(["1"]))

13:10 clojurebot: ([1])

13:10 eee: at one point I forgot my numbers were strings

13:11 Chouser: ah sure

13:12 eee: so the 15-puzzle solver works now, but one ugly thing is that I have a global hash-set that I redefine everytime I insert something new into it. I know that's not idiomatic ... and at the very least it needs to be scoped to the file

13:17 lisppaste8: eee pasted "i need a let binding, right?" at http://paste.lisp.org/display/79986

13:26 eee: how do you make a closure that modifies what was originally (let)?

13:26 so everytime it's called the let binding changes?

13:28 Chouser: let locals are immutable

13:29 eee: so here's what i've got now: http://paste.lisp.org/display/79986 . . . which I was gonna make with an outer (let), instead.

13:29 Chouser: if you're holding onto state and you want to be able to update it, you need a Clojure reference type: ver, ref, agen, or atom

13:29 agent

13:29 eee: since nothing else uses "ALREADY-TRIED"

13:29 i see

13:30 Chouser: the simplest, but not necessarily most correct, would be an atom

13:30 (def already-tried (atom (hash-set)))

13:30 eee: or another hack (with-local-cars)

13:30 Chouser: then when you want to conj something onto it, (swap! already-tried conj new-state)

13:31 eee: cool

13:31 i can do a clojure with an atom, I bet

13:31 (let already-tried

13:31 oops

13:31 Chouser: if you don't want it to be global, perhaps the atom should be passed into each fn

13:31 or right, a closure

13:32 eee: (let [already-tried (atom (hash-set))] (defn sdsdfgsdfg ...

13:33 so because it's an atom, do I want that in a synchronous section?

13:33 dosync

13:33 or something?

13:33 leafw: eee: atoms are AtomicObject, so no need. The are synchronized in themselves.

13:33 s/The/They

13:34 eee: nice

13:34 hense the name

13:35 leafw: I think internally it uses this: http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/atomic/AtomicReference.html

13:35 eee: ,(doc swap!)

13:35 clojurebot: "([atom f] [atom f x] [atom f x y] [atom f x y & args]); Atomically swaps the value of atom to be: (apply f current-value-of-atom args). Note that f may be called multiple times, and thus should be free of side effects. Returns the value that was swapped in."

13:37 Chouser: eee: if the state of already-tried will ever need to be synchronized with any other state, then 'atom' is the wrong choice.

13:37 eee: then you gotta use @ or something to get the thing the atom holds

13:37 right

13:37 ok Chouser, thanks

13:38 i'll start learning about the concurrency model a few projects later . . . that's the ultimate goal. to implement a few basic things to demonstrate the heap . . . branch and bound being the last, and then parallel branch about bound

14:02 Raynes: You wouldn't believe how many adolescents that I've got interested in functional programming so far.

14:02 durka42: really

14:03 that seems like a difficult task

14:03 eee: they are teaching scheme to kids at brown

14:03 as a community project

14:10 __mac: Define community project

14:11 I'm from sweden, I'm stupid with regards to english and american culture sometimes...

14:12 Is that like something the student's take part in if they want to but the teachers are doing the teaching?

14:13 * durka42 wonders if that was due to my complaining

14:16 eee: well i was being vague so as not to misspeak

14:17 but I believe it is for kids in cities that may not get the same chances as others

14:17 so it wasn't for the students going to college at brown

14:17 and what I meant was that it wasn't "for profit"

14:18 __mac: Ah I see

14:18 eee: at any rate, it turns out, the kids enjoyed it a lot and got to the point where they were inspired to learn more math

14:18 __mac: cool

14:18 eee: one thesis being that functional programming encourages learning more math

14:19 __mac: Yeah I can beleive that, pure functions and all that sure feels closer to math than imperative programming

14:19 So if you like functional programming, maybe you figure that math isn't that hard/bad after all

14:22 What about the students at Brown then? They study any lisp? I think we got maybe 2 universities in Sweden that teach any lisp at all. I just got a lot of C, C++ and later Java in uni and when I started learing lisp I felt I got a little cheated back in school

14:22 There is this whole world of programming we were never told about

14:23 eee: they are stating freshman with scheme now

14:23 intro course to programming

14:23 and the students will have their own android phone

14:23 and learn to write apps in some DrScheme dialect

14:23 written for android

14:23 like MobyScheme or something

14:24 i'm signin' off for now. nice shattin

14:24 chattin

14:24 i mean

14:24 lol

15:29 cads_: hey, I need some help with my clojure classpath, and getting cloggle to work

15:29 cloggle's on my classpath, but when I try to load it it says that it can't find some java lib

15:30 durka42: which java lib?

15:30 cads_: it throws "ClassNotFoundException: javax.media.opengl.GLCanva"

15:30 durka42: that looks like a typo

15:32 Canva => Canvas

15:32 dnolen: cads_: are you using slime? and did you already install JOGL?

15:32 lisppaste8: cads pasted "clojure error" at http://paste.lisp.org/display/79992

15:33 cads_: I've installed libjogl-java through apt

15:33 dnolen: but what environment are yo using, vimclojure, slime, netbeans?

15:34 cads_: just the shell

15:34 the first part is my classpath string

15:34 which probably doesn't need to be so long

15:34 dnolen: you need to tell java where the OS specific dynamic library is, not just the jars.

15:35 on Linux they are the .so files

15:36 -Djava.library.path= your library path

15:36 cads_: hmm

15:36 dnolen: needs to be passed to java when you start the REPL

15:36 in addition to setting the classpath to the jars.

15:37 cads_: let me find the so files

15:37 that doesn't seem right, there are no .so files

15:37 dnolen: are you on Linux?

15:38 cads_: yes

15:38 dnolen: then there are most definitely .so files.

15:38 libjogl.so

15:38 libjogl_*.so

15:38 and

15:38 libgluegen-rt.so

15:39 cads_: the jogl package is essentially /usr/share/java/jogl.jar and libgluegen, and some documentation, but no so.. does it get generated somewhere outside the package?

15:39 Im in ubunt :D

15:40 dnolen: look in

15:40 do you have a

15:40 directory?

15:40 sorry

15:40 /usr/lib/java

15:40 ?

15:40 durka42: http://packages.ubuntu.com/jaunty/all/libjogl-java/filelist

15:41 he's right there are no .so's in that package

15:41 ah but ti depends on libjogl-jni http://packages.ubuntu.com/jaunty/i386/libjogl-jni/filelist

15:42 which puts them in /usr/lib/jni

15:42 dnolen: there you go.

15:43 anyways, you need to pass that path to the REPL via the -Djava.library.path flag

15:45 cads_: aah

16:44 cads: I'm trying to use this to run the cloggle example: java -Djava.library.path /usr/lib/jni/*.so -cp /usr/share/java/jogl.jar:$CLJ/clojure/clojure.jar:$CLJ/clojure-contrib/clojure-contrib.jar:$CLJ/ns clojure.lang.Script $CLJ/ns/cloggle/examples/gears.clj

16:45 hiredman: that will not work

16:45 /usr/lib/jni/*.so will expand into a space delimited list of libraries

16:46 which I doubt java is looking for

16:46 dnolen: -Djava.library.path /usr/lib/jni should be sufficient.

16:51 cads: I don't get it, it acts as if that flag is supposed to be giving it classes instead of .so files

16:51 hiredman: ...

16:51 13:45 hiredman : /usr/lib/jni/*.so will expand into a space delimited list of libraries

16:51 13:45 hiredman : which I doubt java is looking for

16:52 durka42: i think the JVM recurses down java.library.path looking for stuff

16:52 if you want to give it a list you will need to delimit with colons

16:54 cads: http://pastie.org/473915

16:54 durka42: -Djava.library.path=/usr/lib/jni

16:55 hiredman: cads: pay attention to what I am saying

16:55 I just told you what is happening

16:55 twice

16:56 durka42: hiredman: no that wasn't the problem

16:57 hiredman: durka42: it obviously is

16:57 oh

16:57 actually you are missing a =

16:57 :P

16:57 cads: d'oh

16:58 dnolen: sorry probably my fault :)

17:02 cads: awesome

17:02 http://pastie.org/473927

17:02 now we're only missing something in the namespace :)

17:02 dnolen: i talked about this on the list

17:02 his library is not structured properly

17:02 you need to create the folders to match his ns

17:02 cads: oh no!

17:02 oh, well..

17:02 that's not too bad

17:13 I created the directory structure and it's no longer complaining about not finding the clj file, but now it throws Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/gluegen/runtime/DynamicLookupHelper (gears.clj:0)

17:13 http://rafb.net/p/M25lKP42.html

17:14 dnolen: typo

17:14 ]/usr/share/jave/gluegen-rt.jar

17:14 java not javve

17:14 jave :)

18:02 thearthur: is #enclojure the best place to ask about the netbeans clojure plugin?

18:20 unlink1: What's the best way to transform a sequence into ((0 <first element>) (1 <second element>) (2 ...) ...) ?

18:20 i.e. am I missing some builtin for this?

18:21 dnolen: clojure.contrib.seq-utils has an indexed

18:21 ,(indexed "test")

18:21 clojurebot: java.lang.Exception: Unable to resolve symbol: indexed in this context

18:22 AWizzArd: the clojurebot has not (use'ed ..) that

18:22 unlink1: Ok, that's exactly what I wanted. Thanks.

18:23 Seemed silly to do that by hand.

18:24 I should really just grep on the clojure-contrib source more.

19:06 I have (ns ... (:gen-class)), (defn -main [] ...), and classes/my_ns$_main__23.class, but I'm still getting "Could not find the main class".

19:09 cmvkk: i think you have to recognize the fact that there's a main function in the :gen-class form somewhow

19:09 actually, on second glance maybe that's not the case.

20:04 bradford: any masters of the way of the monad on?

20:05 I want to make a monad around this: (defn mean-state

20:05 ([x val queue] [(/ (- (+ val x) (peek queue)) (count queue)) (conj (pop queue) x)])

20:05 ([x] [x (conj clojure.lang.PersistentQueue/EMPTY x)]))

20:06 it is a stateful statistic, such as a rolling mean of the last 100 values

20:19 unlink: I'm running into a stateful parsing problem too.

20:21 How would you write a function parse-lines such that: http://dpaste.com/42824/

20:25 durka42: hmm is there even a lazy string split

20:52 unlink: you hooked me :) almost got something

20:54 Clojure=> (parse-lines "positive\n3\n2\n6\nnegative\n1\npositive\n8\n4\n5\nnegative\n12\n5\n9")

20:54 (3 2 6 -1 8 4 5 -12 -5 -9)

20:56 unlink: hmm

20:58 durka42: i started by writing lazy-split

20:59 wrapped in lazy-seq, it looks for the delimiter, and returns (list s) if it's not there, and (cons string-up-to-delimiter (lazy-split rest-of-the-string delim)) if it is

21:02 unlink: What are you lazily splitting on?

21:10 durka42: \newline

21:10 sorry, i walked away

21:10 (.indexOf s (int \newline))

21:11 <rant>why in the world does String.indexOf take an INTEGER?</rang>

21:12 unlink: durka42: I was trying to write a state-machine parser

21:13 durka42: Then I realized my states actually simply repeat in a clojure.core/cycle

21:14 durka42: parsing the string or a list of lines?

21:14 unlink: list of lines

21:23 durka42: so the states are positive and negative

21:23 encountering the opposite word switches the state

21:25 unlink: my version sort of has a state machine, i suppose - apply-signs just does a condp, and calls itself with the current sign

21:27 unlink: oh

21:27 can you paste it?

21:28 durka42: yeah hold on

21:30 lisppaste8: durka42 pasted "parse-lines" at http://paste.lisp.org/display/80001

22:41 unlink: durka42: here was my solution to a related problem: http://dpaste.com/42845/

22:43 * durka42 likes (let [n+1 (+ n 1)]) :)

22:44 unlink: I just learned how to use condp, you don't actually need the first "line" before the second let

22:44 So anyway I consider that horribly gross.

22:45 Indexing into the lines? recur 4 times? ugh...

22:49 eee: ~log

22:49 clojurebot: logs is http://clojure-log.n01se.net/

23:21 unlink: durka42: I've produced a somewhat less horrific version of the same

23:21 durka42: :)

23:22 unlink1: http://dpaste.com/42853/

23:25 I wonder if there's some way I could write that with reduce

23:27 Chouser: seems likely

23:27 durka42: it seems like you'd need to reduce tuples

23:27 of an accumulator and a state

23:28 unlink1: right

23:28 durka42: this is starting to sound like a monad :)

23:28 unlink1: haha

23:28 yes

23:29 ooh, I like destructuring seqs with [x & xs]

23:29 durka42: or you could use a closed-over atom or something

23:32 lisppaste8: Chouser pasted "unlink1's fold-lines, with reduce" at http://paste.lisp.org/display/80007

23:33 unlink1: dammit, I shouldn't have clicked

23:33 Chouser: sorry, I almost warned you

23:33 but I figured if you didn't want to see it, you wouldn't click. :-/

23:33 unlink1: or rather, once clicking, I shouldn't have studied your solution ;)

23:34 Chouser: It's like algebra. kind of relaxing.

23:34 I don't even know what you're doing, or trying to do.

23:35 lisppaste8: unlink1 annotated #80007 "final contribution before bedtime" at http://paste.lisp.org/display/80007#1

23:36 unlink1: Chouser: actually this is a reduced version of the larger problem

23:36 but the larger problem essentially composes into this one

23:37 Chouser: if you add a loop in there, then you wouldn't have to pass f around all the time.

23:37 matter of taste, I suppose.

23:37 unlink1: that's true

23:38 but in this case I find the loop to be a little noisy

23:38 Chouser: sure

23:38 unlink1: in principle I agree

23:40 Chouser: fwiw, recur allows for the possibility of primitives, while reduce does not. Dunno if that's likely to matter in a case like this.

23:55 cads: chouser, I have a real bad bad desire to change the clojure convention to match the classical mathematical convention in the case of sets, where I really want to see {& elems} for a set rather than #{& elems}. Can I switch them out in my personal code?

23:56 will I have to dive into the clojure implementation?

23:56 cmvkk: you want to change the set literal syntax from #{} to {}?

23:57 cads: yeah, but only in my personal files, it should still read normal clojure code

23:57 cmvkk: unfortunately reader syntax is inaccessable from clojure itself.

23:57 you'd have to change java code to make that happen. plus, what would you make map syntax be?

23:58 since {:a 1 :b 2} is currently a map.

23:58 clojurebot: map is *LAZY*

23:58 cads: should I awk it?

23:58 cmvkk: what do you mean?

23:58 to find where that code is? it's in Reader.java i'm pretty sure.

23:59 or to change your own source code?

Logging service provided by n01se.net