> 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))
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
>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
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
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).
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
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
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,
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
,
>
> 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
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
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,
>>
>
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,
) 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
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
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)
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
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
/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
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
(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
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
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
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
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
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
> 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
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
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
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
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
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
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
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:
>
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)
>
--~-
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
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
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
hed element" " "div" ">" "<" "div" " " "class" "=\"" "foo" "\"" ">" "new content" " "div" ">" "" "")
>
> but now
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
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
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:
>
>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
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
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
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
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")))
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
> 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
>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))]
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
> ... 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
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 [
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
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
> 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
>... 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
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
> ... 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
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
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
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
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))
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
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
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
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
> 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
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
#'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
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
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
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:
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:
>
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
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
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
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
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
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=
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
> (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
> 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
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
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
> 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
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
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
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
>
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
>
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)
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
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.
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
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
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
> (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)]
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
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
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 - 100 of 169 matches
Mail list logo