#clojure logs

2009-08-13

00:40mebaran151probably better than transcripts would be an introduction to modern Clojure for Schemers
00:42Chousera transcript is more editable than a video presentation -- might be a decent place to start.
01:18unlink2Is #(Integer/valueOf %) the standard way to parse integers in clojure?
01:27andyfingerhutI don't know of any other way off hand, but I certainly don't know much of what is in all the Clojure libraries yet. It works. Go for it! :-)
01:31hiredman~everyone
01:31clojurebotHuh?
02:32wavisteri'm trying to figure out how to create a collection A that contains a collection B that contains A. any advice? i can do it easily with mutable collections, but that's not ideal
02:33wavistersomething like (let [x [y] y [x]] x)
02:38frodefcompletely unrelated, but (let [x [y]] ..) shows an unfortunate aspect of the [] syntax, imho.. the square brackets are (too) overloaded.
02:38andyfingerhutI don't think that cycles are possible with immutable data structures like that.
02:39wavisternot possible? ack... seems not very declarative of clojure
02:39andyfingerhutWhat leads you to want such a cycle?
02:39andyfingerhutNot saying you shouldn't. Just curious.
02:39wavisternetworks that connect both forward and backward
02:40andyfingerhutSo like x and y are nodes in a graph, with lists of adjacent nodes for each one?
02:40wavisteryeah
02:41andyfingerhutSeems like it should be possible to do that. Thinking...
02:41andyfingerhutAre the nodes just symbols, or some arbitrary data structures?
02:41wavisterthe goal is to avoid creating a top-down map. nodes shouldn't be able to access more than what's next to them
02:42wavistera node could have other properties, but mostly it's just a collection of it's adjacent nodes. potentially empty
02:42andyfingerhutI mean, I've done simple graphs in C/C++ where they could be represented as a vector of nodes, and each node had a vector of nodes adjacent to it, where each nodes was simply an integer
02:44andyfingerhutSo a graph with 3 nodes 1, 2, 3, with edges between 1<->2 and 1<->3 would be represented by a vector [nil [2 3] [1] [1]]
02:44andyfingerhut(nil for the non-existent node 0)
02:44andyfingerhutThat would represent the edges.
02:44andyfingerhutOther info about nodes or edges would need to be represented elsewhere.
02:44wavisteryeah, it's the vector of nodes i'm trying to avoid. it's weird, i know. and there might be another way to do what i'm trying to do
02:45wavisterthe algorithm should have a node object, and have no access to the rest of the graph except through its neighbors
02:45andyfingerhutYou're trying to avoid the vector in order to make it easy to arbitrarily add new nodes, without having to assign them a numerical index, or something like that?
02:46wavisteryeah other nodes could be on other computers possibly
02:47andyfingerhutIt seems to me like you need some kind of "indirection" to represent this, not via pointers, since you can't have them, but via something like some kind of identifiers for node names.
02:47andyfingerhutThen lists of edges are lists of node names.
02:47andyfingerhutYou'd still need to look up those identifiers in some way, in order to traverse the graph.
02:47andyfingerhuti.e. get the edges for the next node in some walk
02:48andyfingerhutThat doesn't have to be a vector. It could be a hash, if the node is stored on the local computer. But what would you do if it was stored on another computer? Send it some request over a network and ask for info about that node? Then you definitely need some kind of identifier, I think.
02:49wavisteryeah, there could be a map that takes nodes as keys and has as values collections of other keys
02:49andyfingerhutAnd a way to know who to ask for info about that node in the graph.
02:50wavisteryeah there would be a function for getting that other node from wherever it was instead of a reference, so they'd all have to be functions i suppose even if they just always return the same reference
02:50wavisterokay i guess that's how i'll do it
02:52wavisterthanks :)
02:52andyfingerhutnp
02:53wavisteroh crap, but the node still has to reference the map of nodes to nodes, which references said node. looks like it has to be mutable
02:54andyfingerhutThe map of nodes to information about the nodes can be "well known", i.e. like a global thing.
02:54andyfingerhutIs there some kind of security or information hiding you're trying to enforce inside of your program?
02:56andyfingerhutOr you need multiple threads to make updated versions of this graph, and you want it to be possible to parallelize such updates?
02:56wavisterwell not really, to be truthful i'm mostly just playing around with concepts at this point. but i'm hoping it will evolve into something more serious
02:56wavisteryeah it's the latter
02:57andyfingerhutI don't know if this will work, but you could try representing nodes as Clojure Refs pointing to information about the nodes.
02:57andyfingerhutThen part of that information could be a vector of other Refs for nodes that are adjacent.
02:58wavisteri think that might be the way to go
03:01andyfingerhutI'd hack up a quick little toy program first to see if that basic idea works at all, or if there is something broken about the idea.
03:03wavisterdoing so :)
03:07wavister'(let [x (ref []) y (ref [])] (dosync (commute x conj y) (commute y conj x)) x)
03:08wavister,(let [x (ref []) y (ref [])] (dosync (commute x conj y) (commute y conj x)) x)
03:08clojurebot#<Ref@917cb0: [#<Ref@1913751: [#<Ref@917cb0: [#<Ref@1913751: [#<Ref@917cb0: [#<Ref@1913751: [#<Ref@917cb0: [#<Ref@1913751: [#<Ref@917cb0: [#<Ref@1913751: [#<Ref@917cb0: [#<Ref@1913751: [#<Ref@917cb0: [#<Ref@1913751: [#<Ref@917cb0: [#]>]>]>]>]>]>]>]>]>]>]>]>]>]>]>
03:08wavisterlooks good
03:08andyfingerhutWe have different esthetics, then :)
03:09wavisterheh. it should look like you're in one of those bathrooms with big mirrors on both walls...
03:09andyfingerhutI know what you mean. It ought to work.
03:10andyfingerhutYou'll just want to make your own custom printing functions for debugging :)P
03:10wavisterlol definitely
03:38lloy0076I'm trying to find an idiot's guide to installing the clojure-contrib and seem to see that there's a repository at sourceforge under SVN, one at github and then another group on google code...
03:39lloy0076It's possible I'm not looking in the right place for it - I've been staring at the wiki and www.clojure.org and various links and seem to have gotten a .jar from sourceforge...and that has download a heap of stuff in a trunk directory...
03:39lloy0076oops, it's not a .jar sorry (forgot to delete)
03:39hiredmanlloy0076: sourceforge is old
03:39hiredmanclojurebot: clojure contrib?
03:39clojurebotclojure is the brand
03:39hiredmanclojurebot: contrib?
03:39clojurebotcontrib is http://github.com/richhickey/clojure-contrib/tree/master
03:39lloy0076Whatever I got, seems to have built.
03:40lloy0076Ok, so I should figure out how to download it from github and build it from there?
03:40hiredmanyou don't want it from sourceforge
03:40hiredmansourceforge will be maybe six months out of date
03:40andyfingerhutTwo most recommended ways would be: get latest clojure and clojure-contrib, both from github, or (2) get 1.0.0 version of Clojure from wherever, and 1.0-compatible version of clojure-contrib from github.
03:41andyfingerhutThe latest stuff seems to work fine, and is probably easier to figure out how to get.
03:41lloy0076Ok, thanks. I believe I can figure that out - I got a tad confused between the s'forge and github one :)
03:46lloy0076@andyfingerhut and @hiredman (and @clojurebot) - thanks - problem fixed!
03:53angerman_how is the anatomy of those (with-xxx construct?
03:53hiredmaneh?
03:54hiredmanlike with-open?
03:54angerman_(def *xxx*) (defn with-xxx [val & body] (binding *xxx* val body)) ?
03:54andyfingerhutyou mean, how are they implemented?
03:54angerman_yes, like that
03:55andyfingerhutYou can do (use 'clojure.contrib.repl-utils), then (source with-open)
03:55andyfingerhutat the REPL
03:55andyfingerhutGreat learning tool.
03:55hiredmanwith-open is basically a let wrapping a try/finally
03:55angerman_I have a session object and I'm getting kinda confused with (let [session (get-session)] (to-session session key val) (from-session session key)))
03:56hiredman,(macroexpand '(with-open [a foo] stuf))
03:56clojurebot(let* [a foo] (try (clojure.core/with-open [] stuf) (finally (. a clojure.core/close))))
03:57angerman_so I'm wondering if I could simplyfy it by having a globaly bound one.
05:13mikem`_hi, newbie here. I have a string which I split with clojure.contrib.str-utils2/split, and I would like to assign the results to a map. starting with (split "First Last" #" ") I'd like to end up with {:first "First", :last "Last}.
05:15clojureusing (source) with vimclojure repl, syntax hi-lighting, is fun ;p
05:17andyfingerhutYou mean you want the keywords to always match the words split out of the string? That wasn't clear from your example.
05:17mikem`_andyfingerhut: yeah, ambiguous. let's try "Bob Smith" -> {:first "Bob", :last "Smith"}
05:18mikem`_the keys are predetermined and constant, I'm just filling in the map from a string
05:19andyfingerhutGetting there. Just having trouble with my home REPL to test out the return value of split
05:19andyfingerhutDon't recall it off top of my head.
05:19mikem`_andyfingerhut: apparently the return value of split is clojure.lang.ArraySeq which cannot be cast to clojure.lang.IPersistentStack (ie: pop won't work on it)
05:20taliosyou could (seq (split ...)) thou?
05:20taliosI think
05:20andyfingerhutTry something like (let [[first last] (split ...)] {:first first :last last})
05:21andyfingerhutNot sure if you've seen destructuring before, but the extra [] around first last mean to treat the (split ...) return value as a sequence, and take the first element and bind it to first, and the second and bind it to last.
05:22arbscht,(doc zipmap)
05:22clojurebot"([keys vals]); Returns a map with the keys mapped to the corresponding vals."
05:22andyfingerhutUsing the names first, last might lead to confusion in larger examples, given that those are also the names of commonly used functions (at least first is)
05:22arbscht,(zipmap [:first :last] ["Bob" "Smith"])
05:22clojurebot{:last "Smith", :first "Bob"}
05:23mikem`_andyfingerhut: ok, cool, that works :)
05:24mikem`_arbscht: thanks for that :)
05:25mikem`_ok, this works. but let's say I wanted to process each of "Bob" and "Smith" by passing it to some arbitrary function. how do I get it out of an ArraySeq?
05:26andyfingerhutThe let form I showed is one way.
05:26talios,(doc seq)
05:26clojurebot"([coll]); Returns a seq on the collection. If the collection is empty, returns nil. (seq nil) returns nil. seq also works on Strings, native Java arrays (of reference types) and any objects that implement Iterable."
05:26mikem`_hm, I guess functions first will get me the first
05:26andyfingerhutAnother is to do something like (let [a (split ...)] expression using (a 0) to get first element of a, and (a 1) to get second )
05:27andyfingerhutHmm. Actually that is only if the return value of (split ...) is a vector, I think.
05:27talios,(seq (split "hello world"))
05:27clojurebotjava.lang.Exception: Unable to resolve symbol: split in this context
05:27taliosdoh
05:28andyfingerhut(nth 0 a) will work for more kinds of things.
05:33mikem`_talios: can clojurebot pull in methods from clojure.contrib?
05:33mikem`_,(seq (clojure.contrib.str-utils2/split "hello world"))
05:33clojurebotjava.lang.ClassNotFoundException: clojure.contrib.str-utils2
05:33taliosI guess not :(
05:33mikem`_,(seq ('clojure.contrib.str-utils2/split "hello world"))
05:33clojurebotnil
05:34andyfingerhut,(use 'clojure.contrib.str-utils2)
05:34clojurebotjava.io.FileNotFoundException: Could not locate clojure/contrib/str_utils2__init.class or clojure/contrib/str_utils2.clj on classpath:
05:34taliosI can't remember who runs clojurebot either
05:34mikem`_,('clojure.contrib.str-utils2/split "hello world")
05:34clojurebotnil
05:34mikem`_,('clojure.contrib.str-utils2/split "hello world" #" ")
05:34clojurebot#" "
05:35tomojwhat do symbols do as functions?
05:36mikem`_,(clojure.contrib.str-utils2/split "hello world" #" ")
05:36clojurebotjava.lang.ClassNotFoundException: clojure.contrib.str-utils2
05:36talios,(use 'clojure.contrib.str-utils)
05:36clojurebotnil
05:36talios,(re-split #" " "Hello World")
05:36clojurebot("Hello" "World")
05:36taliosregex win :)
05:37tomojoh, just like keywords
05:38taliosa symbol is a function that takes a map as an arg
05:38taliosand a map is a function that takes a symbol
05:38talioskinda weird, but neat :)
05:38tomojyeah, I knew keywords did that
05:38tomojdidn't know symbols did too
05:38tomojalso didn't know they took two args
05:39tomoj,('foo {} 3)
05:39clojurebot3
05:40andyfingerhutI wonder what kinds of resource limits are on clojurebot, if any? Not that I want to crash it or make this channel unusable, mind you, just curious :)
05:41taliosforkbomb!
05:41tomoj(require '[clojure.contrib.str-utils2 :as s2])
05:41tomoj,(require '[clojure.contrib.str-utils2 :as s2])
05:41clojurebotjava.io.FileNotFoundException: Could not locate clojure/contrib/str_utils2__init.class or clojure/contrib/str_utils2.clj on classpath:
05:41andyfingerhutI did that once, on a shared server at my college. The sysadmin kicked me off that system for months.
05:41tomojit's in a sandbox
05:41tomojdunno what all it does
05:43arbschtclojurebot is hiredman's creature
05:43arbschtclojurebot: clojurebot
05:43clojurebotclojurebot is like life: you make trade-offs
05:43tomoj10 second timeout looks like
05:44tomoj'Thread. is in a commented-out blacklist, but not the uncommented blacklist on github
05:47tomoj"Naked Singularity" wtf?
05:47tomojclojurebot works with black holes?
05:49andyfingerhutAre you looking at clojurebot's list of patterns and canned replies?
05:49tomojnope
05:50tomojhiredman.horizon
05:50tomojgit b75cdb8b61e0fd4e83934e29d5ddaf78296ba7a7
05:51tomojtomoj: git b75cdb8b61e0fd4e83934e29d5ddaf78296ba7a7
05:51tomoj:(
06:11ole3hi, how do i cast an Intger to an int?
06:11cark,(int 3)
06:11clojurebot3
06:11opqdonut:t fromIntegral
06:11opqdonutwoops, thought i was in #haskell
06:11opqdonutsorry
06:11opqdonuti'll get my coat
06:11tomojhmm
06:12tomojisn't an Integer already an int?
06:12tomoj,(class 3)
06:12clojurebotjava.lang.Integer
06:12carkInteger is the boxed int
06:12opqdonut,(class (int 1))
06:12clojurebotjava.lang.Integer
06:12tomojit gets boxed when you ask for its class?
06:12opqdonutyeah, probably
06:12carkyes
06:12andyfingerhutIt gets boxed on every fn call.
06:12andyfingerhutso I've heard, anyway.
06:13opqdonutyeah, we need primitive type annotations
06:13tomojwell, anyway, there's no reason to cast, right?
06:13opqdonutwell performance
06:13opqdonut(loop [i (int 0)] ...)
06:13andyfingerhutThe primitive type annotations work fine within a loop/recur, inside of one function, but yeah, it would be nice if they could work across function boundaries, too.
06:14carktht would be a gret performance boost
06:14cark+a +a
06:16ole3thank you
06:20tomojopqdonut: I don't get it
06:20tomojoh, yes I do
06:20opqdonut:D
06:21andyfingerhutIs it still funny if you have to explain it to someone?
06:27ChousukeI think Rich is planning on allowing longs and doubles as function parameters (and probably as return values too)
07:12ChrisPSWhenever I do something in the repl and get an error message (inside emacs), I am always returned something like: java.lang.ClassCastException: java.lang.Integer (NO_SOURCE_FILE:0)
07:13ChrisPSthis NO_SOURCE_FILE, I would love to have that work
07:13ChrisPScan someone point a flashlight in front of my face?
07:15carkof you program in files and then load them, you should get a line number
07:16carkof/if
07:16tomojChrisPS: C-c C-k
07:16ChrisPStomoj: what?
07:16ChrisPScompile?
07:18tomojyep
07:18tomojunfortunately it can only compile the entire file
07:18tomojso.. everything has to work
07:19ChrisPScark: that is the odd thing
07:22ChrisPSmy compile is working just fine
07:25tomojafter C-c C-k you still get NO_SOURCE_FILE ?
07:29ChrisPStomoj: right!
07:30ChrisPSmind you, I am a java noob
07:32ChrisPSso I might have some problems wrt source-file ref. etc.
07:32ChrisPSbut everything else is working just fine (except for word-completion, but I think this is related...)?
07:33ChrisPSthat's my analysis anyway
07:45tomojoh hmm
07:45tomojI just got NO_SOURCE_FILE too
07:45ChrisPShehe, see
07:47tomojoh wait
07:47tomojnvm
07:47tomojI don't get NO_SOURCE_FILE
07:47tomojit depends on where the error is
07:48tomojif the error is in the line you type into emacs, then you'll get NO_SOURCE_FILE
07:48tomojif the error occurs inside a compiled function, you should see the filename and line number
07:48ChrisPSI have yet to see this, but ok for now
07:49tomojdo like (defn foo [] (map 1))
07:49ChrisPSusually when things blowup because of an exception or something, it responds with a NO_SOURCE_FILE:0
07:49tomojwhen you C-c C-k, you should get a big stacktrace
07:49tomojwell, compile, then call (foo)
07:50tomojsomewhere down on the stacktrace you should see your filename
07:50ChrisPSuser=> (foo)
07:50ChrisPSjava.lang.IllegalArgumentException: Wrong number of args passed to: core$map (NO_SOURCE_FILE:0)
07:50ChrisPSuser=>
07:50ChrisPS:-)
07:50tomojuhh
07:50tomojsomething's wrong with your slime setup
07:51ChrisPSI guess :-/
07:51tomojyou should get restarts with a full backtrace
07:51ChrisPSI always thought something was missing, since I did not see the Smalltalk effect
07:51tomojwhat is "the smalltalk effect" ?
07:52opqdonutChrisPS: use stacktrace
07:52opqdonutclojure.contrib.stacktrace
07:52ChrisPSthe: instaneosly everything now, effect
07:52opqdonutsee the docs
07:52ChrisPSopqdonut: ok
07:52tomojbut... it should do that by default
07:52tomojChrisPS: you did clojure-install?
07:53ChrisPStomoj: not recently
07:53tomojmaybe you need to update clojure-mode?
07:53ChrisPSwhat is the easiest path
07:54tomojI did emacs-starter-kit, install clojure-mode from elpa, then M-x clojure-install
07:54tomoj(well.. but then I deleted elpa clojure-mode since the clojure-test-mode from elpa still uses clojure.contrib.test-is)
07:54ChrisPSI've spent so much time reconfiguring emacs, that yeah, perhaps something got lost on the way
07:55ChrisPSregarding the stacktrace thing, when I (use it), I get a ClassNotFoundException etc...
07:55ChrisPSjava.lang.ClassNotFoundException: clojure.contrib.stacktrace (NO_SOURCE_FILE:78)
07:55ChrisPSbut what is this? a NUMBER??
07:55tomojyou have to require it
07:55ChrisPSok
07:56ChrisPS(require 'clojure.contrib.stacktrace)
07:57tomojthat's funny, I don't see a clojure.contrib.stacktrace
08:01ChrisPSneither do I
08:02tomojI'd just try starting with a fresh clojure-mode
08:02ChrisPSI think so too
08:02Chousukehm
08:02ChousukeI don't see .stacktrace either.
08:03Chousuke... I'm sure it was there. :P
08:03ChrisPSmkaay
08:04Chousukeheh.
08:05ChousukeI see a clojure.stacktrace
08:05Chousuke:P
08:06Chousukeapparently it was moved over when .test was, too
08:10carkI'm trying to use memcached with clojure, it's a problem that the data structures are not serializable
08:11carkso in the meantime i'm printing these to a string and reading these from the string returned by memcached
08:11carkbut it's slower
08:11carkso that defeats the purpose =/
08:12carki understand the problem about serialization, how to serialize an infinite sequence ...
08:12carkbut still that does not help =(
08:13Fossii thought the persistent datascructures implement serializable
08:13carki could not serialize (range 1 100)
08:14Fossitried (vec (range 1 100))?
08:14carkbut i'm a total noob when it's about java serialization
08:14carkyes that works
08:14Fossii think you have to realize lazy things (naturally)
08:14tomoj(range 1 100) is a lazy seq
08:14tomojwhich has the problem you just mentions
08:14carkright, but then i don't have a "universal" memcached serialization
08:15Fossiwell, maybe only convert to string (or other token) if it's lazy
08:15Fossithen again, almost everything tends to be lazy :D
08:15carkif i need to walk the data structures i'll be as slow as the printer
08:16tomojI don't get it, what's the problem with realizing before serializing?
08:16Fossii'm having a similar inherent problem with exception handling
08:16carkyou mean with lazy sequences ?
08:18Fossicark: seen http://groups.google.com/group/clojure/browse_thread/thread/e704414cf36ef2aa?pli=1 ?
08:19Fossirich suggests print/read too
08:19carkmhhh let me read that =)
08:19tomojI don't think it's gonna help much
08:19tomojmost of the solutions involve serializing to some string form
08:19Fossiand and there is rarely anything else you can do
08:20tomojwhat's missing serialization that needs it?
08:20tomojohh.. PersistentHashMap is, but Keyword isn't
08:21Fossitomoj: well imho it's just the tradeoff of realizing your whole deep datastructure, against serializing to string
08:21Fossia combination would be nifty (but impossible?)
08:21tomojyou have to realize the whole structure to serialize to string anyway, right?
08:21carklooks like i'm stuck with printing/reding
08:22Fossiwell, you could try to keep lazy seqs and delay realizing them to read time
08:22carkthere is still the problem with keywords ...
08:22tomojhuh?
08:23carkkeywords are not serializable either
08:23tomojhow can you write a lazy seq to a string without realizing the whole thing?
08:23Fossiwith exceptions a similar problem is to check for exceptions during realization, but also being able to stream the datastructure from jetty or such
08:24Fossitomoj: don't know, just a thought. kinda keeping the function call around
08:24Fossiso serializing "(range 1 100)" instead of "1 2 3 4 ..."
08:25Fossianyway, it has lot's of weird implications and prolly won't make sense in 99.9% of all cases
08:25tomojyeah, guess that would work if it was pure
08:26Fossiwould make one hell of a serializing framework thought if it would work
08:26Fossii don't have a good solution for the exception problem yet
08:27Fossiit would be so nice if the exception handling would be "carried over"
08:27carkFossi : you couldn't do it without language support
08:27Fossibut it's also *really* weird
08:27tomojwhat exactly are you trying to do?
08:28carkyeah some kind of super-dynamic vars, these would be carried by the environement of the lazy closures
08:28Fossitomoj: the use-case i had was in composure: i want to wrap every function i call in try/catch to not throw an exception at the user
08:28Fossibut i also might want to lazily stream things
08:29tomojguess I don't know enough to understand why that's a problem
08:29tomojoh, yeah, I see
08:29carkthat wouldn't work as you might send the first part of your page, then get the error while realizing the sequence deep in your tree
08:29Fossicdomposure doesn't let me set an exception handler for realization time
08:30Fossiso it realizes a function and one of my inner functions bails
08:30tomojyou _could_ do it in each part of the lazy seq, right?
08:30tomojbut I imagine that would be slow
08:30Fossitomoj: yes, that would make quite some places to add try catch as well
08:31Fossicark: exactly
08:32Fossianywaz, it's more off an enhancement to composure really in this case
08:32Fossibut it felt weird when i discovered it
08:33Fossiand it's not really obvious that try catch doesn't work for lazy seqs
08:33Fossiespecially since you (unknowingly) create/use them all the time
08:33tomojso maybe compojure can try/catch while it's consuming?
08:33Fossitomoj: yes, that's what i meant above
08:33Fossiand let me provide a handler
08:34tomojI've been thinking about compojure lately
08:34tomojit's very unopinionated
08:34carki wouldn't say that
08:35carkit tries very hard to avoid state
08:35carkbit too much in my opinion
08:35tomojwell, that's part of the clojure territory I think
08:35tomojI mean compared to, say, rails
08:35tomojthere are no opinions about how to structure your app really
08:35carktrue
08:35tomojwhich gives me the problem of designing such a structure :/
08:35Fossiyeah
08:36Fossithere are several aproaches as well
08:36tomojI think my experience with rails is probably limiting my imagination
08:36Chousukeon the other hand, if you come up with a good design, you can make a framework on top of compojure that supports that design
08:36Fossibut actually i like compojure for not imposing a structure on me
08:36tomojyeah, it's nice
08:37Fossiand i think the state handling is kinda ok as well
08:37tomojguess compojure is sort of the equivalent of rack
08:37Fossithe request usage is a like awkward, but then again, that's more or less the only place one of our whole projects has a state
08:38Fossican't do much else for the user session
08:38eevar2tomoj: neh. compojure is built on top of ring, which afaik is the equivalent to rack
08:38Fossicompojure is very cl-who'ish
08:38tomojok, so maybe compojure is half-way between rack and rails :)
08:38Fossiand it kinda just works ;)
08:39tomojbut I think in terms of like defcontroller, defaction, render, bindings over render for view variables, helper functions etc
08:39tomojI think these concepts from rails are probably limiting me
08:39Fossii dislike defserver etc for making me restart jetty :(
08:39tomojwonder if I can find some apps written in compojure on github...
08:40eevar2i've rewritten all my compojure apps a gazillion times w/o coming up with a design i'm happy with
08:40Fossiespecially because i have to restart slime then because my layout is too dumb
08:40eevar2s/all/both ;)
08:42tomojFossi: hum?
08:42tomojyou mean layout like html layout?
08:42tomojI found I could just recompile my handlers without even restarting jetty and changes would happen
08:42tomojbut I just did a trivial hello world
08:43Fossino, my clojure file
08:43Fossiif you defserver, the old server variable is gone
08:43Fossibut you need it to stop the jetty
08:43carkuse multiple file, one that initialize your server, and another one for routes/implementation
08:43tomojah, I see
08:43Fossibut using def*, you need to recompile to get the changes
08:44tomojwhat do you think about autoloading files like rails does?
08:44Fossiso if you forget to stop the jetty before compiling, you have to restart slime. at least that's the easiest way to get rid of the process i've found so far
08:44carki just handed out a fairly large compojure application to a customer, and only seldom had to restart the whole thing during developement
08:44Fossitomoj: well, you can recompile almost everything
08:44Fossijust not the defs
08:45tomojdef..whats?
08:45Fossiroute being the most common case
08:45Fossidefserver, defaction, defroutes etc
08:45tomojah
08:45tomojdo they generate anonymous functions or what?
08:46Fossino, they call def, creating a var
08:47Fossiwell, they also create a heap of anonymous functions, but that's not the problem
08:47tomojbut if the var has the same name, wouldn't the def just overwrite the old value?
08:47tomojjust like recompiling defn does?
08:49Fossifor defserver, you loose the reference to the server then, but it still runs
08:49tomojyeah that one makes sense to me
08:49Fossifor defroutes there was similar problem. let me look
08:49tomojactually...
08:49tomojI did it with defroutes and had no problem
08:50tomojat least I thought I did
08:50Fossiyeah, ok, that problem is more on our side of the code
08:50Fossiwe have two defroutes, one using the other
08:50tomojah I see
08:50Fossiand the secondary doesn't get reread
08:51Fossiand the primary is in the same file as the defserver call ;)
08:51Fossiso it prolly would work, if i didn't use C-c C-k
08:51Fossiand compiled everything needed seperately
09:58Fossiit's really funny: i just realized that most of the code i've recently written in javascript is functional
09:58Fossiand i document or mark the few occasions of global state explicitly
09:59Fossimakes me wonder how much of that habit will carry over to java
10:27ole3hello, is it possible to do bitwise or in clojure?
10:28cark,(doc bit-or)
10:28clojurebot"([x y]); Bitwise or"
10:28ole3thank you
10:30ole3hm, bitwise or of n arguments where n is greater 2?
10:31ole3ah... (reduce bit-or args)
10:31cark,(reduce bit-or 0 [1 3 7]) ?
10:31clojurebot7
10:32ole3:)
10:32carki was too slow i guess =)
11:02Chousukeheh, I forgot Clojure pattern literals don't need to escape \
11:03ChousukeGot a bit confusing when the pattern that I copied verbatim from LispReader source wasn't matching my floats :P
12:21cemerick~max
12:21clojurebotmax people is 164
13:08m3llingAnyone here a fan of StackOverFlow.com?
13:08m3llingI'm trying to get people to gather small Clojure examples into a question that I asked.
13:08m3llinghttp://stackoverflow.com/questions/1261557/whats-the-most-useful-thing-youve-done-in-less-than-50-lines-of-clojure
13:09m3llingPut a 250 point bounty on it.
13:13technomancym3llingl: personally I'm still trying to get over the idea of using a web application built in ASP.NET. apart from that it seems decent. =)
13:18carktechnomancy : there might be more of these than you might think
13:18carklots of intranets i guess
13:19technomancycark: well specifically for a web app targeted towards programmers. I'm sure there's plenty of news sites etc. that use it.
13:19carkwell .net programmers are programmers too
13:20carkand i woud say they have much merit =)
13:20technomancycark: Stack Overflow is the first community I've seen that has much overlap between Windows devs and the rest of the world.
13:22carktrue
13:22carksame goes for java
13:22carkit really on it's own planet
13:22cemerickit's a huge improvement for people that generally don't have a high-quality community (e.g. asking Java questions in Java-focussed forums is *really* painful)
13:25carkbut is really stackoverflow ASP.net ? or just .net somehow connected to the web ?
13:27carkok yes it is
13:36jweiss_how come when i call load-file, a java class i refer to in that file (inside a defn) is being instantiated, its static initializer fails because it's being called too early, i want it to wait until i actually call the function
13:38carkmaybe you have some code calling that function in your file ?
13:38carktry adding a print statement and see how it goes
13:38jweiss_cark: no, i don't call the function anywhere
13:39carkwould you care showing the code of this function ?
13:39jweiss_cark ok
13:40jweiss_cark, what paste website do you guys use
13:41carkclojurebot: paster?
13:41clojurebotGabh mo leithscéal?
13:41carkclojurebot: paste?
13:41clojurebotlisppaste8, url
13:41lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
13:41technomancyyou know what I could really use? an introduction to the quirks of the JVM that isn't written for a Java programmer.
13:42lisppaste8jweiss_ pasted "untitled" at http://paste.lisp.org/display/85329
13:42technomancyI have no idea how properties files are used, and I keep running into problems from multiple classloaders that confuse me.
13:42technomancyanyone know of an article like that?
13:42jweiss_cark ^^
13:43jweiss_oh um i think i get it, it's because i used def
13:43jweiss_i thought if i used it inside a function it wouldn't get called until runtime?
13:43jweiss_how do i create a reference to this java object that i can refer to throughout this file?
13:44jweiss_(at runtime)
13:45carkright
13:45carkyou don't use def inside a function
13:45jweiss_cark: what is the right way
13:45carkuse let
13:45jweiss_cark, but i want to be able to refer to this instance in other functions
13:45cark(let [test-script TestScript.)] ..use it here)
13:46jweiss_let is local
13:46carkallright
13:46carkput a (def test-script (atom (TestScript.))) outside the function then
13:46carkbut you said you don't want it to be instanciated early
13:46jweiss_cark, but i don't want it to run at load time
13:47jweiss_right
13:47carkso you (def test-script (atom nil))
13:47carkthen when you want to instanciate it (reset! test-script TestScript.)
13:47carkbut
13:47carkthat's the wrong way to go about doing this kind of stuff
13:48carknot very idomatic
13:48carknot very functional
13:48jweiss_cark: yeah, i am looking for the idiomatic way
13:48jweiss_i know its not functional, but i'm stuck with this java class
13:48jweiss_that has methods i need to call
13:48carki don't quite know about selenium
13:48carkbut usually you want to have a clojure function that will return a result
13:49carkso you can create your java objects in a let
13:49carkand pass these along
13:49jweiss_i don't want to create a new instance in every function call
13:50carkwell at some point you have a top-level state object, with all the state of your program
13:50jweiss_yeah, that's this testscript object
13:50carkyou can pass the script object already created to all your functions
13:50jweiss_using the atom, reset! stuff you mean?
13:50jweiss_oh i see
13:50Chousukeuse refs for state
13:51carkwell if it's a top level object, it's ok to use the atom stuff
13:51Chousukerefs are designed so that the value they reference varies over time, with well-defined semantics for how the reference changes.
13:52Chousukeatoms can change at any time, without any coordination
13:52jweiss_Chousuke: i'm just looking to set this once, and never change it
13:52jweiss_but i don't want to set it at load time, rather at run time
13:52carkChousuke : you don't want to manipulate a java object in a dosync
13:53Chouserjweiss_: sounds like a good job for an atom
13:53Chousukean atom might be okay. or a function that returns a singleton.
13:53Chousukeie. inits on first call, returns the object on subsequent calls.
13:53jweiss_Chouser: ok, i'll give that a shot. Chousuke: how do you return a singleton in clojure
13:53jweiss_Chousuke: oh i see
13:54ChousukeI think you would usually use a local atom for that though :P
13:54carkglobal state is evil !
13:54Chousukebut at least it would be local, so no evil user could go and change it.
13:54Chouseryeah, that's even better. close over an atom with a singleton-access fn
13:55Chousukecark: global coordinated references to immutable values are not :)
13:55Chousukeoh, the language has become sentient!
13:55Chouser(let [thing (atom nil)] (defn get-thing [] ...))
13:55clojure(fear)
13:56Chousermaybe it's just recursion. clojure has joined #clojure has joined ##clojure...
13:57carkChousuke : agreed, though it's best to have as little of that as possible
13:57jweiss_ok so i changed it to an atom that i reset! in my function. still get java.lang.ExceptionInInitializerError (console.clj:0)
13:57jweiss_when i load it in the repl
13:58carkshow us the new code =P
13:58carkprobably a little oversight
13:58lisppaste8jweiss_ pasted "untitled" at http://paste.lisp.org/display/85330
13:59jweisshow do i get it to colorize properly
13:59carkwell i'm positive that this is not run on load =/
14:00jweisscark: remember, it's the static initializer that's being run
14:00jweissso maybe it runs on import?
14:00stuartsierraThe compiler might run the static class initializer when the class is first referenced.
14:00jweissi thought that only ran when you create an instance of the class... but maybe it's even earlier, when the class is loaded?
14:01jweissi guess i should look this up
14:01carkmaybe some magic hapenning in the imported name spaces
14:01jweissyep, "you can also write static initializer blocks to initialize static variables when the class is loaded."
14:02jweisswell, i am gonna have to do some work to move that code out of the java class's initializer block
14:02jweissand into somewhere where it runs later
14:17technomancyOK, I'm pretty stumped about this. I'm trying to set some properties for the jets3t library. Dropping a jets3t.properties file in the classpath seems to have no effect according to System/getProperty.
14:17technomancyfirst of all, is that a good way to check for properties?
14:18technomancyI mean, are library-specific properties going to be present as system properties, or will they be loaded elsewhere?
14:19lrenntechnomancy: just dropping the properties files won't add them to the System properties.
14:19broolI think you need to load them explicitly, don't you?
14:20lrennhttp://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html
14:20broolhttp://www.factorypattern.com/how-to-readwrite-java-properties-files/
14:22technomancylrenn: right, but the jets3t library should be loading them
14:22technomancysorry, should have mentioned that
14:22technomancyhttp://jets3t.s3.amazonaws.com/toolkit/configuration.html doesn't say where the file goes, but in the root of a dir on the classpath is pretty standard
14:22technomancyright?
14:25lrenntechnomancy: right. But I don't think checking System/getProperty is a test to see if they got loaded.
14:25technomancyOK, I'm just not sure what the conventions are here. I guess jets3t should expose its own Properties object somehow?
14:26stuartsierratechnomancy: yes
14:26jweisscan we use the .. macro to call java like this: testscript.getTasks.createUser("blah") - where the last call has args?
14:27stuartsierrajweiss: yes: (.. testscript getTasks (createUser "blah"))
14:28jweissstuartsierra: thanks
14:30Chouseror (-> testscript .getTasks (.createUser "blah"))
14:31lrenntechnomancy: https://jets3t.dev.java.net/source/browse/jets3t/src/org/jets3t/service/Jets3tProperties.java?rev=1.18&amp;view=markup
14:32technomancylrenn: right; I can construct my own jets3t properties object by passing in a filename
14:33technomancybut if I don't know what filename it's going to use by default, that's not going to help
14:33technomancyI need a way to grab the properties object that's currently in use.
14:33lrenntechnomancy: http://jets3t.s3.amazonaws.com/api/org/jets3t/service/Jets3tProperties.html
14:34lrenntechnomancy: You already know the filename it's going to use by default.
14:36technomancylrenn: ah... I see. it wasn't working with "/jets3t.properties", but removing the initial slash fixed it.
14:36technomancygo figure
14:39Anniepoohas anybody written a little swing GUI repl you can embed in a clojure app for debugging?
14:39technomancynow to throw hadoop into the mix and watch it all explode. =\
14:46stuartsierratechnomancy: but it will explode in parallel!
14:46ChouserAnniepoo: I have one in my "textjure" project.
14:46jweissanyone know an existing fn to convert camel case to lisp case?
14:46ChouserIn fact, that's about all it is so far. Though not designed to be embedded in another app, I wouldn't expect it to be too difficult.
14:46technomancystuartsierra: I can now have twenty cores all ignoring my properties file at once! can't say that's not progress.
14:47stuartsierraoh yeah
14:47technomancystuartsierra: do you use s3 with hadoop at all?
14:48stuartsierraA little, mostly just copying stuff between S3 and HDFS.
14:48technomancyyeah, I'm distcping stuff over to S3 and getting lots of BS "Response '/packed' - Unexpected response code 404, expected 200" warnings without any actual errors.
14:48technomancycrazy stuff. =\
14:49stuartsierraYeah, it'll do that, but distcp retries on error.
14:49technomancyit's causing the mappers to fail for me.
14:49technomancyso I'm trying to increase the retry limit
14:50technomancyoh! I think I got it. I need to export HADOOP_CLASSPATH to a dir that has the jets3t.properties file in it
14:50b4taylorI think I've asked a few times but a better solution was always found so I never needed it, but can I give a type hint saying that something is an arry of doubles or something?
14:50b4taylorI just get back a 2d array of Objects.
14:50technomancyputting it in conf/ alone doesn't cut it
14:50stuartsierratechnomancy: yes
14:50b4taylorWhich may not be a problem, but I'd rather see Double[][] from my (into-array-2d foo)
14:51stuartsierraAlso, the Hadoop JARs include a copy of JetS3t, which may have its own properties file.
14:52lrenntechnomancy: are you doing this from the repl/slime with your clojure-project?
14:52technomancylrenn: no, hadoop must be run from the shell
14:52technomancyit's very tedious
14:53stuartsierraYou can run it via the API, but it's not well-documented. I've never figured it out.
14:54technomancystuartsierra: we've got that working, but it's so different from distributed mode that it's nearly useless for debugging real issues
14:54technomancyI mean, if you've already got your code factored out sanely
14:55technomancywrite as much as you can in regular clojure interactive slime style, and then go to slow batch processing for figuring out all the crazy hadoop quirks
14:56stuartsierraRight, that's what I tried to implement in my clojure-hadoop library.
14:56technomancythe problem with Clojure/FP is that the interesting problems get solved so easily that you end up spending all your time on the boring infrastructure BS like this.
14:56Chousukeheheh
14:56stuartsierraI think that's true of programming in general.
14:56clojurebotthat is not what I wanted
14:57technomancystuartsierra: it's just more noticeable when your language is more streamlined
14:58stuartsierrayes
14:58jweisswhat is the significance of # in task#, in this line: (let [task# (apply instantiate-task ant-project ~(name ant-name) props#)]
14:58jweissis it just part of the name?
14:58stuartsierraI'm suffering through WSDL right now.
14:59technomancystuartsierra: my condolances
14:59ChousukeI wonder if it'll be a problem for my reader that it might consume more from a stream that it needs to read a single object :/
15:00technomancyChousuke: that's why you need a PushbackReader IIRC
15:00technomancyin the current implementation
15:00Chousuketechnomancy: yeah, but my current reader design doesn't work with anything stateful.
15:00Chousukeit just wants a seq of lines.
15:00technomancygotcha
15:02Chousukeit shouldn't be too difficult to "push back" any leftover stuff after a read has been completed though.
15:03Chousukebut then it would complicate the line numbering ;/
15:05AnniepooWhat's not to like about a language you already like, when you're stuck in a long debug cycle, and you realize instead of wishing for a debugger you could HAVE one.
15:06ChousukeI suppose the reader could claim ownership of the stream and then any operations on the reader input the user might want to do should be on the (immutable) reader data structure.
15:06Anniepoo11:35 I start writing one - 11:40 I realize undoubtedly one exists and ask, 11:47 Chouser suggests where to get one, 11:53I notice his message, but mine's done already
15:16b4taylorDo you know a sane way to get a 2d array of doubles?
15:16b4taylorargh
15:16b4taylorChousuke: Do you know a sane way to get a 2d array of doubles.
15:19ChousukeI avoid arrays in Clojure code to the best of my ability :P
15:19b4taylorUnfortunately I'm interfacing to a matrix library :p
15:19b4taylorI suppose I could just write a pure clojure library.
15:20b4taylorI doubt it would be slower, and I just need the basic operations. I don't need solving or anything.
15:20stuartsierra,(make-array Double/TYPE 3 5)
15:20clojurebot#<double[][] [[D@1d433c1>
15:20b4taylorAhha.
15:21b4taylorThen I just have to copy the data over.
15:21b4taylorstuartsierra: I'll play with this. Thanks.
15:21stuartsierranp
15:23b4taylorAlso, I suppose I should ask for a good lisp macro how-to before I ask for a clojure one.
15:25lrennjweiss: it generates a unique symbol.
15:25jweisslrenn: thanks
15:28lrennhttp://clojure.org/macros is pretty sparse.
15:36jweisscan someone tell me whats wrong w this macro (trying to defn a function that is just a wrapper for a java method, using memfn):
15:36jweiss(defmacro define-task [task-name]
15:36jweiss `(def ~task-name (memfn (.. @testscript getTasks ~task-name))))
15:36jweissi get java.lang.IllegalArgumentException: Malformed member expression (repl-1:15)
15:38stuartsierramemfn only works on isolated symbols
15:38andyfingerhutIf you want lots of examples and discussion of macros, book length, then Paul Graham's On Lisp is a Common Lisp specific book on them, but a lot of them translate well to Clojure. http://www.paulgraham.com/onlisp.html Probably more than you want right now, though :)
15:39cemerickisn't memfn long deprecated at this point (by #()?)
15:39jweisscemerick: it's still in the Programming Clojure book
15:39cemerickah
15:39stuartsierra,(defmacro define-task [name] `(defn ~name [script#] (.. script# getTasks ~name)))
15:39clojurebotDENIED
15:40jweissstuartsierra: thanks
15:40Chousukeit's not deprecated I guess but I don't think anyone uses it :P
16:20jweissif i have a vector of args i want to pass to a java method, how do i unpack the vector to call the method
16:22hiredmanjweiss: easiest way is to wrap the java method call in a function and use apply
16:23hiredman,(let [f (fn [s p r] (.replaceAll s p r))] (apply f "foo" ["o" "a"]))
16:23clojurebot"faa"
16:23jweisshiredman, maybe i should go up one level. i'm trying to write a macro that just creates function wrappers for all the member methods on a class
16:24hiredman:(
16:24hiredmanjweiss: I would just write function wrappers as needed
16:24jweissi'm having trouble dealing with methods with args tho
16:24jweisshiredman, i can't it has to be dynamic :)
16:24hiredmanwhy?
16:25jweissbecause my prog won't know beforehand what all the methods on this class are, it will just know at runtime
16:25hiredmanwhat does that have to do with any thing?
16:26jweisshow can i write a wrapper for a method before i even know what class i'm going to be using
16:27jweissoh, i think what you're asking is why wouldn't i just use the java method directly
16:27jweissi just want a cleaner syntax
16:27jweissbecause i want other people to be able to use this
16:30cemerickjweiss: about the only difference you'll see is the lack of a period before method names
16:30cemerick,(.size [])
16:30clojurebot0
16:30cemerick-> (size [])?
16:31cemerickit's too bad proxy doesn't allow one to put docstrings in their usual spot
16:32jweisscemerick: yeah sorta, i was actually using (.. @myobjatom (method args)) -> (method args)
16:32jweissor actually
16:33cemerick(.method @youratom args) is more idiomatic
16:33jweiss(.. @myobjatom getTasks (method args))
16:33hiredmanand -> is kind of prefered over ..
16:33hiredman(-> myobjatom deref getTasks (.method args))
16:34cemerickwell, I'd keep the @, but sure :-P
16:34jweissk
16:34cemerickjweiss: the java interop syntax is virtually transparent -- enjoy it :-)
16:35hiredmanI can tell which functions I created though messing around at the repl and which I just sort of typed out by the use of →
16:35jweisscemerick: hopefully my other team members won't be thoroughly confused. clojure is completely foreign to them
16:35hiredmanthe repl functions always have a bit long → call
16:35jweissthen again, so is most programming, so what is the diff right
16:36jweisseventually i'm going to make a UI, but was hoping for a repl to be usable enough
16:36cemerickindeed -- shock them with concision
16:42jweissthere isn't any way to really build javadoc into classes so it's available at runtime, is there.
16:42jweissthat sucks
16:52cemerickThat will change eventually. We'll need that capability before we can release the next version of our main product.
16:54ChouserJava's going to compile javadoc right into the classfiles?
16:59jweissi can't believe they didn't allow for annotations to hold javadoc
16:59cemerickChouser: wha?
17:00cemerickoh, hah, I didn't read jweiss' comment properly
17:00cemerickI thought he was talking about generating javadoc from clojure code (e.g. gen-class, newnew)
17:01cemericknot sure how I misunderstood that :-/
17:01cemerickmisread*
17:01Chouserah
17:02Chouserdoes that mean generating a sort of stubbed out .java?
17:03cemerickYeah, almost certainly. We dove into that a little bit some months ago, if you'll recall.
17:03Chouserhm, I don't. I maybe be blocking the memories.
17:03cemerickI did some spelunking into javadoc, and it's a super-gnarly javac sidecar that is entirely unextensible.
17:04cemerickI thought that's where gen-interface originally came from, but maybe I'm inventing whole cloth over here.
17:08cemerickhrm, what is #_ used for? It's defined in LispReader, but unused in core.
17:10ChouserIt comments out an expression.
17:10hiredman,(do 1 #_2)
17:10clojurebot1
17:10Chouser,[1 2 #_ (oh no goin crazy here) 3]
17:10clojurebot[1 2 3]
17:12cemerickyeah, I figured that from the LR impl. I just can't think of any reason to use it...
17:12cemerickjust inline comments, where (comment ...) is too much?
17:13cemerickoh, I see, it doesn't evaluate to nil
17:19Chouserexactly.
17:23cemerickannotations will be the death of us all
17:24ChouserI don't even know what they are.
17:24ChouserAs far as I'm concerned, if Clojure doesn't support it, it doesn't exist. :-D
17:25cemerickit's only a matter of time before clojure supports them. The whole Java multiverse is tilting in their direction.
17:25Chouseryes, this does present logical paradoxes when I try to write new features for clojure.
17:35mebaran151I never really got their point, but probably clojure could quarantine annotations with the rest of its Java compromise
17:36mebaran151I also was wondering whether or not, based on Clojure's compilation model, anonymous fn's were ever garbage collected
17:36mebaran151if each fn gets it's own class, it would seem that using lots of clojures would rapidly fill up the permgen
17:37Chousukelots of clojures? :P
17:37technomancymebaran151: iirc that was a problem a while ago, but it's been addressed
17:37cemerickas code transformation mechanisms, they're simply nutty; for controlling code generation and runtime configuration in one spot, they're better than the alternative (e.g. like wedging stuff into a superclass or put into an XML file or whatever)
17:38cemerickmebaran151: an anonymous fn still has just one class.
17:38carkmebaran151 : closures are really like a class
17:38carkso the environement is an instance of that class
17:38carkand instances can be garbage collected
17:40cemerick,(doseq [x (range 2)] (println (class #(list))))
17:40clojurebotsandbox$eval__2445$fn__2447 sandbox$eval__2445$fn__2447
17:41mebaran151no I see
17:42mebaran151cemerick, but if you just had a large application with lots of anonymous functions, it seems like wedging them into the superclass would be preferable, though I guess at any given time you might want to run that code path
17:43cemerickmebaran151: are you referring back to annotations?
17:46mebaran151nah, I'm being unclear
17:47mebaran151in a really large app, it seems like clojure might force you to suffer from class bloat
17:47mebaran151'though I guess each class is small enough individually
17:47carkwell we don't see these classes
17:47mebaran151that it's not like in some Java servlet apps I've seen
17:47carkyou mean for the user ?
17:47cemerickwell, I think class GC is off by default in most VMs, though there's an option
17:48cemerickUnless you're actually defining new fns regularly, I don't think there'd be enough class definition to cause a problem.
17:50hiredmanthe class gc can also be an issue for java, I've seen reports of redeployments on tomcat eventually filling the permgen space
17:50carkbut the fix technmancy refered to should shield us from that , isn't it so ?
17:51carkmy understanding was that everything was in it's own class loader
17:51mebaran151hiredman, that's what I was referencing: I've had to redeploy on Jetty
17:51mebaran151and if you have many many classes, I've noticed weird GC behavior on this one app I put up
17:52hiredmancark: I dunno if it is complete fix
17:52hiredmanit might fix some clojure specific issue
17:52carkwell every eval (and so the compiled code) should be garbage collected
17:53carkbut i don't know how that applies to loaded code
17:53carkis there a class loader per defn ?
17:53carkor per anonymous function even
17:57cemerickI wonder if it'd be worthwhile to define a binary serialization mechanism, so that arbitrary Serializable object could be dropped in in-line
17:58hiredmanit would be pretty easy with #=
18:00cemerickugh, doesn't seem like a good move -- one would have to encode the binary serializations. I was thinking of going the other way, emitting binary for clojure data structures, with java-serialized graphs in-line.
18:01cemerickreadable clojure is nice, but *big* (esp. strings and such)
18:01hiredmancemerick: you could do that
18:01hiredmanjust wrap the binary in #=(read-binary-chunk ...)
18:01Chousukeyou need to base64-encode it too :/
18:02cemerickyeah, that's what makes any use of #= sorta pointless
18:02hiredmanI guess
18:03cemerickIt'd be pretty easy to emit the core data structures via DataOutputStream, etc.
18:05Chousukehmm
18:05Chousukehow do you serialise infinite seqs though? :P
18:06carkserialize the underlying lambda !
18:06Chousukehm, I guess it's not so difficult. you'd just have to serialise whatever produces the next value.
18:06Chousuke(in addition to the values so far, of course)
18:07cemericknot even that, I think. Just some marker to start a map, read pairs until you hit a terminating marker, etc. Recurse, and done.
18:13hiredmanI thought the marker to start a map was {
18:14cemerickah, I had thought that DataOutputStream packed bits. So yeah, standard delimiters would work fine.
18:41cemerickheh, java regex Patterns are serializable, but not interned. I didn't expect that...
18:42cemerickactually, I didn't expect that they wouldn't override equals and hashcode based on the pattern string. That's more like it. :-)
19:55arraymanI've looked all over, but can't seem to find the right syntax for an array argument in gen-class
19:58_mstI've done something like this before: (defn -read-char<>-int-int [this cbuf off len] 456)
19:58_mstbut I haven't tried it recently :)
20:01arrayman@_mst Thanks; does that automatically get added to the .class as an instance method because of its name, or do I have to mark it as such?
20:03_mstI think it's just based of the name, yep. In that case I was overriding this method of StringReader: "int read(char[] cbuf, int off, int len)"
20:03_mstthe full example's here if you want to try it: http://dishevelled.net/Tricky-uses-of-Clojure-gen-class-and-AOT-compilation.html
20:05arraymanI remember reading that article, but was under the impression that I had to give the method that special name _and_ tag it inside the gen-class invocation. Thanks for setting me straight.
20:07arrayman@_mst I notice that -read-char<>-int-int matches the argument signature (char array and two ints), but how does the return type get specified?
20:10_mstit doesn't in that example, but I'm not sure you'd need to
20:10clojurebotthat is not what I wanted
20:10_mstdoes java actually let you dispatch on return type too?
20:14arrayman@_mst I don't believe it does, so maybe I'm fretting about nothing.
20:15arrayman@_mst Does the same naming apply to static methods?
20:16_mstI've never done much with static methods and gen-class, sorry. But can you really override static methods anyway?
20:16arrayman@_mst I'm creating a brand new class, not overriding
20:17_mstah I see
20:17arrayman@_mst ...and I've been able to define other static methods on it -- but haven't been able to specify an array type at all.
20:50mrsolohttp://4.bp.blogspot.com/_syI_yyzTPG8/SnDhboxfNZI/AAAAAAAAATk/4cyx7jJ4XLc/s1600-h/chart1_jruby.5.png
20:50mrsoloack!
20:50mrsoloand i though jruby is slowest of them all...
20:56cemerickmrsolo: that's why libraries are so important. e.g. who cares that the sort fn uses java.util.Arrays/sort?
20:57cemerickmrsolo: where'd that graphic come from?
20:57mrsolohttp://berlinbrowndev.blogspot.com/2009/07/jvm-notebook-basic-clojure-java-and-jvm.html
20:57mrsoloi haven't went through the details
20:58mrsolobut this is the first benchmark that shows jruby is faster than clojure
20:58mrsolousually it is another way around..
20:58carkhe's filtering twice
20:59cemerick*shrug* both JRuby and clojure should (and do, at least in clojure's case) use Java's sorting routines
21:01mrsoloshould but this is intentional
21:01mrsologuess he is trying to determine the overhead of various jvm langauges.
21:01cemerickyeah, I suppose it's an interesting exercise.
21:02cemerickquicksort certainly benefits from the use of a mutable data structure. :-P
21:03carkthe java example doesn't really mutate stuff
21:09cemerickcark: LinkedLists are most certainly mutable.
21:10carkright, but they are only used like our own mutables
21:14cemerickhardly -- the clojure code is doing two filters on each pass, vs just accumulating results.
21:15carkyes yes
21:15carki mean the linked lists while being mutable are used in a way that won't interfere with the outside of the function
21:16carkin the same way we're supposed to use the new mutable data structures in clojure
21:17carkbut yes i wouldn't do the quicksort in clojure that way, not for speed ... though the ruby version is not any better
21:19mrsoloya jruby version is pretty crappy
21:19mrsolostill faster
23:08avitalhi. is there an equivalent to filter for hashmaps?
23:08RaynesFilter works for maps.
23:09avitali'm looking at the source code and it seems that pred only gets one argument. i want to filter based on the keys, not the values.
23:12hiredmanavital: the seq of a map is a seq of [key value] pairs
23:12avitalah nice ok cool
23:12hiredman,(seq {:a 1 :b 2})
23:12clojurebot([:a 1] [:b 2])
23:13hiredman,(filter #(= 1 (val %)) {:a 1 :b 1 :c 3})
23:13clojurebot([:a 1] [:b 1])
23:13hiredman,(into {} (filter #(= 1 (val %)) {:a 1 :b 1 :c 3}))
23:13clojurebot{:b 1, :a 1}
23:13avitalwow what wow wow
23:13avitalwhat is #(
23:13avitaland what is val
23:13avitaland %
23:13avitalWOW
23:14avitalis #( a really quick way to define a fn
23:14avitalwhere % is its arg?!
23:14hiredmanyes
23:14avitalINCREDIBLE
23:14hiredmanbut it is not equiv to (fn [] )
23:14hiredmanwith #() there is no implicit do
23:14hiredmanwell
23:14avitalhmmm not sure what that entails
23:14hiredmanmore that that
23:14hiredman#(foo 1) => (fn [] (foo 1))
23:15hiredman#(1) => (fn [] (1)) => an Exception
23:15avitalah i see
23:15avitalso wait what is val?
23:15hiredman,(doc val)
23:15clojurebot"([e]); Returns the value in the map entry."
23:15hiredman,(class [1 2])
23:15clojurebotclojure.lang.LazilyPersistentVector
23:15hiredmangrrr
23:16hiredman,(val [1 2])
23:16clojurebotjava.lang.ClassCastException
23:16hiredmanbah
23:16hiredman,(class (first {:a 1}))
23:16clojurebotclojure.lang.MapEntry
23:17avitalthanks this is great
23:56Chouserany suggestions on an easy way to un-chunk a seq?
23:56Chouser, (chunked-seq? (seq [1 2 3]))
23:56clojurebottrue
23:57Chouser,(chunked-seq? (seq (map first (take-while identity (iterate next [1 2 3])))))
23:57clojurebotfalse
23:57Chousersurely there's something better than that.