#clojure logs

2009-05-10

00:04gcvah -- the swank-clojure-find-package looks suspicious
00:28ataggarthow do I create a "block" for an if? e,g. (if predicate then-do-a-bunch-of-stuff)
00:28ataggartmake it a separate function?
00:30ataggartaha, just below the documentation for if
00:30ataggart(do ...)
01:39gcvwow, figured it out... the answer is to start swank-clojure before opening up a .clj source file.
01:40gcvswank-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.
01:47gcvactually 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.
02:36cadshi, 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)))))))
02:37cadsit compiles okay
02:38hiredmanerm
02:38cadsI've omitted the code for the other argument cases here
02:38cadsbut when I try to start clojure, I get an error
02:38hiredman,^and
02:38clojurebotjava.lang.Exception: Can't take value of a macro: #'clojure.core/and
02:38hiredmanyou cannot apply a macro
02:38cadsCaused by: java.lang.Exception: Can't take value of a macro: #'clojure.core/and
02:38cadsyea
02:38hiredman(reduce #(and % %2) ...)
02:39replacaunless you use stuart's "secret
02:39replaca" apply macro function
02:39hiredmanreplaca: ick
02:39replaca:-)
02:39cmvkkshouldn't there be a non-macro function that does the same thing as and?
02:40replacathat's why it's secret
02:43cadswhy's and a macro
02:43cmvkkso that it can short circuit.
02:43cmvkkso that if one argument returns false, the remaining arguments won't be evaluated at all.
02:43cadsyeah but then you can't and a list of truth values?
02:43hiredman,(and nil (println :foo))
02:43clojurebotnil
02:43hiredmansure you can, just use reduce
02:43cmvkkso where's the 'every' function, that's what I want to know.
02:43cmvkkwe have 'some'
02:43cadscan I get short circuiting with something like reduce?
02:43hiredman...
02:43cadsam I going to have to use a maybe monad? :D
02:43_mst,^every?
02:43clojurebotnil
02:43replacacads: no, but it's not too hard to write a version that does something like that
02:43hiredman,(doc every?)
02:43clojurebot"([pred coll]); Returns true if (pred x) is logical true for every x in coll, else false."
02:43_msthurrah :)
02:43cadsit's a special case of reduce that passes a logical value, anyways
02:43cadsah
02:43hiredman^ is reader syntax for (meta ...)
02:43cmvkkhmm
02:43_mstah, yes. I'd mistaken it for magic bot syntax :)
02:43cmvkki guess (every? identity ...) is mostly the same as (apply and ...) when you don't care about short circuiting.
02:43hiredman~def every?
02:44hiredmanthere is no reason every? couldn't short circuit, and it may well do so
02:44_mstthere's also (not-any? pred col) which presumably short-circuits...
02:45cmvkkhmm that's true.
02:45cmvkkactually, if you passed it a lazy-seq I bet it would.
02:45hiredmanuh
02:45hiredmanI guess it does short circuit
02:45cmvkkwell then.
02:46hiredman~botsnack
02:46clojurebotthanks; that was delicious. (nom nom nom)
02:46cadshow do I print out the source code of a public function?
02:46hiredman~def source
02:46hiredmanbetter check to if that worked, crontrib source lookup is new
02:47cmvkkseems to have worked.
02:47cads,(source 'every?)
02:47clojurebotjava.lang.Exception: Unable to resolve symbol: source in this context
02:47durka42don't quote the function name
02:47durka42it's in clojure.contrib.rep-utils
02:47durka42and clojurebot won't do it because he won't do IO
02:47cads,(do (use 'clojure.contrib.repl-utilities) (source every?))
02:47clojurebotjava.lang.Exception: Unable to resolve symbol: source in this context
02:47cadsok
02:48hiredmancads: clojurebot just sent a url leading to the source of every?
02:48hiredmanjust click on it
02:50cads~def every?
02:51cadsthat short circuits even with the recur there, right?
02:52hiredmanyes
02:52hiredmanbecause and is like do, but it stops if something is false or nil
03:09djkthxis there a way to get read-line to work properly in the slime repl?
03:09djkthxwhen i use it in slime, it never stops accepting input
03:11hiredman,(doc read-line)
03:11clojurebot"([]); Reads the next line from stream that is the current value of *in* ."
05:33cadsI'd like to contribute some functions to clojure.set, are there existing tests and stuff I could add to?
05:34kotarakcads: tests (if there are any) are probably in contrib in test_clojure
05:35hiredmanmake sure you get a CA in
05:43cadswhat's CA?
05:44cadsI'm thinking cellular automaton :)
05:47hiredmancontributor agreement
05:47hiredmanhttp://clojure.org/contributing
09:09jal648greetings all, I'm hoping to demo a bit of clojure at my work tomorrow, and I was going to use the ants.clj demo.
09:10jal648I 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?
09:10Chouseryes
09:10jal648Hmm, it did not seem to...
09:11jal648I launched the code through the REPL, that shouldn't matter though right?
09:11Chouserright
09:12ChouserI haven't actually tried on a 4-core. Now that I have one, I should try it... just a sec.
09:14Chouser hm, that's hardly using any CPU at all
09:16jal648I was wondering if perhaps the demo is out of date.
09:16Chouserseems likely, but I would expect that to cause an error, not just a low CPU usage.
09:17ChouserI think there may just be insufficient work to keep all my cores busy.
09:17jal648I 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?
09:19jal648maybe I'll just try increasing the number of ants...
09:27Chouseryeah, using 8 for nants-sqrt helps, as does changing ant-sleep-ms to 10
09:27Chouserbut it's still not pegging all 4 cpus
09:28Chousereach of the 4 are averaging 40% for me
09:30jal648I did 20 nants-sqrt and made the dimensions 120, I'm showing around 220% cpu usage which is enough for the demo I think
09:30Chouserso they're all being used, just not fully
09:31Chouserok
09:31jal648yeah thanks for the help!
11:44durka42whoops
11:45durka42contrib.javalog doesn't compile
11:45durka42 [java] java.lang.NoSuchFieldException: GLOBAL_LOGGER_NAME (javalog.clj:49)
11:46durka42oh, java 6
11:46durka42my bad
11:46durka42there should be a warning about that somewhere more obvious than the top of javalog.clj
11:48durka42and i am using java 6...
11:56durka42sorry about the noise
11:56durka42apparently ant ignores the settings in Java Preferences and reads $JAVA_HOME instead
12:09eeehi
12:10eeeI'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:10eeefor example
12:11eeeseems like an obvious thing to want to test a set for "hasKey" (python)
12:11eeedo you just use .contains ?
12:11eeei know someone wrote "includes?" in the contrib
12:12eeei just wanna check membership and I can't find the answer easily on the web
12:15eeei guess it's "(contains?)
12:15eee,(contains? #{'3} '3)
12:15clojurebottrue
12:16eee,(.contains #{'3} '3)
12:16clojurebottrue
12:16eeeso there are two ways that work
12:16eeeat least
12:17eee,(contains? '(3) 3)
12:17clojurebotfalse
12:17eee,(contains? '(3) '3)
12:17clojurebotfalse
12:17eee,(contains? ('3) '3)
12:17clojurebotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
12:17eee,(contains? '('3) '3)
12:17clojurebotfalse
12:18eee,(contains? '("3") "3")
12:18clojurebotfalse
12:18eee,(.contains '("3") "3")
12:18clojurebottrue
12:19eee??? so the clojure way doesn't always work?
12:19liebke,(doc contains?)
12:19clojurebot"([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:20eee,(doc some)
12:20clojurebot"([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:20liebkeeee: Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the range of indexes
12:20liebkethat's the problem you were having
12:21eeeso what's the most generic way to find membership
12:21eeein clojure
12:21eeefor any collection
12:23eeethat defn of contains seems out of whack with java's .contains
12:23liebkemost generic way? I'm not sure, but you can use some: (some #(= 3 %) [4 5 3])
12:24eeewell, it seems like the java method works
12:24eee,(.contains '("3") "3")
12:24clojurebottrue
12:24eee,(some '("3") "3")
12:24clojurebotjava.lang.ClassCastException
12:24eeeoh it needs a function
12:24eeei see
12:25liebkeI think the most generic way to do it, is .contains. It's alright to use java in clojure after all :)
12:25eeeto me, it's all right for esoteric stuff. for fundamental, primitive stuff, it seems wacky
12:26eeebecause you waste time looking
12:26eeelike in lisp . . .i think there was "member?"
12:26eeeor something
12:26eee(pmember
12:26liebkethat's why clojure uses java types, so you can use java transparently
12:27eeei see
12:27eeeso that'sa requirement on new collections if people were to write them
12:27eeemust implement collection interface
12:28eeeso I can count on this: http://java.sun.com/docs/books/tutorial/collections/interfaces/collection.html
12:29eee,(doc do)
12:29clojurebotjava.lang.Exception: Unable to resolve var: do in this context
12:30eeewhat happened to do?
12:30eee,(doc doall)
12:30clojurebot"([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:31eee,(doc do)
12:31clojurebotjava.lang.Exception: Unable to resolve var: do in this context
12:32chrizelmaybe because do is a special form?
12:32chrizel,(doc let)
12:32clojurebot"([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:32chrizelok O_o
12:33eee so (do) returns the last thing it doesn, right
12:33eee??
12:33chrizel,(doc if)
12:33clojurebot"([tst & etc]); "
12:33eeethat's what I was checking
12:33chrizelyes, do is for side effects
12:33chrizellike progn in common lisp or begin in scheme
12:34eeenow that's cool. I wish you were the docs
12:34eeethen I learn three languages at once!
12:34chrizel:-D
12:50eeedo redefinitions take a long time? I know they are not idiomatic ... but like (def foo (conj foo blah))
13:00eee(doseq i ,'(["a" "b"]) (print i))
13:00eee,(doseq i ,'(["a" "b"]) (print i))
13:00clojurebotjava.lang.IllegalArgumentException: doseq requires a vector for its binding
13:00eee,(doseq i ,(vec '(["a" "b"]) (print i)))
13:00clojurebotjava.lang.IllegalArgumentException: doseq requires a vector for its binding
13:00eeewhy that not work?
13:00eeei made it a vec
13:02Chouser,(doseq [i ["a" "b"]] (print i))
13:02clojurebotab
13:02eeeoh, it changed so that the i goes inside a vec
13:02Chouseryes
13:03eee,(doseq [i ,'(["a" "b"])] (print i))
13:03clojurebot[a b]
13:03eeesomeone's docs are old
13:03eeeon the web
13:04eeedoes that mean you can have as many bindings and seqs as you want?
13:04eeewell then you'd have to decide
13:04eeewhat to do when lengths were different
13:06Chouseryes, it acts like 'for'
13:06Chousernested.
13:06eee,(doc for)
13:06clojurebot"([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:06Chouser(doseq [a [1 2 3] b [4 5 6]] (prn [a b]))
13:06Chouser,(doseq [a [1 2 3] b [4 5 6]] (prn [a b]))
13:06clojurebot[1 4] [1 5] [1 6] [2 4] [2 5] [2 6] [3 4] [3 5] [3 6]
13:07eeeoh ok
13:07eeewoah
13:07Chouserit's got all the other 'for' features too. :while, :when, etc.
13:07eee,(doc prn)
13:07clojurebot"([& more]); Same as pr followed by (newline). Observes *flush-on-newline*"
13:07eee,(doc pr)
13:07clojurebot"([] [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:08eeei didn't know println was the long way
13:08eeeeither
13:08Chouserwell, it does different things
13:08Chouser,(println "hello")
13:08clojurebothello
13:08Chouser,(prn "hello")
13:08clojurebot"hello"
13:09eeei like the latter
13:09eeefor what i'm doing
13:09Chouserok
13:09eeewould have avoided confusion for me
13:09eee(,prn ,'(["a"]))
13:09eee,(prn ,'(["a"]))
13:09clojurebot(["a"])
13:09eee,(println ,'(["a"]))
13:09clojurebot([a])
13:09eeeyup
13:10eee,(println ,'(["1"]))
13:10clojurebot([1])
13:10eeeat one point I forgot my numbers were strings
13:11Chouserah sure
13:12eeeso 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:17lisppaste8eee pasted "i need a let binding, right?" at http://paste.lisp.org/display/79986
13:26eeehow do you make a closure that modifies what was originally (let)?
13:26eeeso everytime it's called the let binding changes?
13:28Chouserlet locals are immutable
13:29eeeso here's what i've got now: http://paste.lisp.org/display/79986 . . . which I was gonna make with an outer (let), instead.
13:29Chouserif 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:29Chouseragent
13:29eeesince nothing else uses "ALREADY-TRIED"
13:29eeei see
13:30Chouserthe simplest, but not necessarily most correct, would be an atom
13:30Chouser(def already-tried (atom (hash-set)))
13:30eeeor another hack (with-local-cars)
13:30Chouserthen when you want to conj something onto it, (swap! already-tried conj new-state)
13:31eeecool
13:31eeei can do a clojure with an atom, I bet
13:31eee(let already-tried
13:31eeeoops
13:31Chouserif you don't want it to be global, perhaps the atom should be passed into each fn
13:31Chouseror right, a closure
13:32eee(let [already-tried (atom (hash-set))] (defn sdsdfgsdfg ...
13:33eeeso because it's an atom, do I want that in a synchronous section?
13:33eeedosync
13:33eeeor something?
13:33leafweee: atoms are AtomicObject, so no need. The are synchronized in themselves.
13:33leafws/The/They
13:34eeenice
13:34eeehense the name
13:35leafwI think internally it uses this: http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/atomic/AtomicReference.html
13:35eee,(doc swap!)
13:35clojurebot"([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:37Chousereee: if the state of already-tried will ever need to be synchronized with any other state, then 'atom' is the wrong choice.
13:37eeethen you gotta use @ or something to get the thing the atom holds
13:37eeeright
13:37eeeok Chouser, thanks
13:38eeei'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:02RaynesYou wouldn't believe how many adolescents that I've got interested in functional programming so far.
14:02durka42really
14:03durka42that seems like a difficult task
14:03eeethey are teaching scheme to kids at brown
14:03eeeas a community project
14:10__macDefine community project
14:11__macI'm from sweden, I'm stupid with regards to english and american culture sometimes...
14:12__macIs that like something the student's take part in if they want to but the teachers are doing the teaching?
14:16eeewell i was being vague so as not to misspeak
14:17eeebut I believe it is for kids in cities that may not get the same chances as others
14:17eeeso it wasn't for the students going to college at brown
14:17eeeand what I meant was that it wasn't "for profit"
14:18__macAh I see
14:18eeeat 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__maccool
14:18eeeone thesis being that functional programming encourages learning more math
14:19__macYeah I can beleive that, pure functions and all that sure feels closer to math than imperative programming
14:19__macSo if you like functional programming, maybe you figure that math isn't that hard/bad after all
14:22__macWhat 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__macThere is this whole world of programming we were never told about
14:23eeethey are stating freshman with scheme now
14:23eeeintro course to programming
14:23eeeand the students will have their own android phone
14:23eeeand learn to write apps in some DrScheme dialect
14:23eeewritten for android
14:23eeelike MobyScheme or something
14:24eeei'm signin' off for now. nice shattin
14:24eeechattin
14:24eeei mean
14:24eeelol
15:29cads_hey, I need some help with my clojure classpath, and getting cloggle to work
15:29cads_cloggle's on my classpath, but when I try to load it it says that it can't find some java lib
15:30durka42which java lib?
15:30cads_it throws "ClassNotFoundException: javax.media.opengl.GLCanva"
15:30durka42that looks like a typo
15:32durka42Canva => Canvas
15:32dnolencads_: are you using slime? and did you already install JOGL?
15:32lisppaste8cads pasted "clojure error" at http://paste.lisp.org/display/79992
15:33cads_I've installed libjogl-java through apt
15:33dnolenbut what environment are yo using, vimclojure, slime, netbeans?
15:34cads_just the shell
15:34cads_the first part is my classpath string
15:34cads_which probably doesn't need to be so long
15:34dnolenyou need to tell java where the OS specific dynamic library is, not just the jars.
15:35dnolenon Linux they are the .so files
15:36dnolen-Djava.library.path= your library path
15:36cads_hmm
15:36dnolenneeds to be passed to java when you start the REPL
15:36dnolenin addition to setting the classpath to the jars.
15:37cads_let me find the so files
15:37cads_that doesn't seem right, there are no .so files
15:37dnolenare you on Linux?
15:38cads_yes
15:38dnolenthen there are most definitely .so files.
15:38dnolenlibjogl.so
15:38dnolenlibjogl_*.so
15:38dnolenand
15:38dnolenlibgluegen-rt.so
15:39cads_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:39cads_Im in ubunt :D
15:40dnolenlook in
15:40dnolendo you have a
15:40dnolendirectory?
15:40dnolensorry
15:40dnolen/usr/lib/java
15:40dnolen?
15:40durka42http://packages.ubuntu.com/jaunty/all/libjogl-java/filelist
15:41durka42he's right there are no .so's in that package
15:41durka42ah but ti depends on libjogl-jni http://packages.ubuntu.com/jaunty/i386/libjogl-jni/filelist
15:42durka42which puts them in /usr/lib/jni
15:42dnolenthere you go.
15:43dnolenanyways, you need to pass that path to the REPL via the -Djava.library.path flag
15:45cads_aah
16:44cadsI'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:45hiredmanthat will not work
16:45hiredman/usr/lib/jni/*.so will expand into a space delimited list of libraries
16:46hiredmanwhich I doubt java is looking for
16:46dnolen-Djava.library.path /usr/lib/jni should be sufficient.
16:51cadsI don't get it, it acts as if that flag is supposed to be giving it classes instead of .so files
16:51hiredman...
16:51hiredman 13:45 hiredman : /usr/lib/jni/*.so will expand into a space delimited list of libraries
16:51hiredman 13:45 hiredman : which I doubt java is looking for
16:52durka42i think the JVM recurses down java.library.path looking for stuff
16:52durka42if you want to give it a list you will need to delimit with colons
16:54cadshttp://pastie.org/473915
16:54durka42-Djava.library.path=/usr/lib/jni
16:55hiredmancads: pay attention to what I am saying
16:55hiredmanI just told you what is happening
16:55hiredmantwice
16:56durka42hiredman: no that wasn't the problem
16:57hiredmandurka42: it obviously is
16:57hiredmanoh
16:57hiredmanactually you are missing a =
16:57hiredman:P
16:57cadsd'oh
16:58dnolensorry probably my fault :)
17:02cadsawesome
17:02cadshttp://pastie.org/473927
17:02cadsnow we're only missing something in the namespace :)
17:02dnoleni talked about this on the list
17:02dnolenhis library is not structured properly
17:02dnolenyou need to create the folders to match his ns
17:02cadsoh no!
17:02cadsoh, well..
17:02cadsthat's not too bad
17:13cadsI 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:13cadshttp://rafb.net/p/M25lKP42.html
17:14dnolentypo
17:14dnolen]/usr/share/jave/gluegen-rt.jar
17:14dnolenjava not javve
17:14dnolenjave :)
18:02thearthuris #enclojure the best place to ask about the netbeans clojure plugin?
18:20unlink1What's the best way to transform a sequence into ((0 <first element>) (1 <second element>) (2 ...) ...) ?
18:20unlink1i.e. am I missing some builtin for this?
18:21dnolenclojure.contrib.seq-utils has an indexed
18:21dnolen,(indexed "test")
18:21clojurebotjava.lang.Exception: Unable to resolve symbol: indexed in this context
18:22AWizzArdthe clojurebot has not (use'ed ..) that
18:22unlink1Ok, that's exactly what I wanted. Thanks.
18:23unlink1Seemed silly to do that by hand.
18:24unlink1I should really just grep on the clojure-contrib source more.
19:06unlink1I 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:09cmvkki think you have to recognize the fact that there's a main function in the :gen-class form somewhow
19:09cmvkkactually, on second glance maybe that's not the case.
20:04bradfordany masters of the way of the monad on?
20:05bradfordI want to make a monad around this: (defn mean-state
20:05bradford ([x val queue] [(/ (- (+ val x) (peek queue)) (count queue)) (conj (pop queue) x)])
20:05bradford ([x] [x (conj clojure.lang.PersistentQueue/EMPTY x)]))
20:06bradfordit is a stateful statistic, such as a rolling mean of the last 100 values
20:19unlinkI'm running into a stateful parsing problem too.
20:21unlinkHow would you write a function parse-lines such that: http://dpaste.com/42824/
20:25durka42hmm is there even a lazy string split
20:52durka42unlink: you hooked me :) almost got something
20:54durka42Clojure=> (parse-lines "positive\n3\n2\n6\nnegative\n1\npositive\n8\n4\n5\nnegative\n12\n5\n9")
20:54durka42(3 2 6 -1 8 4 5 -12 -5 -9)
20:56unlinkhmm
20:58durka42i started by writing lazy-split
20:59durka42wrapped 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:02unlinkWhat are you lazily splitting on?
21:10durka42\newline
21:10durka42sorry, i walked away
21:10durka42(.indexOf s (int \newline))
21:11durka42<rant>why in the world does String.indexOf take an INTEGER?</rang>
21:12unlinkdurka42: I was trying to write a state-machine parser
21:13unlinkdurka42: Then I realized my states actually simply repeat in a clojure.core/cycle
21:14durka42parsing the string or a list of lines?
21:14unlinklist of lines
21:23durka42so the states are positive and negative
21:23durka42encountering the opposite word switches the state
21:25durka42unlink: my version sort of has a state machine, i suppose - apply-signs just does a condp, and calls itself with the current sign
21:27unlinkoh
21:27unlinkcan you paste it?
21:28durka42yeah hold on
21:30lisppaste8durka42 pasted "parse-lines" at http://paste.lisp.org/display/80001
22:41unlinkdurka42: here was my solution to a related problem: http://dpaste.com/42845/
22:44unlinkI just learned how to use condp, you don't actually need the first "line" before the second let
22:44unlinkSo anyway I consider that horribly gross.
22:45unlinkIndexing into the lines? recur 4 times? ugh...
22:49eee~log
22:49clojurebotlogs is http://clojure-log.n01se.net/
23:21unlinkdurka42: I've produced a somewhat less horrific version of the same
23:21durka42:)
23:22unlink1http://dpaste.com/42853/
23:25unlink1I wonder if there's some way I could write that with reduce
23:27Chouserseems likely
23:27durka42it seems like you'd need to reduce tuples
23:27durka42of an accumulator and a state
23:28unlink1right
23:28durka42this is starting to sound like a monad :)
23:28unlink1haha
23:28unlink1yes
23:29unlink1ooh, I like destructuring seqs with [x & xs]
23:29durka42or you could use a closed-over atom or something
23:32lisppaste8Chouser pasted "unlink1's fold-lines, with reduce" at http://paste.lisp.org/display/80007
23:33unlink1dammit, I shouldn't have clicked
23:33Chousersorry, I almost warned you
23:33Chouserbut I figured if you didn't want to see it, you wouldn't click. :-/
23:33unlink1or rather, once clicking, I shouldn't have studied your solution ;)
23:34ChouserIt's like algebra. kind of relaxing.
23:34ChouserI don't even know what you're doing, or trying to do.
23:35lisppaste8unlink1 annotated #80007 "final contribution before bedtime" at http://paste.lisp.org/display/80007#1
23:36unlink1Chouser: actually this is a reduced version of the larger problem
23:36unlink1but the larger problem essentially composes into this one
23:37Chouserif you add a loop in there, then you wouldn't have to pass f around all the time.
23:37Chousermatter of taste, I suppose.
23:37unlink1that's true
23:38unlink1but in this case I find the loop to be a little noisy
23:38Chousersure
23:38unlink1in principle I agree
23:40Chouserfwiw, recur allows for the possibility of primitives, while reduce does not. Dunno if that's likely to matter in a case like this.
23:55cadschouser, 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:56cadswill I have to dive into the clojure implementation?
23:56cmvkkyou want to change the set literal syntax from #{} to {}?
23:57cadsyeah, but only in my personal files, it should still read normal clojure code
23:57cmvkkunfortunately reader syntax is inaccessable from clojure itself.
23:57cmvkkyou'd have to change java code to make that happen. plus, what would you make map syntax be?
23:58cmvkksince {:a 1 :b 2} is currently a map.
23:58clojurebotmap is *LAZY*
23:58cadsshould I awk it?
23:58cmvkkwhat do you mean?
23:58cmvkkto find where that code is? it's in Reader.java i'm pretty sure.
23:59cmvkkor to change your own source code?