Re: (finally) got all class signature changes w/gen-class reloading at runtime

2011-02-10 Thread Robert Campbell
>  (vm) >>  {(first (find-classes #"clojure.lang.Compiler\$DefExpr\$Parser")) >>   (to-byte-array >>    (java.io.File. >>     "/Users/georgejahad/incoming/clojure/classes/clojure/lang/Compiler >> $DefExpr$Parser.class"))}) >> >> is th

(finally) got all class signature changes w/gen-class reloading at runtime

2011-02-09 Thread Robert Campbell
Back in January I found myself writing some gen-class to connect my Clojure library to my Java project. Until now I'd been spoiled by Clojure's dynamic, interactive nature, so running up against the whole "stub class signature can't change w/out jvm reboot" thing hurt a bit. I found a partial solu

Re: Clojure/JVM languages internal presentation

2011-01-19 Thread Robert Campbell
s this conclusion > derived ("Clojure - being a Lisp dialect - has a steeper learning > curve due to its syntax and more purely functional nature.")? Scala > has more syntax/semantics than Clojure AFAICT. Was it familiarity with > the Java syntax? > > Regards, >

Clojure/JVM languages internal presentation

2011-01-17 Thread Robert Campbell
Hey guys, This past summer I gave a presentation on JVM langauges at our company's worldwide developer summit. I tried to get approval for Clojure but had to settle for Scala because its syntax didn't frighten management. I figured I'd share it in case any of the slides can be of use elsewhere. o

Re: Why does (.foo (new Bar)) use a different method invocation mechanism than (def bar (new Bar)) (.foo bar)?

2011-01-16 Thread Robert Campbell
't seem to actually matter since at the end of the day the compiled bytecode is twi identical invokevirtuals. Rob On Sun, Jan 16, 2011 at 7:22 PM, Rasmus Svensson wrote: > 2011/1/16 Robert Campbell : >> The second form - (.foo bar), expanded to (. bar foo) - eventually >> call

Why does (.foo (new Bar)) use a different method invocation mechanism than (def bar (new Bar)) (.foo bar)?

2011-01-16 Thread Robert Campbell
I've been trying to understand exactly how these two statements are evaluated by tracing execution through Compiler.java, Reflector.java, etc of tag 1.2.0. The second form - (.foo bar), expanded to (. bar foo) - eventually calls Reflector.invokeNoArgInstanceMember. The first form - (.foo (new Bar

Re: Slides for short (45 minutes) presentation of clojure for java devs

2010-06-23 Thread Robert Campbell
I'd like to resurrect this thread, because I have the exact same requirement Laurent had and I'm hoping there's been some additional progress in this area. I'm set to give a Clojure presentation to our company's Java developers, and I'm looking for a way to excite the audience about FP concepts in

Re: The % Schemer Series - are they worth the money?

2010-03-23 Thread Robert Campbell
I love the Little/Seasoned Schemer books. They feel lightweight, both physically and in content, and I managed to work through them fairly quickly. It was surprisingly fun. SICP/HTDP/PAIP, on the other hand, have more of the textbook feel which has so far kept me from working through them. The onl

Re: Leaning about VM's, JVM in particular

2010-02-16 Thread Robert Campbell
"Some good books that we recommend to get you on your way [to understanding the JVM/runtime] are: "Java Reflection in Action" by Ira R. Forman and Nate Forman. "The Java Virtual Machine Specification" 2nd edition by Tim Lindholm. "Effective Java" 2nd edition and "Java Puzzlers" by Joshua Bloch. And

Re: iterator-seq runs over

2010-02-16 Thread Robert Campbell
Hi Stuart, That fixes the problem, thank you. When I ran the result-set through (type), it showed me that the instance was actually a ResultSetStream. While the Jena ResultSet interface doesn't act as a closable resource, perhaps the stream was being closed once the owning QueryExecution obj was

iterator-seq runs over

2010-02-15 Thread Robert Campbell
(map handler (iterator-seq result-set)) always throws a NoSuchElementException (map handler (butlast (iterator-seq result-set))) always works. (count (iterator-seq result-set)) is returning the correct number of elements. Calls to first, second, nth, also work correctly. When I manually test a r

Re: Cartesian product of map pairs w/labels

2010-02-07 Thread Robert Campbell
Hi Michał, That works perfectly and is much simpler, thank you. On Sun, Feb 7, 2010 at 4:23 PM, Michał Marczyk wrote: > Ouch, sorry, I misread your specs... Use this instead: > > (map #(zipmap (keys coordinates) %) >  (apply cartesian-product (vals coordinates))) > > With coordinates bound to y

Re: Dutch Clojure users

2010-02-07 Thread Robert Campbell
I'm only 1.5hr flight away in Prague. I'd be happy to host any Clojure users to trade notes over our famous beer. On Sat, Feb 6, 2010 at 12:26 PM, Joop Kiefte wrote: > Hello folks! > I am from the Netherlands and I am learning Clojure now, using it at work, > and loving it so far. Are there any

Cartesian product of map pairs w/labels

2010-02-07 Thread Robert Campbell
Imagine a map m { "foo" [1 2 3 4] "bar" [\a \b \c] "baz" [true false] } How could I transform that into a seq s ( {"foo" 1 "bar" \a "baz" true} {"foo" 1 "bar" \a "baz" false} {"foo" 1 "bar" \b "baz" true} {"foo" 1 "bar" \b "baz" false} {"foo" 1 "bar" \c "baz" true} {"foo

Re: Clojure + Redis

2009-12-30 Thread Robert Campbell
I think anything which lowers the impedance mismatch between Clojure data structures and a persistent store is worth investigating. I'd love to find an ACID, transactional store which accepts native structures. Right now I'm using CouchDB, and while JSON is close enough, it still requires a mapping

Re: Help with my vec matching function

2009-12-28 Thread Robert Campbell
e and the candidates, I will just return []. Rob On Mon, Dec 28, 2009 at 6:28 PM, ajuc wrote: > > > On 28 Gru, 20:57, Robert Campbell wrote: >> How might I add a third and final condition, where those candidates >> with equal scores AND equal counts are all returned toget

Re: Help with my vec matching function

2009-12-28 Thread Robert Campbell
hould be getting [[1 2 \a] [1 2 \b] [1 2 \c]] since each of them is equally close to [1 2 3] On Mon, Dec 28, 2009 at 5:20 PM, Robert Campbell wrote: > Thanks ajuc. > > I updated the implementation to match your algorithm: > > (defn closest-match >  "Searches the haystack v

Re: Help with my vec matching function

2009-12-28 Thread Robert Campbell
Thanks ajuc. I updated the implementation to match your algorithm: (defn closest-match "Searches the haystack vecs for the closest match to the needle vec" [#^IPersistentVector needle #^IPersistentVector haystack] (letfn [(matching [candidate] (reduce + (map #(if (= %1 %

Help with my vec matching function

2009-12-28 Thread Robert Campbell
When given the following set of vecs #{[1 2 3] [9 8 3] [1 2] [1] [1 0 3 4] [1 2 3 4 5]} find the closest match to [1 2 3] (defn closest-match "Searches the haystack vecs for the closest match to the needle vec" [#^IPersistentVector needle #^IPersistentVector haystack] (second

Re: Leiningen Run ?

2009-12-13 Thread Robert Campbell
>> We have talked about adding a run task; >> if you're interested we could even get it in for the 1.0.0 release. I'd definitely like to see that. Right now my deployment sequence looks like: lein compile lein uberjar java -jar myapp-standalone.jar I imagine "lein run" should be able to execute

Re: FileNotFoundException (Access is denied)

2009-11-26 Thread Robert Campbell
ies like "myproj.clj" don't throw an error. I suppose that's being excessively safe for what's meant to be a simple example. On Thu, Nov 26, 2009 at 9:43 AM, Rob Wolfe wrote: > > > Robert Campbell napisał(a): >> I'm trying to write a file scanner very s

Re: Question about future

2009-11-25 Thread Robert Campbell
If you have this: user> (def f (future (Thread/sleep 2) :done)) #'user/f user> @f ; this immediate deref blocks for 20 sec, finally returning :block :done user> @f ; returns immediately :done What is actually happening when you call the first @f? You are waiting for the function to finish e

Re: FileNotFoundException (Access is denied)

2009-11-25 Thread Robert Campbell
Forgot to mention: running Clojure 1.0.0- and Clojure-Contrib 1.0-SNAPSHOT according to the pom.. On Thu, Nov 26, 2009 at 7:38 AM, Robert Campbell wrote: > I'm trying to write a file scanner very similar to the one on page 131 > of Stuart's book: > > (ns user >  (:

FileNotFoundException (Access is denied)

2009-11-25 Thread Robert Campbell
I'm trying to write a file scanner very similar to the one on page 131 of Stuart's book: (ns user (:use [clojure.contrib.duck-streams :only [reader]])) (defn scan [dir] (for [file (file-seq dir)] (with-open [rdr (reader file)] (count (filter #(re-find #"foobar" %) (line-seq rdr)

Re: roll call of production use?

2009-11-24 Thread Robert Campbell
I've deployed two small mashup apps which combine OpenCalais and our content repository to annotate documents with metadata (named entities, relationships, etc) and expose the results over the web. Good experiences all around, including with the clojure-http-client and saxon wrapper libs + Compojur

Transforming a Seq to a Map

2009-11-18 Thread Robert Campbell
Hey guys, I'm having some trouble finding a nice way to perform a map transformation I need. I need to transform this: [ {:a 1 :b 2 :c 3} {:a 4 :b 5 :c 6} {:a 7 :b 8 :c 9} ] into this: { {:a 1 :b 2} 3 {:a 4 :b 5} 6 {:a 7 :b 8} 9 } I wanted to use map, but each f in map only returns one value,

Re: Strange behavior seen when ints have leading zeros

2009-11-12 Thread Robert Campbell
Oh, that's pretty neat. Thanks! On Thu, Nov 12, 2009 at 2:36 PM, Fogus wrote: >> Why does Clojure hate 8's? :-) > > It doesn't.  By adding a leading zero you're telling Clojure that you > want octal numbers.  There is no number 08 in octal, instead to write > the base-10 number 8 you would use 0

Strange behavior seen when ints have leading zeros

2009-11-12 Thread Robert Campbell
C:\dev\clojure>java -cp clojure.jar clojure.lang.Repl Clojure 1.1.0-alpha-SNAPSHOT user=> (def grid1 [01 02 03 04 05 06 07]) #'user/grid1 user=> grid1 [1 2 3 4 5 6 7] user=> (def grid2 [01 02 03 04 05 06 07 08]) java.lang.NumberFormatException: Invalid number: 08 java.lang.Exception: Unmatched deli

Re: Converting to TCO

2009-11-08 Thread Robert Campbell
Mark: that looks a lot like the "collector" I learned about in The Little Schemer. I actually do have How to Design Programs, but I wanted to finish Seasoned Schemer first. I was poking around in SICP because of a Project Euler problem. Thanks for the tip! John: good catch. Can you confirm the di

Re: Converting to TCO

2009-11-08 Thread Robert Campbell
One correction: after playing with the functions a bit I noticed I screwed up, putting sqrt where I needed square. On Sun, Nov 8, 2009 at 4:43 PM, Robert Campbell wrote: > I've started reading SICP and I came across the Fermat primality test > implemented an Scheme. I reimplem

Converting to TCO

2009-11-08 Thread Robert Campbell
I've started reading SICP and I came across the Fermat primality test implemented an Scheme. I reimplemented it in Clojure and was able to switch the recursive call in fast-prime to TCO/recur, but I was unable to do the same for the exp-mod function. (defn exp-mod [base exp m] (cond (zero?

Re: feedback on this code

2009-10-27 Thread Robert Campbell
the server for each request. The purpose of sessions are to avoid exactly this hairy situation. I wrapped cart in a Ref in case multiple browser windows are open and there is a concurrent "add to cart" click. On Tue, Oct 27, 2009 at 12:41 PM, Timothy Pratley wrote: > > Hi Robert >

feedback on this code

2009-10-27 Thread Robert Campbell
Hey guys, I'm looking for _any_ feedback/thoughts on this Clojure code I wrote. I just feel like the entire thing is way too complex, but I'm not sure about how to simplify it. I wanted to try something "real world" so I made a simple shopping cart ref to put in a session: (defstruct cart :line-

Tricks for transforming a DB ResultSet into XLM?

2009-09-11 Thread Robert Campbell
I am using clojure.contrib.sql which gives me the typical Clojure ResultSet: a set of maps. Are there any tricks you've used in the past to transform this into XML? I was looking at Enlive since I've used it - and loved it - for HTML transformations in the past, but examples are few and I don't se

Re: Why do Enlive template functions return a seq instead of a str?

2009-07-13 Thread Robert Campbell
the past. Rob On Mon, Jul 13, 2009 at 12:37 AM, Christophe Grand wrote: > Hi ! > > On Sat, Jul 11, 2009 at 7:31 PM, Jarkko Oranen wrote: >> >> On Jul 11, 6:01 pm, Robert Campbell wrote: >> > Hey guys, >> > >> > I'm just curious why Christoph

Why do Enlive template functions return a seq instead of a str?

2009-07-11 Thread Robert Campbell
Hey guys, I'm just curious why Christophe chose to return seq instead of a str for Enlive for his template functions. Example: (deftemplate my-page-transformation "index.html" [message style] [:style] (content style) [:h1] (content message)) orchid> (my-page-transformation "my wonderful he

Re: Clojure box - loading book examples from "Programming Clojure"

2009-07-08 Thread Robert Campbell
> Wherever the files goes after C-x C-f ~/.emacs and then C-x C-s is where > emacs thinks your home directory is. I would just go with that. It's > normally in %appdata%, but it won't be there until you create it and save > it. yes, this is better than my #2 > Robert? Is that all you have in you

Re: Clojure box - loading book examples from "Programming Clojure"

2009-07-08 Thread Robert Campbell
1. Here is my .emacs I use for Clojure Box to load the Jars and add the proper paths to your classpath: (setq swank-clojure-extra-classpaths '()) (add-to-list 'swank-clojure-extra-classpaths "C:/Dev/clojure/clojure.jar") (add-to-list 'swank-clojure-extra-classpaths

Re: Save current namespace like a Smalltalk image

2009-07-08 Thread Robert Campbell
Phil - got it. It wouldn't be hard at all to write a script to monitor a directory, and any jar you throw in there gets exploded to the classpath dir like you use. That would make it pretty painless. > For the record, this is usually termed "dribbling" in the Lisp world. > It's very handy for deb

Re: Help with example from "A Field Guide to Genetic Programming"

2009-07-08 Thread Robert Campbell
That's it, that's exactly what I needed to complete this example. I'm pretty pumped because you guys have shown me a way to do it without macros and without manually managing a quoted tree structure. If it's okay, could somebody explain the difference between what's happening here: user> (def my

Re: Save current namespace like a Smalltalk image

2009-07-08 Thread Robert Campbell
x27;s the problem with adding urls to the current ClassLoader ? > > i've seen remarks to the effect that it doesn't work well, but i don't > understand why... > > c > > On 8 Jul 2009, at 17:37, Phil Hagelberg wrote: > >> >> Robert Campbell writes

Re: Save current namespace like a Smalltalk image

2009-07-08 Thread Robert Campbell
ution. Having said that, it's better than nothing. There are certainly times when I need to backtrack to previous definitions when I've down down the wrong path. Having a transcript is better than where I'm at today. On Wed, Jul 8, 2009 at 12:00 PM, John Harrop wrote: > On Wed

Re: Help with example from "A Field Guide to Genetic Programming"

2009-07-08 Thread Robert Campbell
u. > > I think once it is compiled a function is not easy to examine... so as > you alluded to the best alternative would be to keep the AST? > > Regards, > Tim. > > On Jul 7, 10:18 pm, Robert Campbell wrote: >> I'm trying to write the first basic GP example in thi

Re: Save current namespace like a Smalltalk image

2009-07-08 Thread Robert Campbell
ded that as much. > > Incidentally, I find the easiest way to port my code around is to > print it to the repl, then cut-and-paste it to etherpad, which I can > then access from anywhere (without having to save). Now if only there > was a hosted REPL that integrated an IDE nic

Re: Save current namespace like a Smalltalk image

2009-07-08 Thread Robert Campbell
spath without rebooting. Then I wouldn't be rebooting so often and I wouldn't need to be making images to save I'm-in-the-middle-of-a-thought state On Wed, Jul 8, 2009 at 10:57 AM, Daniel Lyons wrote: > > Robert, > > On Jul 8, 2009, at 2:13 AM, Robert Campbell wrote: > &

Save current namespace like a Smalltalk image

2009-07-08 Thread Robert Campbell
Hello, Sometimes I have pretty long REPL sessions where I'm trying to flesh out some ideas. When I close my instance of Clojure Box (Emacs based) I lose all the definitions I had worked out over time. Is there any way to dump namespace(s) to an image? It would be great to be able to load up some

Help with example from "A Field Guide to Genetic Programming"

2009-07-07 Thread Robert Campbell
I'm trying to write the first basic GP example in this free book: http://www.lulu.com/items/volume_63/2167000/2167025/2/print/book.pdf I've gotten a lot of the suppor methods working correctly (like fitness) but I'm having problem convering the pseudocode on page 14 for generating random expressi

Re: What books have helped you wrap your brain around FP and Clojure?

2009-06-06 Thread Robert Campbell
r this specific list Paul Stadig: Concepts of Programming Languages by Sebesta, suggested as more general than SICP On Sat, Jun 6, 2009 at 1:12 PM, Robert Campbell wrote: > Going beyond the language-specific Programming Clojure book, what > other books have best helped you make the (s

What books have helped you wrap your brain around FP and Clojure?

2009-06-06 Thread Robert Campbell
Going beyond the language-specific Programming Clojure book, what other books have best helped you make the (sometimes mind-bending) transition from OOP thinking to FP thinking? My bookshelf is piled high with OOP books like Design Patterns, Domain Driven Design, Analysis Patterns, etc. I've recen

STM & Resource transactions

2009-06-02 Thread Robert Campbell
I've been looking at using the clojure.set functions to create a simple in-memory database cache. Basically when the app boost up, load entire db into memory, work with it through the basic relational algebra functions provided. Any mutations (create/update/delete) would be wrapped in a simple fun

Re: clojure-contrib build error

2009-04-30 Thread Robert Campbell
If you're on Windows, please take a look at Clojure Box: http://clojure.bighugh.com/ It comes with an installer which sets you up with an Emac environment running Clojure + contrib. It's everything you need to get up in running in minutes. This is the path I took when I faced similar difficulti

Re: AppEngine in Atlanta this week

2009-04-27 Thread Robert Campbell
Is there any way you could record the presentation and post it on your site? On Mon, Apr 27, 2009 at 1:36 PM, slc wrote: > > If you are interested in Google AppEngine and live in the Atlanta > area ... > > Tuesday - Clojure > >    * Who: John Hum