: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 *locs)] bdir .)]
...)
i.e bdir assumes the value of the test
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
Thanks!
On Fri, Feb 13, 2009 at 1:28 PM, Timothy Pratley
timothyprat...@gmail.com 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 adrian.cuthbert...@gmail.com
wrote:
Hi,
I have had need of a sub
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,
, at 15:35, Adrian Cuthbertson wrote:
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
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,
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)
it. In Waterfront this design is integrated with the context
pattern which I described here a few days ago.
Hope that helps.
--
Itay Maman
http://javadots.blogspot.com
On Mar 5, 6:48 am, Adrian Cuthbertson adrian.cuthbert...@gmail.com
wrote:
Hi,
How would one create a plugin modular
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
.
...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 da...@bosatsu.net wrote:
On Mar 7, 2009, at 7:17 PM, Adrian Cuthbertson wrote
? (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
adrian.cuthbert...@gmail.com wrote:
You're absolutely right...
user= (time (let [[a b] (separate even? (range 100))] (nth a 3)))
Elapsed time
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 item
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.MyStatic)
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 y.taken...@gmail.com wrote:
In my
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
r.mark.volkm...@gmail.com wrote:
On Fri, Mar 13, 2009 at 2:50 AM, Adrian Cuthbertson
adrian.cuthbert...@gmail.com 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
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 francoisdev...@gmail.com wrote:
Hi,
Does anyone know of a good compression library in java or
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
timothyprat...@gmail.com
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
Nice case of clojure reductio :-)
On Mon, Apr 6, 2009 at 7:51 AM, Stephen C. Gilardi squee...@mac.com 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 squee...@mac.com
wrote:
(- *ns* ns-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 dnolen.li...@gmail.com wrote:
One early thought, would you like me to extend the
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 limejui...@yahoo.com wrote:
I can see a lot of technologies that drive the open source world, and this
group,
)
Adrian Cuthbertson a écrit :
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
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-recognised
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
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
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
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)
#HeapByteBuffer java.nio.HeapByteBuffer[pos=0 lim=5 cap=5]
(defmethod t-str String [s]
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
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
... 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
On Mon, May 18, 2009 at 11:29 AM, Mark Reid mark.r...@gmail.com 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
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
konrad.hin...@laposte.net wrote:
On May 18, 2009, at 11:58, Adrian Cuthbertson wrote:
I know I keep
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
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 Fri,
... 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, media,
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 squee...@mac.com wrote:
Here's a macro I've found useful for loading and running Clojure programs
from the REPL:
(defmacro run
Loads the specified namespace
... 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 to
Thanks, these are useful posts.
On Thu, Jun 11, 2009 at 4:49 AM, Nicolas Buduroinbudu...@gmail.com 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
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-read your example - that should have been;
(let [updated-val (loop [updateable 0 line (.readline reader)]
(if (or (empty? line) ( line-num max-num))
(+ updateable (somefunc))
(recur (.readLine reader)]
(do-something-with updated-val))
I.e initialising updateable to 0.
On
Here's a fuller example of similar techniques extracted from a working
program. It reads a file of lines and applies some transformations and
accumulates a vector of records which it finally returns;
(defn some-fn
Read a file and return a vector of its records.
[fpath]
(let
[r
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 Bentonjo...@jonah.com wrote:
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
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-open [w (java.io.FileWriter. file
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 cstejer...@gmail.comwrote:
On Wed, Jun 24, 2009 at 8:59 PM, CuppoJava
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,
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 rbysam...@gmail.com wrote:
Wonderful. Thanks for the answer.
On Jun 29,
: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 Cuthbertson adrian.cuthbert...@gmail.com
wrote:
As a matter of interest, one can get the keys keys
Johannesburg, South Africa.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
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 mark.engelb...@gmail.com wrote:
On Mon, Dec 22, 2008 at 4:23 AM, Parth Malwankar
parth.malwan...@gmail.com 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
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 with
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
My compliments - this is a great addition to the clojure suite!
On Thu, Jan 29, 2009 at 10:15 AM, Tom Faulhaber tomfaulha...@gmail.com 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
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 jawo...@berkeley.edu
Sorry! That should have read;
(- m :one :b)
2
On Sun, Feb 1, 2009 at 5:13 PM, e evier...@gmail.com 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=
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 evier...@gmail.com wrote:
is there a definition of thread somewhere, and a definition of form
somewhere?
Thanks.
On Sat, Jan
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 rowdy.redn...@gmx.net wrote:
Say I have a data structure like this
(def
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 nbudu...@gmail.com wrote:
I've just figured out that the macro version in the
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:
You can
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
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
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
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,
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
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=
(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
Cuthbertsonadrian.cuthbert...@gmail.com wrote:
For completeness we should include a loop/recur pattern;
(defn
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 we
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
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 Devlinfrancoisdev...@gmail.com wrote:
Could you put it on GitHub anyway? It would be a good way to evaluate
it.
On Sep 10,
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 Grandchristo...@cgrand.net wrote:
I propose to compute the score of a golf competition entry using
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 s...@tewebs.com wrote:
Hello. I'm trying to use
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 j3f...@gmail.com wrote:
I have a vector that I need to count the size of and do a
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
adrian.cuthbert...@gmail.com 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)
= brown
(some
If y're Sco'ish... - 59
(dotimes[i 4](printlnAppy Birthdy({2D'r XXX}iTo 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 dnolen.li...@gmail.com wrote:
hiredman in the lead!
(dotimes[i 4](printlnHappy
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
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
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))
#Thread Thread[foo,5,main]
user=
(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)]
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
(reduce (fn [model f] (assoc model f (inc (get model f 1
{} features))
Do Clojurians usually arrange like that? Can it be rearrange for more
understandability?
I would write it exactly like that. What happens as you become
familiar with Clojure is that the patterns of the api
Hi Greg, here's a sample but realistic pattern of the sort of thing
you're doing;
(import '(java.io BufferedReader FileReader File IOException)
'(bqutils BQUtil))
(defn samp-loop
Read a csv file containing user records.
[#^String fpath]
(with-open [r (BufferedReader. (FileReader. (File.
Hi Sean,
The background to this lies in the implementation of lazy sequences -
seq returns an implementation of ISeq for the data structure in
question - nil when there are no elements in the structure. Have a
look at http://clojure.org/sequences and also http://clojure.org/lazy
which gives the
How about the intricacies of syntax-quotes and in particular, nested
syntax-quotes?
Yeah, +1.
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated
In the doc for dotimes, the bindings are required as name n (see below).
Hence (dotimes [i 5] ... ) is the only pattern. Check out (doseq and (for
for what you're trying to do.
user= (doc dotimes)
-
clojure.core/dotimes
([bindings body])
Macro
bindings = name n
I'd like to pitch in here as I think it's distressing to see (vim
familiar) people abandoning clojure when it's quite possible to have
an easy and very efficient working environment using just vim,
vimclojure and rlwrap. I set this up 14 months ago when I started with
clojure and I'd be dragged
Here's an idiomatic way of doing what you want;
(defn lp [col]
(loop [ll (seq col)]
(when ll
(try
(let [itm (first ll)]
(if (= itm 'x) (throw (IllegalArgumentException.
(str itm not supported.)))
(println (str done item: itm
I concur with Garth - structures like coordinates, points, etc are
non-changing in their structure and hence don't need mapped
references into their elements. Destructuring is the easy way to get
at the elements;
(let [[x y z] pt] ...
and they can be combined in collections, arrays, etc, and
Have a look at clojure/core_print.clj in the clojure source. It is
indeed used with serialization - see print-dup. Here's an example of
usage;
(import '(java.io File FileWriter PushbackReader FileReader))
(defn rec-save
Save a clojure form to file. Returns the called form.
[#^File file frm]
Diversity is good. Nice work.
I concur. There is a huge body of Jsp code out there and many
thousands even millions of J2EE developers who work with it. Tools
that bridge the Clojure/J2EE gap are very welcome.
Additionally, looking at the the Fleet library it seems well designed
and written,
Try including [*print-dup* true] in the binding;
(defn write-nick-sets [file-name obj]]
(with-open [w (FileWriter. (File. file-name))]
(binding [*out* w *print-dup* true] (prn obj
You can read it back with;
(defn rec-load
Load a clojure form from file
[#^File file]
(with-open [r
You can also do stuff in the middle of a let;
(let [a vala
b valb
_ (do-something-with a b)
c (some-fn a b)
d (some-fn a b)
_ (do-something a b c d)
e (fn ...)
f (fn )]
(and-whatever-else))
Here _ is just some arbitrary unused variable.
Note that
1 - 100 of 147 matches
Mail list logo