Re: FAQ

2008-12-18 Thread Adrian Cuthbertson
> Suggestions for entries welcome here. > > > > Rich > Here's another that was a "gotcha" for me for an hour or two... Why after using map/reduce/for to change a java object does the object remain unchanged? (defn initv1 [myseq] (let [v (java.util.Vector.)] (for [x myseq] (.addElement v x)) v))

Re: How to encapsulate local state in closures

2008-12-26 Thread Adrian Cuthbertson
On Dec 22, 2:34 pm, "Mark Engelberg" wrote: > On Mon, Dec 22, 2008 at 4:23 AM, Parth Malwankar > > wrote: > > If I get it right, atoms are quite useful to maintain state > > in the context of a single thread with memoization and > > counter (within a thread) being two examples. > > No, RH said

Re: SLIME: trouble with java.lang.OutOfMemoryError

2009-01-11 Thread Adrian Cuthbertson
>I might look at the JEdit plugin though - JEdit is nice, for simple >editing, which might be good enough for me for now. I similarly haven't had time to relearn emacs and have used jedit quite sucessfully with jedit-mode. I keep one or more terminal window tabs open each with a REPL launched wit

Re: non recursive impl in presence of persistence?

2009-01-11 Thread Adrian Cuthbertson
Bear with the trials and tribulations (of grokking functional/clojure). It takes a few weeks of trying things out, absorbing the documentation and group archives, watching the group posts and then suddenly there are one or two "aha" moments and then the flood gates open! When you've crossed the t

Re: Common Lisp format function is now fully* CL-compatible

2009-01-29 Thread Adrian Cuthbertson
My compliments - this is a great addition to the clojure suite! On Thu, Jan 29, 2009 at 10:15 AM, Tom Faulhaber wrote: > > The cl-format library now implements the full* Common Lisp spec for > format (* = with the exception of a couple of things used by the > internals of the CL pretty printer).

Re: what does -> mean?

