> (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 b
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
How about;
(defn reflection-dump [o]
(let [methods (seq (.getDeclaredMethods o)) ]
(str
o " has " (count methods) "methods...\n"
(second (reduce (fn [[i st] meth] [(inc i) (str st "meth" i ": "
meth "\n")]) [0 ""] methods)
(print (reflection-dump java.io.InputStream))
class java
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 fu
>> >> I vote let's turn this into a clojure vacation, and hold it in an
>> >> exotic location.
Well, how about Johannesburg or Cape Town. Sort of equidistant from
the US, Europe, Asia and Aus. Also if you wait a month or two you can
get to watch a soccer (footie) match or three as well :).
--
Yo
>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 moderat
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 kic
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 mani
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, an
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 [
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 y
Hi Dan, you need to include an arg for "this" in -fooMeth, i.e
(defn -fooMeth [this] "fooMeth")
or
(defn -fooMeth [_] "fooMeth")
- Rgds, Adrian
On Sun, Feb 28, 2010 at 12:06 AM, Dan Becker wrote:
> Hi,
>
> I'm trying to write a java class in clojure, and then call it from
> java. But I keep get
Hi Ivar,
> ;; Do things such as hash-map comprehensions exist? Should they? ;-)
> (defn some-eqn3 [obj]
> (let [{:a a :b b :c c} obj]
> (/ (+ (- b) (sqrt (- (* b b) (* 4 a c
> (* 2 a
At least a partial stab at some of your questions...
(def myhash {:a 1 :b 5 :c 6 :x nil})
(defn s
Maybe just;
(let [{:keys host port user password} config]
(.connect store host port user password))
On Mon, Mar 8, 2010 at 9:47 AM, Michael Gardner wrote:
> Given a Java instance 'store' with a .connect method that takes a host, port,
> user and password, and given a hash-map 'config' with co
There's a fundamental law of nature that says; if you don't try it at
the repl before posting, you WILL get it wrong :-).
On Mon, Mar 8, 2010 at 5:19 PM, Meikel Brandmeyer wrote:
>
>> (let [{:keys host port user password} config]
>> (.connect store host port user password))
>
> module missing
You asked for it! What's the bet there are at least 50 responses to
your post. How about;
natty, nattle, clonat, or just nat.
-Rgds, Adrian.
On Wed, Mar 17, 2010 at 9:08 AM, mac wrote:
> After just a little more test and polish I plan on calling clj-native
> 1.0. But clj-native is a *really* bor
f a lengthy exposition on this topic last year after
experimenting with modifying namespaces. Perhaps that will give you
some ideas. See below...
>On Sun, Aug 30, 2009 at 8:46 AM, Adrian Cuthbertson
> wrote:
>> Is there a way to unregister some names from a namespace without reload
You could perhaps also try format;
(println (format "%5.2f" 10.2)))
-Rgds, Adrian
On Thu, Apr 1, 2010 at 7:27 AM, Mark Engelberg wrote:
> printf doesn't seem to do anything inside a gen-class -main function, when
> run from the executable jar program (compiled by the latest Netbeans
> Enclojure
> I hereby cast my vote into the void: release often; release 1.2
> soon. :-)
(inc (fetch void))
--
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 modera
Not sure about your specific case, but when you don't get back
expected results it's usually due to the functions called being lazy.
Try doall or dorun to force the iterations.
-Rgds, Adrian.
On Tue, Apr 27, 2010 at 12:25 AM, David McNeil wrote:
> I am experimenting with clojure.test and I encou
(last p) returns a char \/
(first p) returns \B)
so, use (= (str (last p)) sep)
-Rgds, Adrian.
On Wed, Apr 28, 2010 at 3:30 PM, WoodHacker wrote:
> Can someone explain to me why this doesn't work:
>
> (let [ p "Bill/"
> sep (System/getProperty "file.separator")
> ]
>
>
> simple, you'd be embarrassed to admit that you didn't see WHAT WAS
> STARING YOU IN THE FACE all along?
Don't be too hard on yourself - it takes a while for the clojure
patterns to sink in so you easily spot the simple errors. Best to
throw it out there so someone else can help.
Gen-class is a
Some time ago I experimented with migrating definitions between
namespaces. Here's a post from then that covers some lower-level
detail regarding namespaces.
http://groups.google.com/group/clojure/msg/f00a82b747c1636f
-Hth, Adrian.
On Mon, May 10, 2010 at 12:15 AM, Mark Engelberg
wrote:
> The m
I don't think there's a way to do it with :keys, but could you use
individual key destructuring? I.e;
(let [{x :x/y} {:x/y 20}] x)
20
-Rgds, Adrian.
On Thu, May 13, 2010 at 6:47 PM, David McNeil wrote:
> Is there a way to destructure namespace qualified map keys?
>
> I want to do something like
Hi Base,
It's useful to think of the "pattern" of loop/recur and then apply it
to your problem. I.e
(loop [-- initial bindings --]
(if --- terminating condition ---
---return result---; otherwise...
(do-stuff with bindings
(recur ---with new bindings---
A simple examp
> What is the canonical way to know whether something satisfies (is satisfies
> the right terminology?) a protocol.
You're looking for extends? ...
(doc extends?)
-
clojure.core/extends?
([protocol atype])
Returns true if atype extends protocol
(defprotocol PStr "String
> Actually, it seems to do what I thought.
Right, indeed
(satisfies? PStr ss)
-> true
--
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 -
On Wed, May 19, 2010 at 9:06 AM, alux wrote:
> Any comment here?
(defn spawn-repl [socket]
"spawns a repl on a given socket"
(let [input (new LineNumberingPushbackReader
(new InputStreamReader (.getInputStream socket)))
output (new PrintWriter (.getOutputStream sock
> thanks for the hint. I looked into clojure.core and similar files,
> and didnt find much use of *err*.
>
There are a few in clojure.contrib. Have a look at logging.clj,
repl_ln.clj, server_socket.clj, internal.clj and utilities.clj.
(doc *in*)
-
clojure.core/*in*
A ja
On Fri, May 21, 2010 at 4:57 AM, Mibu wrote:
> I tried to use Long keys from the java.io.File/length method in a hash-
> map and failed to retrieve values using them. sorted-map is fine. The
> doc says hash-maps require keys that support .equals and .hashCode.
> Doesn't Long support those or am I
> That said, I'd rather make sure that my low-level data structures are being
> operated on by only one implementation.
You could use closures to encapsulate the refs/atoms ...
(let [car-mem (ref nil)]
(defn set-car-mem [new-car-mem]
(dosync (ref-set car-mem new-car-mem)))
(defn update-
Also have a look at Christophe's excellent "Taming multidim Arrays"...
http://clj-me.cgrand.net/2009/10/15/multidim-arrays/
-Rgds, Adrian
--
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
N
Hi,
It seems definterface/deftype have a problem with "-" in the method name...
... Clojure 1.2.0-master-SNAPSHOT (today)
(definterface INm (^String get-nm []))
==> user.INm
(deftype Nm[nm] INm (^String get-nm [this] (str "Mr " nm)))
==> java.lang.IllegalArgumentException: Can't define method no
> Is that a bug or is there a usage rule I'm missing?
seems so - underscore in the definterface method works...
(definterface INm (^String get_nm []))
==> user.INm
(deftype Nm[nm] INm (^String get-nm [this] (str "Mr " nm)))
(.get-nm (Nm. "Smith"))
==> "Mr Smith"
--
You received this message be
You can also use a multiline string in a comment...
(comment "
To do: x y z
More to do: a b c
")
-Rgds, Adrian.
--
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 ne
Hi Jared,
Some good clojure specific learning resources;
http://java.ociweb.com/mark/clojure/article.html
and the essential http://clojure.org/
- Regards, Adrian
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to
The do form (see http://clojure.org/special_forms#do) only
encapsulates forms and returns the value of the last form evaluated.
The forms generally perform some side effect (otherwise they would be
superfluous). An example of where it's useful is with an if...
(if some-pred return-something
(do (
> 1. Loading .clj files
> Is it possible to load up .clj files from the classpath of an
> arbitrary java app? For example, could you proxy HttpServlet and run
> your servlet as a .clj from within a servlet container?
Hi Todd, here's a pattern for doing what you want;
1.) Create svlt/Svlt.clj as b
> You can use Compojure to build webapp in more convenient way.
I should elaborate on my previous post. It was intended not to
recommend the clojure way of building web apps (there's plenty of info
regarding that - compojure, ring, clout, hiccup, conjure, etc), but
rather as a specific, detailed e
> 1. Have you written, or are you writing, a web application that uses
> Clojure? What does it do?
I am and have been extending an existing production java web
application environment with all new server work now being done in
clojure. It is a complex jvm server running tomcat and other threaded
p
You need the "this" arg and I find you need to hint the exact types
when reifying java interfaces;
(seq (.list (java.io.File. ".") (reify java.io.FilenameFilter
(^boolean accept [_ ^java.io.File f ^String s] (not (.startsWith s
"."))
... works for me.
- Rgds, Adrian
--
You received this me
Sorry, you don't need the type hists just the "this" arg...
(seq (.list (java.io.File. ".") (reify java.io.FilenameFilter (accept
[_ f s] (not (.startsWith s "."))
On Tue, Jun 29, 2010 at 3:35 PM, Adrian Cuthbertson
wrote:
> You need the "this
I don't seem to be able to get rid of reflection warnings on
definterface/deftype field/method calls...
Clojure 1.2.0-master-SNAPSHOT
user=> (set! *warn-on-reflection* true)
true
(import '(java.io File))
java.io.File
(definterface IFile (^String getNm[]))
(deftype TFile [^File file] IFile (^String
> I think it is the var that should be hinted. In practice you probably
> have a function which could have a hinted arg.
That's it! Thanks Karl.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups
> To test with pooled DB connections I thought I'd mention Apache Commons
> dbcp. Its a generic connection pool library that could be used for any jdbc
> connection.
There's also the lighter-weight MiniCollectionPoolManager. See
http://www.source-code.biz/snippets/java/8.htm
-Regards, Adrian.
--
Hi Sean,
I think there are two ways to do this;
1) Use an agent. You can "send-off" a fn to the agent with your
select/update logic and this will run within the agent thread -
guaranteed to be serial so you only need your select/update and no
retry logic. The state of the agent is not important -
I'm trying...
git clone http://github.com/clojure/clojure.git
and getting the following error...
Getting pack 9be7389ab68fea4a8309596c2916961599d2b06c
which contains 833f9f368d2274766aa4699195b3fba3f9e4e8f0
error: Unable to get pack file
http://github.com/clojure/clojure.git/objects/pack/pack-9be
Apparently there's a problem with git clone http://...
Should be git clone git://github.com/clojure/clojure.git
Sorry for the noise.
On Thu, Jul 15, 2010 at 3:57 PM, Adrian Cuthbertson
wrote:
> I'm trying...
> git clone http://github.com/clojure/clojure.git
> and getting
Hi Benny,
The 1.2 release source site has moved to
http://github.com/clojure/
-Regards, Adrian
On Sat, Jul 17, 2010 at 8:00 AM, Btsai wrote:
> Hi Clojurians,
>
> The recent 1.2 beta release is the first time I played with 1.2. When
> reading the release notes, I saw a number of new namespaces.
unable to find an
> online API there. http://richhickey.github.com/clojure/ is the only
> online API I have seen. And again, the other new 1.2 namespaces like
> clojure.java.io show up just fine there, which is why I'm confounded
> why clojure.string is not there.
>
&g
> :)
(inc ":)")
On Sat, Aug 7, 2010 at 7:27 AM, Meikel Brandmeyer wrote:
> Hi,
>
> Am 07.08.2010 um 05:06 schrieb j-g-faustus:
>
>> I don't think there's a direct way to create a String array in Clojure
>
> (defn to-env
> [env-vars-map]
> (->> env-vars-map
> (map #(str (name (key %)) "=" (
Hi Brian,
System/out
#
(System/out)
#
both return the "out" PrintStream object, so
(.. System/out (print "-"))
-nil
(.. (System/out) (print "-"))
-nil
(.. System/out (print "-"))
-nil
all invoke the print method on the java PrintStream object and
correctly return nil
as does...
(.print System/o
Hi Nicolas,
I've done a bit of manipulation of namespaces for dynamic loading and
executing of functions in a web app context which might give you some
ideas...
Here ns-nm and ipath have been extracted from a url. Then...
(let [ .
ipath (if (or (nil? ipath) (= ipath "")) "root" ipath)
ip
Here's an approach that might work...
; app1.clj
(ns app1)
(defn myinc[x] (inc x))
(defn mydec[x] (dec x))
(defn .)
;app2.clj
(ns app2)
(defn mysq[x] (* x x))
then you have a mylib.clj which is your public "user" module;
(ns mylib)
(require 'app1 'app2)
(defn exports[]
(refer 'app1 :only
Hi Albert,
I made sense of this by keeping the concept of defprotocol separate
from definterface and deftype. defprotocol is like multimethods and
deftype is like creating an implementation of an interface. You then
need to instantiate a new instance of the deftype to execute its
methods. The foll
te:
> Hi,
>
> On 1 Sep., 07:33, Adrian Cuthbertson
> wrote:
>
>> There are probably ways of creating types on protocols, but I haven't
>> tried that yet.
>
> Clojure is a dynamically typed language. I don't think that putting
> types on protocols is very
Have a look at Stuart Halloway's video on protocols;
http://vimeo.com/11236603
and also clojure.core.protocols.clj in the 1.2 source code.
A general google on clojure protocols also brings up some blogs in
which various people have some good examples and explanations.
Also note that deftype of cou
e myComp)
true
On Wed, Sep 1, 2010 at 4:33 PM, Adrian Cuthbertson
wrote:
> Have a look at Stuart Halloway's video on protocols;
> http://vimeo.com/11236603
> and also clojure.core.protocols.clj in the 1.2 source code.
> A general google on clojure protocols also brings up some blogs
I strongly support any initiative that does not assume maven is a given.
-Rgds, Adrian.
On Thu, Sep 9, 2010 at 5:03 AM, Sean Devlin wrote:
> Until you don't want to deal with maven, and just need a jar. Like if
> you're installing Enclojure & just want the stupid jars.
>
> On Sep 8, 3:42 pm, bu
lojure up and running. You
> download one script, make it executable and run it to install
> Leiningen and then projects are as easy as 1. lein new myproject, 2.
> lein deps, 3. lein test - although I pretty much always add lein-run
> and I'm looking forward to it being built
> Just fixed this with some help from Hugo Duncan; best guess is it's a
> weird Mac encoding issue. Should be clear now though.
Hi Sean,
Noticed you're running java 1.5. Fwiw, I used to run 1.5 with Mac OSX
Leopard 10.5 (vanilla install) and I remember having a few "funnies"
with clj/java. I did
Hi Dmitri,
The problem is probably related to calling init with args. It requires
that super() gets called - I can't remember where I saw the
documentation, but here's an example of what works for me.
The following is a generic servlet which gets passed a clojure
namespace name as an init paramet
I would guess the problem is referring to T inside the deftype. This works;
(deftype T [] Object (equals [this o] (if (instance? (class this) o)
true false)))
(let [t (T.)] (.equals t t))
==> true
On Wed, Nov 3, 2010 at 12:39 PM, ka wrote:
> Clojure 1.2.0
> 1:1 user=>
> 1:2 user=>
> 1:3 user=>
> in db.clj
> I have
> (:require [some-library :as mylib])
> in api.clj:
> I have (:require [myapp.db :as db])
> I then want to call mylib/somefunction -
You can use "some-library/..." directly after requiring db, e.g;
xxlib.clj...
(ns xxlib)
(defn xxfoo [] :xxfoo)
db.clj...
(ns db
(:require
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
Hmm, I tried your dirs and files off my dev directory and the same
binding/compile form and it works fine or me - firstly on 1121, but then I
checked out 1130 and also no problem. (I'm on jdk 1.5 on OSX). Sure you've
created the classes dir?
Also you said you invoked using;
java -cp /home/gteale/s
101 - 169 of 169 matches
Mail list logo