2009-01-31 Thread Adrian Cuthbertson
Some examples... ; using -> (f1 (f2 (f3 (f4 x ; can be "flattened" to (-> x f4 f3 f2 f1) Useful for nested maps... user=> (def m {:one {:a 1 :b 2 :c {:x 10 :y 11}}} ) #'user/m user=> (-> m :one :c :x) 10 user=> (-> x :one :b) 2 On Sun, Feb 1, 2009 at 5:31 AM, Jason Wolfe wrote: > > On Jan

Re: what does -> mean?

2009-02-01 Thread Adrian Cuthbertson
Sorry! That should have read; (-> m :one :b) 2 On Sun, Feb 1, 2009 at 5:13 PM, e wrote: > I was able to work through the first two examples, and thanks for those. I > will have to study maps more, I guess, to understand the last one. I don't > know where 'x' came from: >> >> user=> (-> x :one

Re: what does -> mean?

2009-02-01 Thread Adrian Cuthbertson
I would say "thread" is used here colloquially - i.e. "works the expr through the forms" and "form" is as defined in clojure.org/reader. On Sun, Feb 1, 2009 at 4:01 PM, e wrote: > is there a definition of "thread" somewhere, and a definition of "form" > somewhere? > > Thanks. > > On Sat, Jan 31,

Re: if-let

2009-02-08 Thread Adrian Cuthbertson
Here's one, I'm setting basedir to either :basedir in a map in *locs (a thread-local var) or to "." if :basedir was not found in the map... (let [basedir (if-let [bdir (:basedir *locs)] bdir ".")] ...) i.e bdir assumes the value of the test and if that is not false (or nil) returns it otherw

Re: if-let

2009-02-08 Thread Adrian Cuthbertson
, > > Am 08.02.2009 um 15:47 schrieb Adrian Cuthbertson: > >> Here's one, I'm setting basedir to either :basedir in a map in *locs >> (a thread-local var) or to "." if :basedir was not found in the map... >> >> (let [basedir (if-let [bdir (:basedir *loc

Idiomatic sub-hashmap

2009-02-13 Thread Adrian Cuthbertson
Hi, I have had need of a "sub" hash map function and implemented it as follows; (defn sub-hashmap "Return a sub map of hmap containing the specified keys." [hmap & ks] (reduce (fn [mm k] (assoc mm k (k hmap))) {} ks)) (sub-hashmap {:a 1 :b 2 :c 3} :a :c) ;=> {:c 3, :a 1} Is there a similar ex

Re: Idiomatic sub-hashmap

2009-02-13 Thread Adrian Cuthbertson
Thanks! On Fri, Feb 13, 2009 at 1:28 PM, Timothy Pratley wrote: > > Yup: select-keys > > user=> (select-keys {:a 1 :b 2 :c 3} [:a :c]) > {:c 3, :a 1} > > Regards, > Tim. > > On Feb 13, 8:01 pm, Adrian Cuthbertson > wrote: >> Hi, >> >

Re: with-local-vars vs. let

2009-02-13 Thread Adrian Cuthbertson
Have a look at compojure - a good example of with-local-vars is where a servlet request is executed. Each (get, post) request occurs in its entirety on a single (jetty or tomcat) thread. The compojure call to the application service function binds the http headers, servlet request parameters, etc,

Re: with-local-vars vs. let

2009-02-13 Thread Adrian Cuthbertson
) which just uses let. The html parameters are wrapped in *params* using binding rather than with-local-vars, so my example does not actually demonstrate with-local-vars, but rather just thread-local use of vars with binding. On Fri, Feb 13, 2009 at 5:19 PM, Konrad Hinsen wrote: > > On Feb

Re: Algebraic data types in clojure.contrib

2009-02-25 Thread Adrian Cuthbertson
Hmm, I get a stack overflow when trying that make macro. After using macroexpand-1... (with-meta (struct stuff 1 2) {:type (keyword (str *ns*) (name (quote stuff)))}) I still get the stack overflow. I'm on svn 1307, jdk 1.5 mac osx. Any ideas? Regards, Adrian. On Thu, Feb 26, 2009 at 7:08 AM, J

Modular composition/plugin architecture

2009-03-04 Thread Adrian Cuthbertson
Hi, How would one create a "plugin" modular composition using clojure functions/modules only (i.e without resorting to java interface/ plugin class implementations)? For example; ; say myutil/ut1.clj contains (ns 'myutil.ut1) (defn foo [] :foo-ut1) ; and myutil/ut2.clj contains (ns 'myutil.ut2)

Re: Modular composition/plugin architecture

2009-03-05 Thread Adrian Cuthbertson
gt;  ((load-file path) {}) ) > > ;mylib/lib1.clj > (defn libfoo [] >  (((load-plugin (if some-condition "myutil/ut1.clj" "myutil/ > ut2.clj")) :foo)) ) > > > > That's it. In Waterfront this design is integrated with the context > pattern whic

Re: filter-split

2009-03-07 Thread Adrian Cuthbertson
That's the beauty of this language - there are many ways to skin the cat! Here's a version using reduce... (defn filt-split [pred col] (reduce (fn [[a b] x] (if (pred x) [(conj a x) b] [a (conj b x)])) [[] []] col)) (filt-split even? [1 2 3 4 5 6 7 8]) [[2 4 6 8] [1 3 5 7]] But when you look a

Re: filter-split

2009-03-07 Thread Adrian Cuthbertson
/recur method. > ...I don't want to traverse the collection twice. Yes, I guess that even though each filter clause is lazy they each will pass through the entire collection once. On Sun, Mar 8, 2009 at 7:53 AM, David Sletten wrote: > > > On Mar 7, 2009, at 7:17 PM, Adrian Cuthber

Re: filter-split

2009-03-08 Thread Adrian Cuthbertson
returning a lazy sequence. > > My 0,02€, > > -- > Laurent > > 2009/3/8 Adrian Cuthbertson >> >> That's the beauty of this language - there are many ways to skin the cat! >> Here's a version using reduce... >> >> (defn filt-split [pred c

Re: filter-split

2009-03-08 Thread Adrian Cuthbertson
(separate even? (range 10))] [(nth a 4) (nth b 4)])) "Elapsed time: 67.004 msecs" [8 9] On Sun, Mar 8, 2009 at 12:11 PM, Adrian Cuthbertson wrote: > You're absolutely right... > > user=> (time (let [[a b] (separate even? (range 100))] (nth a 3

Re: filter-split

2009-03-08 Thread Adrian Cuthbertson
Hmm, on the same (micro admittedly) benchmark as above... (time (let [[a b] (unzip-with even? (range 10))] [(nth a 4) (nth b 4)])) "Elapsed time: 177.797 msecs" [8 9] that's a bit slower than both the previous versions. The reduce version does only apply the pred once per ite

class of java array

2009-03-09 Thread Adrian Cuthbertson
I have a java object that either contains a String or an array of Strings. (instance? java.lang.String obj... works fine for the String, but how would I check for the String Array? Thanks, Adrian. --~--~-~--~~~---~--~~ You received this message because you are s

Re: class of java array

2009-03-09 Thread Adrian Cuthbertson
Thanks Stuart, Bill - both answers are very useful. On Mon, Mar 9, 2009 at 6:58 PM, .Bill Smith wrote: > >> Here is one way: >> >>   (-> (into-array ["one" "two"]) (class) (.getComponentType)) >> -> java.lang.String >> (-> (to-array ["one" "two"]) (class) (.getComponentType)) >> -> java.lang.Obj

Re: generating a static method

2009-03-09 Thread Adrian Cuthbertson
HI Bill, I also tried the metadata tag and couldn't get it to work, but the following does... (ns gncls.MyStatic (:gen-class :methods [[say-hi [String] String]])) (defn -say-hi [this who] (str "Hi " who)) (defn -say-static-hi [who] (str "Hi " who)) user=> (compile 'gncls.MySta

Re: generating a static method

2009-03-10 Thread Adrian Cuthbertson
Hi Christophe, It works as per your example, but not with arguments to the method... ns gncls.MyStatic (:gen-class :methods [#^{:static true} [f [String] void ]])) (defn -f [s] ; also [this s] doesn't work (prn "Hi from " s )) (gncls.MyStatic/f "me") java.lang.Exception: No such var

Re: New in the group and question about Java interaction

2009-03-10 Thread Adrian Cuthbertson
> One more question: is there a way to call a function similar to > reloadClasses in Clojure? If so, it would be my solution. Yep, I work with a multi-tab console with a rlwrap repl window and another window for builds (ant) and other general stuff, then I use the clojure load function to reload

Re: VimClojure 2

2009-03-13 Thread Adrian Cuthbertson
I think the " could be a problem in generating your path in .vimrc. Try... let vimclojure#NailgunClient='/your_path/vimclojure-2.0.0/ng' and don't forget also for .vimrc let g:clj_want_gorilla = 1 Rgds, Adrian. On Fri, Mar 13, 2009 at 2:09 AM, Yasuto TAKENAKA wrote: > > In my environment, same

Re: VimClojure 2

2009-03-13 Thread Adrian Cuthbertson
he only problem I had was in getting vim to see the ng client but that was solved as per my previous post. Hope that helps. On Fri, Mar 13, 2009 at 1:51 PM, Mark Volkmann wrote: > > On Fri, Mar 13, 2009 at 2:50 AM, Adrian Cuthbertson > wrote: >> >> I think the " could

Re: March 20th 2009 Rich Hickey Appreciation Day!

2009-03-20 Thread Adrian Cuthbertson
I wrote my first program in Fortran in 1975. Since then I've worked in Assember, Jcl, Rexx, Lisp 370, C, C++, VB (the low-light of my career), and a host of scripting/macro tools. I started with Java in 1998 and my own business in 2002 (web apps and backends with Java/Jsp/Js). I became disillusion

Re: LZW compression

2009-03-30 Thread Adrian Cuthbertson
There's apache commons; http://commons.apache.org/compress/ and Java also has a built-in zip/gzip library - see java.util.zip in the Java docs. Adrian. On Mon, Mar 30, 2009 at 10:19 PM, Sean wrote: > > Hi, > Does anyone know of a good compression library in java or clojure?  A > quick google di

Re: basic question on structuring refs

2009-04-01 Thread Adrian Cuthbertson
I came across a thread from Jul '08 which seems to be the definitive on handling side-effects within transactions - http://groups.google.co.za/group/clojure/browse_thread/thread/d645d77a8b51f01/667e833c1ea381d7 Adrian. On Wed, Apr 1, 2009 at 9:24 AM, Timothy Pratley wrote: > > Hi Korny, > > > T

Re: Questions about Clojure and Common Lisp

2009-04-01 Thread Adrian Cuthbertson
I have used Java and Jsp for many years as the platform for my business offerings. All new development is now being done in Clojure - I am comfortable (nay, delighted) with it's stability and viability. On Wed, Apr 1, 2009 at 6:12 PM, Jon Harrop wrote: > > On Wednesday 01 April 2009 16:51:49 Jo

Re: Keeping a ref and a DB in sync

2009-04-03 Thread Adrian Cuthbertson
Perhaps you could do the db update as an agent action and then the ref update within the agent action if it is successful - see http://groups.google.co.za/group/clojure/browse_thread/thread/d645d77a8b51f01/667e833c1ea381d7 Regards, Adrian. On Fri, Apr 3, 2009 at 11:02 AM, Brian Carper wrote: >

Re: introspect namespace ?

2009-04-05 Thread Adrian Cuthbertson
Nice case of clojure reductio :-) On Mon, Apr 6, 2009 at 7:51 AM, Stephen C. Gilardi wrote: > (str *ns*) > > On Apr 6, 2009, at 1:27 AM, Kevin Downey wrote: > >> (.toString *ns*) >> >> On Sun, Apr 5, 2009 at 12:39 PM, Stephen C. Gilardi >> wrote: >>> >>> >>>       (-> *ns* ns-name name) > --~-

Re: Enlive questions

2009-04-14 Thread Adrian Cuthbertson
I'm just starting out on Enlive - any examples added would be welcome. I'll also accumulate some documentation as I go through the learning curve. Thanks, Adrian. On Wed, Apr 15, 2009 at 5:05 AM, David Nolen wrote: > One early thought, would you like me to extend the number of examples? I'm > r

Re: Oracle and Clojure

2009-04-20 Thread Adrian Cuthbertson
There are some precedents - the acquisition of SleepyCat (berkeley db, et al) - still readily available under GPL compatible licenses. On Tue, Apr 21, 2009 at 7:47 AM, AlamedaMike wrote: > >>> I can see a lot of technologies that drive the open source world, and this >>> group, being compromise

Enlive tutorial

2009-04-22 Thread Adrian Cuthbertson
I've uploaded a file http://groups.google.co.za/group/clojure/web/enlive-tut1.txt?hl=en which is a basic tutorial on getting started with Enlive (the html transformation library). Christophe, this is intended as a contribution to the Enlive project, so you're welcome to use it as part of the Enli

Re: Enlive tutorial

2009-04-23 Thread Adrian Cuthbertson
hed element" " "div" ">" "<" "div" " " "class" "=\"" "foo" "\"" ">" "new content" " "div" ">" "" "") > > but now

Re: How to have one lib with source in multiple files

2009-04-23 Thread Adrian Cuthbertson
billh04, have a look at the compojure project (http://github.com/weavejester/compojure/tree/master). In that James uses an "immigrate" function which may be useful to you. Also the structure used is a good example of a reasonably large, quite complex project. Hth, Adrian. On Fri, Apr 24, 2009 at

Re: more vimclojure

2009-04-28 Thread Adrian Cuthbertson
Likewise a real fan! In the absence of an issue tracker at this time, could I mention the following relating to indenting; (defn xxx "Some stuff... (defmacro xxx "Some stuff... (defroutes xxx "Some stuf... That is, the indenting starts under the argument for "non-recognis

Re: Help: Java code works, Clojure code doesn't

2009-05-05 Thread Adrian Cuthbertson
Perhaps you could try calling your java class directly from the repl... (TutorialConnect1.) That might highlight the problem - your java stack strace might give some clues. It does sound like a classpath problem of some sort. Rgds, Adrian. On Tue, May 5, 2009 at 6:04 PM, Sean Devlin wrote: >

Re: Writer turned programmer seeks string processing advice

2009-05-06 Thread Adrian Cuthbertson
>2. Would it be better (or even possible) to learn about matching and >string processing in general, independent of the programming language? Hi Dirk, it's a pretty advanced topic and quite difficult to get one's head around (at least for me), but monads (both clojure and in general) may be of in

Re: Feedback on new persistentmatrix datatype

2009-05-06 Thread Adrian Cuthbertson
If you haven't seen it yet, the set module (clojure.set) provides a basic implementation of set relational algebra. May be useful for this work? See clojure.org data structures and the source for clojure/set.clj in the clojure source. Rgds, Adrian. On Wed, May 6, 2009 at 7:05 PM, Anand Patil w

Re: AIML pattern matcher design

2009-05-08 Thread Adrian Cuthbertson
I found that after a couple of months of working with Clojure, my whole perspective on thinking about the problem domain and its possible abstractions changed really significantly. An approach that might benefit you is to spend a while dabbling with some repl explorations of some of the key Clojur

Re: Launching apps

2009-05-08 Thread Adrian Cuthbertson
For production server systems running under Linux, I've used apache commons daemon to get java apps launched, for example under root to get port 80 and then su'd to run under the app (non-privileged) userid. The advantage is these can be automatically restarted when the server reboots, or services

Re: String.getBytes does not translate to byte[]?

2009-05-12 Thread Adrian Cuthbertson
Using a java nio ByteBuffer to simulate what you're doing, the following works ok for me; (defmulti t-str class) (defmethod t-str String [s] (java.nio.ByteBuffer/wrap (.getBytes s "us-ascii"))) (t-str "abcde") # (defmethod t-str String [s] (java.nio.ByteBuffer/wrap (.getBytes s "utf-8")))

Re: String.getBytes does not translate to byte[]?

2009-05-12 Thread Adrian Cuthbertson
Well, under the covers the str function applies the java "toString" method to any passed in object and hence the result could for some reason be different to the original String object passed in. I think this could occur if the object subclasses String, but has a different representation (i.e a di

Re: Speed up network transfers?

2009-05-15 Thread Adrian Cuthbertson
> But it turns out that this is rather slow. What would be some methods > to speed this up? You could also wrap your input and output stream's with java.util.zip.GZIPInputStream and GZIPOutputStream to compress/decompress the data either side. They allow you to specify buffer sizes, so you could

Re: Override the + operator for a 'struct'

2009-05-16 Thread Adrian Cuthbertson
>Yes, the general consensus is that basic math needs to be as fast as >possible, even at the expense of some flexibility. It's worth noting here that one can also use binding to override other than arithmetic core functions; (defn ustr [s] (binding [clojure.core/str (fn [x] (.toUpperCase x))]

Re: Question about building modular code in Clojure

2009-05-17 Thread Adrian Cuthbertson
Hi Mark, I've used the following macro to achieve something like what you're doing; In the file/namespace module (say eg_globs/fns.clj); (ns eg-globs.fns) (declare *gravity*) (defmacro with-grav [grav & body] `(let [gr# ~grav] (binding [*gravity* gr#] ~...@body))) (defn say-gra

Re: Question about building modular code in Clojure

2009-05-18 Thread Adrian Cuthbertson
> ... signs a contributor agreement. If he wants to create his own > version of the module for his own personal use, in which he swaps out > my function for his faster one, there appears to be no good way to do > this, short of copying my entire file, commenting out my function, ... I think Stua

Re: Question about building modular code in Clojure

2009-05-18 Thread Adrian Cuthbertson
On Mon, May 18, 2009 at 11:29 AM, Mark Reid wrote: > ... > test=> (lcm 4 6) > 24 > > > Maybe a variant of ns could be written that allows the overriding of > specific functions? e.g., > I know I keep plugging this - sorry - but it just keeps surfacing as a solution; (lcm 4 6) 12 (binding [

Re: Question about building modular code in Clojure

2009-05-18 Thread Adrian Cuthbertson
Aha! Thank you for clarifying that. Reinforces your point on monkey-patching :). I will read your blog post with careful attention. Adrian. On Mon, May 18, 2009 at 12:42 PM, Konrad Hinsen wrote: > > On May 18, 2009, at 11:58, Adrian Cuthbertson wrote: > >> I know I keep pluggi

Re: Clojure as a Java lib documentation / examples?

2009-05-21 Thread Adrian Cuthbertson
Check out clojure.org - focus on java interop, compilation and class generation. Mark Volkmann's http://java.ociweb.com/mark/clojure/article.html has a good general clojure overview and nice examples. Gen-class and proxy are the main tools you'll need for exposing your clojure libraries as java ap

Re: Clojure for high-end game development

2009-05-21 Thread Adrian Cuthbertson
> Game developement? Some work has been done on using clojure with jogl (the java opengl library) Search this forum with "jogl" for details. > with the Android platform I'm pretty sure there is also an android implementation of clojure. Again, search this forum for "android". Rgds, Adrian. On

Re: Clojure at JavaOne

2009-05-21 Thread Adrian Cuthbertson
>... impact part can be merged with the "business application" mindset by >generating a report that includes the data visualization (I think PDF >generation is built into processing). I've been doing some work with enlive and XHtmlRenderer - it's a pretty awesome way of generating (business, medi

Re: "run" macro for "executable namespaces"

2009-06-02 Thread Adrian Cuthbertson
Thanks Steve! That's very neat. Pretty much a "canonical" macro example. Adrian. On Tue, Jun 2, 2009 at 5:50 AM, Stephen C. Gilardi wrote: > Here's a macro I've found useful for loading and running Clojure programs > from the REPL: > >  (defmacro run >    "Loads the specified namespace and invo

Re: You know you've been writing too much Clojure when...

2009-06-03 Thread Adrian Cuthbertson
> ... You know you've been writing too much Clojure when... You see a cartoon swearword @^#!>! and you think it's clojure meta-data! -Adrian. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post

Re: Reading files with nio.

2009-06-10 Thread Adrian Cuthbertson
Thanks, these are useful posts. On Thu, Jun 11, 2009 at 4:49 AM, Nicolas Buduroi wrote: > > I've got an even faster version using memory-mapped file I/O. It also > simplify the code a little bit. > > (defn fast-read-file [#^String filename #^String charset] >  (with-open [cin (. (new FileInputStr

Re: Simple idiom in clojure, mutate a value

2009-06-11 Thread Adrian Cuthbertson
You could do something like; (let [updated-val (loop [updateable start-value line (.readline reader)] (if (or (empty? line) (> line-num max-num)) (+ updateable (somefunc)) (recur (.readLine reader)] (do-something with updated-val)) Rgds, Adrian. On Thu, Jun 11, 2009 at 8:34

Re: Simple idiom in clojure, mutate a value

2009-06-11 Thread Adrian Cuthbertson
On Thu, Jun 11, 2009 at 8:38 PM, Adrian Cuthbertson wrote: > You could do something like; > > (let [updated-val (loop [updateable start-value line (.readline reader)] >    (if (or (empty? line) (> line-num max-num)) >      (+ updateable (somefunc)) >      (recur (.read

Re: Simple idiom in clojure, mutate a value

2009-06-11 Thread Adrian Cuthbertson
ur (.readLine r) newrec) (finally (.close r) On Thu, Jun 11, 2009 at 8:48 PM, Adrian Cuthbertson wrote: > Re-read your example - that should have been; > > (let [updated-val (loop [updateable 0 line (.readline reader)] >   (if (or (empty? line) (> line-num max-num))

Re: Mnesia like?

2009-06-16 Thread Adrian Cuthbertson
There's also Berkeley DB Java Edition, now owned by Oracle (it has a GPL compatible license). It's an excellent, robust, embedded, fully transactional key-store db. See http://www.oracle.com/database/berkeley-db/je/index.html On Tue, Jun 16, 2009 at 3:26 PM, Jonah Benton wrote: > > Another schem

Re: the inverse function of load or load-file

2009-06-23 Thread Adrian Cuthbertson
You can use the following; (defn frm-save "Save a clojure form to file." [#^java.io.File file form] (with-open [w (java.io.FileWriter. file)] (binding [*out* w *print-dup* true] (prn frm (defn frm-load "Load a clojure form from file." [#^java.io.File file] (with-open [r (java.i

Re: the inverse function of load or load-file

2009-06-23 Thread Adrian Cuthbertson
Sorry, (prn frm) should have been (prn form). On Wed, Jun 24, 2009 at 5:33 AM, Adrian Cuthbertson < adrian.cuthbert...@gmail.com> wrote: > You can use the following; > > (defn frm-save > "Save a clojure form to file." > [#^java.io.File file form] > (with

Re: I must be blind. No matching method found?

2009-06-24 Thread Adrian Cuthbertson
There was a post a few days ago about a StringBuilder problem on MacOs Java 1.5. I think this is the same problem (i.e Java not Clojure). Rgds, Adrian. On Thu, Jun 25, 2009 at 4:52 AM, Cosmin Stejerean wrote: > > > On Wed, Jun 24, 2009 at 8:59 PM, CuppoJava wrote: > >> >> Hi guys, >> I'm having

Re: [OT] Convincing others about Clojure

2009-06-25 Thread Adrian Cuthbertson
> I need some pointers on this. This is a really crucial thing for me and > any help will be appreciated. Here's one - better warn them not to let on what the startup is. Someone here will get it to market an order of magnitude quicker than they will on some other platform :-). On Thu, Jun 25, 2

Re: Speedy accessors for the trees of clojure.xml

2009-06-29 Thread Adrian Cuthbertson
As a matter of interest, one can get the keys keys in an unknown struct by allocating an empty struct; (def st (create-struct :a :b :c)) (keys (struct st)) (:a :b :c) -Adrian. On Tue, Jun 30, 2009 at 12:14 AM, samppi wrote: > > Wonderful. Thanks for the answer. > > On Jun 29, 2:47 pm, Rich Hic

Re: Speedy accessors for the trees of clojure.xml

2009-06-29 Thread Adrian Cuthbertson
#'user/test-2-s > user=> (def accessor-a (accessor test-s :a)) > #'user/accessor-a > user=> (accessor-a (struct test-2-s 5 3 2)) > java.lang.Exception: Accessor/struct mismatch (NO_SOURCE_FILE:0) > > But thanks for the tip anyway! > > On Jun 29, 6:47 pm, Adrian Cu

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Adrian Cuthbertson
You could use assoc-in... (def rms (ref {:key1 {:key2 {:key3 #{)) (dosync (alter rms assoc-in [:key1 :key2 :key3] "foo")) {:key1 {:key2 {:key3 "foo"}}} Rgds, Adrian. On Sun, Jul 5, 2009 at 6:07 AM, Rowdy Rednose wrote: > > Say I have a data structure like this > > (def ref-map-map-map-set

Re: Calling static methods on a variable holding a class

2009-07-06 Thread Adrian Cuthbertson
You can call the static method directly on the class name; (java.nio.ByteBuffer/allocate 1024) or just (ByteBuffer/allocat 1024) if it's imported. Rgds, Adrian. On Tue, Jul 7, 2009 at 2:16 AM, Nicolas Buduroi wrote: > > I've just figured out that the macro version in the allocate example > ca

Re: Calling static methods on a variable holding a class

2009-07-06 Thread Adrian Cuthbertson
Hi Nicolas, sorry, that last post missed the second part, I meant to add; If you know the method you wish to call, do you not know the class and can thus call the static method directly? -Adrian. On Tue, Jul 7, 2009 at 5:21 AM, Adrian Cuthbertson < adrian.cuthbert...@gmail.com> wrote:

Re: Performance question (newbie)

2009-07-15 Thread Adrian Cuthbertson
It's also worth searching this group for 'performance' and checking out the discussions over the past few months. There've been lots of queries about many different aspects of performance and some really good advice dispensed. - Adrian. On Wed, Jul 15, 2009 at 3:39 PM, Frantisek Sodomka wrote: >

Re: How to achieve indirection?

2009-07-16 Thread Adrian Cuthbertson
You can also pass functions (and closures) around in a map; (defn my-app-uses-do-something [map-with-cfg-stuff] ... ((:do-something map-with-cfg-stuff) 13 19)) ) (defn do-something-quickly [x y] ... (defn do-something-elegantly [x y] ... (my-app-uses-do-something {:do-something do-somet

Re: Can (genclass) be changed to operate when not compiling?

2009-07-21 Thread Adrian Cuthbertson
I get around this for servlets by combining gen-class and proxy in my servlet file; (ns my-servlets.MyServlet (:import (javax.servlet.http HttpServlet HttpServletRequest HttpServletResponse)) (:gen-class :extends HttpServlet) ) (defn req-do [#^HttpServlet svlt #^HttpServletRequest r

Re: the point of next vs rest?

2009-08-09 Thread Adrian Cuthbertson
Hi Rob, have a look at http://clojure.org/sequences and then on that page there's a reference to http://clojure.org/lazy, which explains the evolution of the lazy/eager sequences. Next is used for eager cases (e.g loop/recur) and rest for lazy-seq. Should make sense if you check out those referenc

Re: Request for Discussion: user created reader macros

2009-08-13 Thread Adrian Cuthbertson
Hmm, not so sure this is related, but I've often thought it would be great to have some way of having "embedded" source of other types as a "special" string defined as normal in the clojure source but marked in such as way that the editor (vim, emacs, etc) could recognise this and do formatting, s

Re: Jwt from Clojure?

2009-08-17 Thread Adrian Cuthbertson
Hi Raphaël, If you're going to drive your app (and server) from clojure, then you can use Compojure's jetty.clj module. This allows you to create a servlet holder (in which you can add an instantiated Jwt servlet on a jetty url path). Compojure also supports the Ring protocol, so you can also the

Re: How to generate a hash map from a list

2009-08-24 Thread Adrian Cuthbertson
For completeness we should include a loop/recur pattern; (defn fzipmap [f col] "Takes a col, applies f to each element and generates a hash map keyed on each element of col." (loop [col (seq col) mp {}] (if col (recur (next col) (assoc mp (first col) (f (first col mp))) user=

Re: A little discovery: abbreviated-namespace-qualified keywords

2009-08-24 Thread Adrian Cuthbertson
Also just what I needed - thanks! On Mon, Aug 24, 2009 at 8:05 PM, Dragan Djuric wrote: > > It may look silly, but that's just what I need AND the last time I > checked > it didn't work! > Now it does :) > > Thanks! > >> On Aug 24, 7:14 pm, samppi wrote: >> I just discovered something cool that

Re: How to generate a hash map from a list

2009-08-24 Thread Adrian Cuthbertson
> (defn fzipmap [f col] > "Takes a col, applies f to each element and generates a Note that the args should have come after the doc string! On Tue, Aug 25, 2009 at 6:20 AM, Adrian Cuthbertson wrote: > For completeness we should include a loop/recur pattern; > > (defn fzipm

Re: How to migrate definitions to another namespace ?

2009-08-29 Thread Adrian Cuthbertson
> Is there a way to unregister some names from a namespace without reloading it > ? This is a bit trickier than one might think. An example illustrates this; Given two files, a.clj... (ns a) (defn stuff-a [] :stuff-a) (defn hello [] :hello) And b.clj... (ns b) (defn stuff-b [] :stuff-b) Say w

Re: How to represents a Big text file using sequence?

2009-08-31 Thread Adrian Cuthbertson
I mostly revert to good ole loop/recur for these large file processing exercises. Here's a template you could use (includes a try/catch so you can see errors as you go); (import '(java.io BufferedReader FileReader PrintWriter File)) (defn process-log-file "Read a log file tracting lines matchi

Re: minor grievance with arithmetic on characters

2009-09-07 Thread Adrian Cuthbertson
Clojure's compare; (compare \a \b) -1 user=> (doc compare) - clojure.core/compare ([x y]) Comparator. Returns 0 if x equals y, -1 if x is logically 'less than' y, else 1. Same as Java x.compareTo(y) except it also works for nil, and compares numbers and collections

Re: Content negotiation?

2009-09-09 Thread Adrian Cuthbertson
> Could you put it on GitHub anyway? It would be a good way to evaluate > it. +1 - I'd be interested in using it. - Adrian. On Thu, Sep 10, 2009 at 6:40 AM, Sean Devlin wrote: > > Could you put it on GitHub anyway?  It would be a good way to evaluate > it. > > On Sep 10, 12:36 am, Richard New

Re: Clojure Golf – Episode 2: Largest Prime Factor

2009-09-10 Thread Adrian Cuthbertson
What about a golf competition on the golf competition scorer? Then we can evaluate that using; (defmacro score-scorer [scorer] ... ) :) - Adrian On Thu, Sep 10, 2009 at 8:12 AM, Christophe Grand wrote: > > I propose to compute the score of a golf competition entry using this > function: > (d

Re: Class function alwayrs returns java.lang.class??

2009-09-10 Thread Adrian Cuthbertson
You need to pass the object to (class, e.g... user=> (class "a") java.lang.String user=> (class String) java.lang.Class user=> (class 1) java.lang.Integer (So String is actually a Class object). Rgds, Adrian. On Thu, Sep 10, 2009 at 5:00 PM, Gorsal wrote: > > Hello. I'm trying to use (class St

Re: Issue with casting integers with clojure.lang.ifn's

2009-09-14 Thread Adrian Cuthbertson
Hi Jeff, you're using defn which defines a function instead of def which defines a var; (def vect1 [1 2 3 4]) #'user/vect1 user=> (* (count vect1) 5) 20 Rgds, Adrian. On Mon, Sep 14, 2009 at 8:05 AM, Jeff Gross wrote: > > I have a vector that I need to count the size of and do a simple math >

Re: Issue with casting integers with clojure.lang.ifn's

2009-09-14 Thread Adrian Cuthbertson
Alternatively, if really meant to use defn then it should have been; (defn vect1 [] [1 2 3 4]) #'user/vect1 user=> (* (count (vect1)) 5) 20 On Mon, Sep 14, 2009 at 2:28 PM, Adrian Cuthbertson wrote: > Hi Jeff, you're using defn which defines a function instead of def >

Re: loop-recur for string handling

2009-09-17 Thread Adrian Cuthbertson
There's also re-split in str-utils in clojure.contrib; (use 'clojure.contrib.str-utils) (re-split #"\s" "The quick brown fox") => ("The" "quick" "brown" "fox") You can then use all the good clojure collection functions; (def words (re-split #"\s" "The quick brown fox")) (some #{"brown"} words)

Re: java/scala oneliner

2009-09-17 Thread Adrian Cuthbertson
If y're Sco'ish... -> 59 (dotimes[i 4](println"Appy Birthdy"({2"D'r XXX"}i"To Ye"))) Appy Birthdy To Ye Appy Birthdy To Ye Appy Birthdy D'r XXX Appy Birthdy To Ye On Fri, Sep 18, 2009 at 6:35 AM, David Nolen wrote: > hiredman in the lead! > (dotimes[i 4](println"Happy Birthday"({2"Dear XXX"}i

Re: "If you wish to have a version for off-line use...

2009-09-20 Thread Adrian Cuthbertson
Generally I use the source code for clojure and contrib documentation. I open an instance of Jedit on the source directory and use it's search/grep facilities to find what I'm looking for. It also helps in familiarising with the clojure and contrib implementations and learning the techniques used.

Re: re-sub / re-gsub with back-reference?

2009-09-29 Thread Adrian Cuthbertson
I was just trying out str-utils2 when Stuart posted. Here's an example; (require '[clojure.contrib.str-utils2 :as s]) (s/replace "hello Jung" #"hello (\S+)" #(str "hello, how are you "(% 1))) "hello, how are you Jung" Rgds, Adrian. On Tue, Sep 29, 2009 at 4:58 PM, Stuart Sierra wrote: > > Hi

Re: Using 'future' ?

2009-10-18 Thread Adrian Cuthbertson
The following seems to do it; (defmacro with-thread [nm & body] `(let [thread# (Thread. (fn [] (do ~...@body)))] (if ~nm (.setName thread# ~nm)) (.start thread#) thread#)) (with-thread "foo" (println "HasdfasdfasdfasdfasdfasdfasdfasdfI")) # user=> HasdfasdfasdfasdfasdfasdfasdfasdfI

Re: Using 'future' ?

2009-10-18 Thread Adrian Cuthbertson
quot; (println "HasdfasdfasdfasdfasdfasdfasdfasdfI"))) (.start th) nil HasdfasdfasdfasdfasdfasdfasdfasdfI (.getName th) "foo" - Adrian. On Mon, Oct 19, 2009 at 7:18 AM, Adrian Cuthbertson wrote: > The following seems to do it; > > (defmacro with-thread [nm & body] >  `(let [thre

Re: idiom questions

2009-10-30 Thread Adrian Cuthbertson
> (let [x nil] > ;; do something and modify 'x' > ) > >how does one modify the value of 'x' ? Hi Chick, there's nothing stopping you re-binding x within the let construct, eg; (defn myfn [x] (let [x (if (or (nil? x) (< x 0.2)) 0.0 x) x (if (>= x 0.8) 1.0 x)]

Another "closure" available

2009-11-07 Thread Adrian Cuthbertson
Hmm, someone else has made another "closure" available :). http://googlecode.blogspot.com/2009/11/introducing-closure-tools.html -Adrian. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to t

Re: roll call of production use?

2009-11-24 Thread Adrian Cuthbertson
For a data analysis/reporting application, I use colt for some matrix processing, joda time for period calculations, jfreechart to generate charts, an adaptation clj-html to create some dynamic html, also now some StringTemplate templates to bring in and manipulate static content and finally all th

Re: Clojure as a first programming language?

2009-12-01 Thread Adrian Cuthbertson
Hi Towle, Judging by the articulateness of your post, I would say that Clojure would definitely be an ideal language for what you are looking for. It is not "handed to you on a plate" and you will have to engage deeply to achieve your goals, but if you do so, along with the increasingly prolific d

  1   2   >