Hi clojure folk,
I'm reading up on clojure from the book 'Programming clojure'. In
chapter 2 there is a statement -
"The imperative indexOfAny must deal with several special cases:
null or empty strings, a null or empty set of search characters,
and the absence of a match. These special cases ad
Thanks, that answers my questions.
--
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 - please be patient with your
first post.
To unsubscribe f
Hi,
I was just wondering if (by now) Open CL has been 'wrapped' by higher
level languages. I came across these from the Khronos site (http://
www.khronos.org/developers/resources/opencl/#timplementations) -
1. http://ruby-opencl.rubyforge.org/
2. http://planet.plt-scheme.org/display.ss?package=ope
I'm trying to make a function which gives the n! permutations of a
vector of n things. Here is my first attempt :
(defn permute
"Gives the n! permuations of the input vector of things"
[v]
(if (= 1 (count v)) (list [(v 0)])
(loop [i 0 perm '()]
(if (= i (count v))
perm
Hi,
I'm using an API to connect to a server which does not provide
constructors, just static methods to get & close connections.
How can I do something like ...
(try
(let [conn (API/getConnection ..)]
())
(catch ..)
(finally (if conn (API/closeConnection conn
Problem is that c
ull)
API2.closeConnection(conn2);
}
I agree that this code doesn't look good from a purist pov, but any
issues besides that?
- Thanks!
On Apr 21, 4:58 pm, Alex Osborne wrote:
> ka writes:
> > How can I do something like ...
>
> > (try
> > (let [conn (API/getCo
when 3 {$s ~= 'c';}
when 4 {$s ~= 'd';}
default {$s ~= 'z';}
}
is $s, 'c', 'Caught number';
};
Thanks!
On Apr 21, 7:05 pm, Alex Osborne wrote:
> ka writes:
> > The whole code gets cluttered with all these tr
ding scope;
> you have to wrap one around it or within it via let. That's why I thought a
> combination of try and let would be useful, if only as syntactic sugar.
>
>
>
> On Wed, Apr 21, 2010 at 10:43 AM, ka wrote:
> > Thanks all for replies.
>
> > Laurent,
Hi ppl,
Above I wrote a macro with-open-flexi! ... which I'm planning to use
in my app's API . .. please let me know if there are any bugs /
gotchas / improvements etc...
I didn't get any responses, so does it means there is something so
obviously wrong that you can't even begin where to start :)
s are
> constructed ?
>
> 2010/4/29 Alex Osborne :
>
>
>
> > ka writes:
>
> >> Above I wrote a macro with-open-flexi! ... which I'm planning to use
> >> in my app's API . .. please let me know if there are any bugs /
> >> gotchas / improvemen
+1
On May 7, 2:13 am, Mibu wrote:
> Am I the only one driven mad by the new auto-appended signature to
> every message in this group ("You received this message because you
> are subscribed...")? It started on April 16th. Is there a way a
> moderator can stop it?
>
> --
> You received this messag
Not wanting to become an uninvited guest to your party :-) ... but do
you mind elaborating .. ?
On May 9, 2:31 am, Base wrote:
> I just replaced 443 lines of java with 61 lines of Clojure.
>
> THANK YOU RICH !!!
>
> --
> You received this message because you are subscribed to the Google
> Groups
> I think def should support docstrings, as ^{:doc "foo"} is 8
> characters longer then "foo" - not to mention consistency across
> definers as well as readability.
I agree that there should be consistency across definers and that the
default def should be the best. Removes unnecessary complexity
If add-watch is not what you want because you want the consumers to
have a life of their own, then does something like this work? -
(def my-hash (ref {}))
(def new-keys (ref #{}))
(defn produce []
(let [new-key (rand-int 10)
new-val "P"]
(Thread/sleep 100)
(dosync
(alter
pm, ka wrote:
> If add-watch is not what you want because you want the consumers to
> have a life of their own, then does something like this work? -
>
> (def my-hash (ref {}))
> (def new-keys (ref #{}))
>
> (defn produce []
> (let [new-key (rand-int 10)
> new-v
> You can get rid of the I/O in the transaction and still see a consistent
> snapshot by simply return the contents of the refs.
>
> (defn report-status
> []
> (apply println (dosync [...@my-hash @new-keys])))
>
> Sincerely
> Meikel
>
> --
Isn't ensure necessary? Because http://clojure.org/re
@Michael,
There is already a monitor mechanism available in Clojure via the
'locking' macro or more primitive monitor-enter, monitor-exit. So in
your case all you have to implement is the blocking behavior, I'm not
sure if it can be already done somehow using just Clojure elements.
The above code
Hi all,
I've written an API in Clojure to be consumed by people working in the
Java world. Now most of these people haven't even heard of Clojure;
but all they care about is 1) a working API and 2) with nice
documentation.
1) Something about the API - I tried out various things, types,
records,
As Steve said, better look at the combinatorics-api.
As for your original code, the idea you have gives all permutations
not combinations! Few changes will make it functioning -
(defn permutations [n coll]
(if (= n 1)
(map #(vector %) coll)
(for [el coll nlis (permutations (- n 1
1:6 user=> (use '[clojure.set])
nil
1:7 user=> (reduce union #{} #{#{[3 2] [5 4] [3 3] } #{[4 3] [5 4] [3
3] } #{[3 2] [2 2] [3 3] } } )
#{[3 2] [4 3] [5 4] [2 2] [3 3]}
1:8 user=>
Thx
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this g
Hi, any responses?
--
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 - please be patient with your
first post.
To unsubscribe from this group,
You may use reduce, as follows:
(let [r (java.util.Random.)
f (fn [el] (.nextBoolean r))]
(def pred f))
(reduce (fn [m el]
(let [k (pred el)]
(assoc-in m [k] (conj (m k) el
{true [] false []}
(range 10))
Thanks
--
You received this message beca
Tim,
I don't know much about either lisp or latex :). But it looks like a
really neat idea at a first thought to me. Have two remarks-
1. From the developer's pov - I'm not sure how the developer, who is
accustomed to looking at just code + some comments, will manage
working with the book. But
Hi all,
Inspired by Erik above, I've written a macro: gen-class+javadoc
(http://gist.github.com/415269).
It works quite well for me on Windows XP. For *nix, I think people
will have to make at least one change - the shell command (at line
57).
What it does -
1. Generates a javadoc for your API
This looks cool. I'll definitely give it a try in my next project.
Any chance to get it integrated somehow with eclipse ccw?
- Thanks
--
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
Hi Tim,
Thanks! for such a detailed response. Really got things in
perspective for me, my thinking yet isn't of such large scale.
So you say literate programming is for those who are writing code that
will live for decades to come and that writing literate programs takes
~3x resources.
Is there
It would be voodoo magic :) and totally awesome might I say if (= a
(drop 4 a)) returned true immediately!
- Thanks
--
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
My 2 cents, I read about transients for the first time (why is the
page not linked from clojure.org?) and they seem very promising at a
first glance.
I'm not sure if I agree with Michael's idea of having the same
functions for transients and persistents both. Functions should have
easy, reproduc
> Stefan Kamphausen writes:
> sorry, I'm a little late. However, to me it is not clear what the
> trim functions shall do. If they become a replacement for chomp they
> are clearly misnamed. In many applications and languages (like Excel,
> several SQL variants, oh, and Java, ...) "trim" means s
I've also added a :class-doc key to the macro -
(gen-class+javadoc
:class-doc "Class Docs
One Two
"
:name "a.b.c.MyCoolClass"
:methods [
#^{:static true} [method1
[clojure.lang.PersistentArrayMap] int]
#^{:st
Oops didn't know that Rich had already answered. Google seems to
think that our posts are commutative :/ (often they're not, or are
they? I can't take a stand on this) and just uses the commute fn
instead of using alter and failing the transaction (informing us); but
it does allow for more concurr
Hi Clojurians,
I have some conceptual questions on the sequence abstraction. I
understand that (seq coll) will give me a "sequence".
coll maybe be a list, vector, map, set, LazySeq or nil.
1. In case coll is a LazySeq why does (seq coll) realize its first
element? I thought seq just did a type
@Richard
>> 1. In case coll is a LazySeq why does (seq coll) realize its first
>> element? I thought seq just did a type conversion and all of list,
>> vector .. etc implemented Seqable or something.
> Because seq is defined as returning nil for an empty sequence. The
> only way to find that out
Hi Zak,
I tried your example on my i7 (4 physical cores, 8 logical); here are
the results -
1:298 user=> (time (do (doall (map fac (take 10 (repeat 5
nil))
"Elapsed time: 54166.665145 msecs"
1:300 user=> (time (do (doall (pmap fac (take 10 (repeat 5
nil))
"Elapsed time: 27418.263
Hi Zak,
It seems very weird that my version of fac changes performance
characteristics on my machine and not yours (OS/hardware dependent?).
Can you tell your hardware configuration, esp. number of physical and
logical cores? I am planning next to leave out using pmap and just try
to run the thing
@Jason
I'm supplying a Java API (implemented in Clojure) so needed a solution
quickly which just worked w/o me having to do special things.
Hence the gen-class+javadoc macro (http://gist.github.com/415269).
But I feel there should be something like this available in contrib
which handles the whol
denominator, you run:
> * gen-stubs
> * Javac
> * gen-class
>
> Since the stubs are around, you can also run JavaDoc.
>
> The stubs don't need to be saved. In the Maven world, they are part of
> the build, not source files.
>
> On Jun 4, 8:03 am, ka wrote:
>
> >
> My favorite option of those proposed is:
> +, *, -, inc, dec auto-promote.
> loop/recur is changed so that primitive bindings are boxed.
> +',*',-',inc',dec' give error upon overflow.
> A new construct, loop', is introduced that doesn't box primitives and
> enforces recur with primitive upon pena
How about this (using only map, reduce) -
user=> (def data1 [[:a1 :b1 :c1]
[:a1 :b1 :c2]
[:a1 :b2 :c3]
[:a1 :b2 :c4]
[:a2 :b3 :c5]
[:a2 :b3 :c6]
[:a2 :b4 :c7]
[:a2 :b4 :c8]])
user=> (pprint
(reduce
(fn f [tree r
To my naive inexperienced eyes, there doesn't seem to be something
obviously wrong with your code.
> Since FOR returns a lazy sequence of the results, is this function
> safe? (Seeing that it is not side-effect free?)
I'm not getting this, do you foresee any safety issues? I think that
the logs
I'm also facing the same problem -
(let [handler (agent 50)
a (agent 42
:error-handler
(fn [_ ex]
(do
(println "Inside agent a error handler fn" (Thread/
currentThread))
(send handler
(fn [_] (do (print
>(for [a (r 2), b (r 3)] [a b])
>; produces:
>
>(
>[0 0] [0 1]
>[0 2] [1 0] [1 1] [1 2])
Why does (r 2) get evaluated before the seq is needed ?
=> (def k (for [a (r 2), b (r 3)] [a b]) )
#'a/k
- Thanks
--
You received this message because you
Awesome awesome new features !!
Yes, when does windows support stop being experimental ?
Even though one of the new features is -
* Added experimental Windows support.
Has anyone tried lein 1.2 on windows (with the lein.bat on
http://github.com/technomancy/leiningen) ?
--
You received this m
@Chouser
Sorry, my above post was directed as a question to you. Have to stop
being lazy while posting atleast :) !
--
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
@Meikal,
Hi, I get what you mean. Consider the following func -
(defn r
[n lazy?]
(.println System/out (str "Called (r " n ")"))
(let [r-lazy-seq (fn r-lazy-seq [i n]
(lazy-seq
(when (< i n)
(.println System/out (str "Real
> For the program, I know that when processing a character, I do not
> need the previous result. All I need is the current character, and I
> can return a function that acts on the result. I'm not sure if this is
> simple to implement in a functional way.
Actually my understanding says that you ne
> So, it appears the (read-line) consumes the Clojure form (in-ns
> 'test.readln) probably stacked by CCW (at least I didn't type that!)
Yup you're right, CCW "typed" that, you may disable that feature from
the Windows > Preferences > Clojure > Editor.
Thanks
--
You received this message becaus
Hi,
I have two refs a1, a2. One thread modifies a1, another modifies a2.
Sample code: http://gist.github.com/556679
If I don't ensure any ref in the transaction, the code runs in ~ 0.2
ms.
$ java -cp lib/clojure-1.2.0.jar\;src clojure.main -e "(require 'tt)
(tt/transaction-simul {:ensure2 fals
These seem like good changes to me! Any plans to push?
--
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 - please be patient with your
first p
I follow this thread, but haven't read Clojure's source. I have a
similar question -
http://groups.google.com/group/clojure/browse_thread/thread/46415b89c7b311f6,
but haven't got any responses yet.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To p
@Alan
I'm trying to understand why you find the solution you gave "gross"
> I could construct all the objects and have a single "global" map, with
> mappings for both set-id=>[objects] and object=>set-id, but this seems
> kinda gross and obscures what is actually meant (objects belong to
> sets)
I've been wondering about having let over defn, I have the following
concerns -
1. Not recommended in the docs
http://clojure.org/special_forms#Special%20Forms--%28def%20symbol%20init?%29
says - Using def to modify the root value of a var at other than the
top level is usually an indication that y
+1, besides adding transients, protocols 1.2 features, can we also
have a "Future" section after the Reference section?
--
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
Hi,
Please explain this!
> code path for using vars is now *much* faster for the common case, and you
> must explicitly ask for :dynamic bindability
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@google
which
generates namespace (and package) dependency graphs at various levels
- complete src, single ns, single package. Additionally the graph
itself is available in many forms - Clojure map, .xml, .dot, .png
The code itself is a bit ugly & old but it works on both unix and
windows - http://github.
Hi, not sure if this is useful for you - http://github.com/na-ka-na/cdeps.
--
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 -
Hi Alex, Can we have a section: Clojure - What's next? Dishes out
some details & links for the next versions and ideas.
--
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
1. How to combine protocols?
For example I have protocols walks, talks, sleeps, now how might I
come up with an abstraction which walks-talks-and-sleeps ? In Java
one might create an interface which extends multiple interfaces.
Although getting an instance which walks-talks-and-sleeps is made ea
Clojure 1.2.0
1:1 user=>
1:2 user=>
1:3 user=> (deftype T [] Object (equals [this o] (if (instance? T o)
true false)))
user.T
1:4 user=> (def t (T.))
#'user/t
1:5 user=> (.equals t t)
false
1:6 user=> (deftype T [] Object (equals [this o] (if (= T (class o))
true false)))
user.T
1:7 user=> (def t (
>> I would guess the problem is referring to T inside the deftype.
This also works:
(deftype T [] Object (equals [this o] (if (= T (class o)) true
false)))
But as Meikel said hope that this is not the end of the story.
--
You received this message because you are subscribed to the Google
Group
> AFAIK, it is not possible. You must implement all the different protocols.
> It might look desapointing, but on the other hand it is not necessary.
> (As there is no static typing in Clojure)
> What is your use-case?
Current use case is that I want an abstraction which comprises of a
set of oper
> May I ask a heretic question: Why don't you specify the contract in the
> docstring of the protocol?
Yes Meikel that is exactly what I have right now. Just trying to learn
and stir up a discussion here :)
Most times you'll just do fine by passing 'something' to Coolness
functions and expect th
Christophe, Is it reasonable to assume that atleast the documentation
should be modified to reflect the situation?
--
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 m
Hi Tom,
I might not be even remotely qualified but since I'm interested and
find the idea cool, so here's my take:
> - has anyone already experimented with a toy STM in Clojure for didactic
> purposes?
No idea :)
> - what would be a good resource to start such a design from? (my current plan
Hi Islon,
Records already implement java.io.Serializable. So this is working:
(ns record-serialization)
(defrecord R [x y])
(defn test-serialization
[]
(with-open [oos (java.io.ObjectOutputStream.
(java.io.FileOutputStream. "tmp"))]
(.writeObject oos (R. 12 42)))
(with-open [ois (java
> (defn dec-or-dissoc! [key]
> (dosync
>(let [n (@*counts* key)]
> (if (< 1 n)
>(alter *counts* assoc key (dec n))
>(alter *counts* dissoc key)
> Is it true that in that case, one would have to use "ensure" to make the
> operation correct?
I don't think ensure is n
Hi Tim,
How about compare?
user=> (compare "a" "b")
-1
user=> (compare "b" "b")
0
user=> (compare "b" "a")
1
user=> (compare 1 2)
-1
user=> (compare 2 2)
0
user=> (compare 2 1)
1
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group,
This is a good question and I'm not sure of the right answer or if
there is one. Personally, if I were exposing an API I would use the
io! macro for sure. Even otherwise its a good convention to follow.
On Nov 30, 9:06 am, Alex Baranosky
wrote:
> Hi guys,
>
> I've recently discovered the io! macr
Hi Michael,
We're in a very similar situation to yours. Here's what we did:
1. 2 back end storage impls rah.storage1, rah.storage2 - these are
"private" nses.
2. a single storage interface rah.storage for the rest of the business
code. At runtime this decides which of storage1 or 2 to call.
3. No
I'm also stuck with the same issues: 1. no option to get string keys
2. I don't understand, why do libs go through the trouble of
downcasing ?
Having said that I totally agree with the point Ryan makes: >> A
greater feature of clojure is its extensibility. What I am after is a
generalization of t
Hi Brian,
Can you explain this in more detail :
>> I didn't have the laziness problem. I don't know if that was by accident or
>> because Midje applies an #'eagerly function before checking.
Because it seems that if code has a laziness problem, Midje will
actually hide it in tests?
Thanks.
--
The functions get-in, assoc-in, update-in are really useful. Just
wanted to share a thoughts.
user=> (def m {:a {:b {:c 10 :c1 20} :b1 90} :a1 100})
#'user/m
1. Lets see the behavior of these functions in the corner case of
empty keyseq:
user=> (get-in m [])
{:a {:b {:c 10, :c1 20}, :b1 90}, :a1
+1 on partial with no args !
I have a doubt: using partial conveys the intent, but with automatic
currying one may get confused between "partial application" &
"function call", no?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group
Here's one way to use eclipse + ccw + lein
1. Download latest eclipse helios. Go to market place and search for
counter clockwise plugin. Install the latest stable.
2. Create a new Clojure project. Delete the 4 jars it provides :) (yes
that's right delete them).
3. Install lein (https://github.com
@Bill,
If you have a REPL open you can just run the test as a zero arg
function.
(ns 'abc)
(detest xyz ...)
user=> (abc/xyz)
--
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 po
Yes that compareTo doesn't define a total order on your class. I think
you are missing a clause in cond:
(cond
(= sr sr2) 0
(= (.lik sr) (.lik s2)) return something based on quasi-isomorphic
(> (.lik sr) (.lik sr2)) -1
:default 1)
I think you should implement quasi-isomorphic as a
To me this looks totally fine, max-key should keep at most two
sequences in memory. I don't think there should be any difference
between the non-lazy and lazy versions as the depth of cseq is ~500.
The non-lazy version works for me (no heap error) for inputs 1M, 2M,
4M, but for 4M the java process
>> Running in VisualVM suggests that % of Used Heap is actually very
>> less. So the problem is that GC isn't running often enough, so the JVM
>> has to keep allocating more memory.
By problem I meant, in my case, of too much memory consumption.
> Odd. I'd expect the JVM to run a GC immediately
Andreas, How are you running that? Also what do you see in the heap
dump and what is the jvm heap size?
--
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
I've been using ccw for a while now and it works perfectly as
advertised. Plus the new 0.2.0 version looks to be really promising. I
invite all ccw users to give their inputs.
What's bugging is not that you faced a problem or that ccw didn't work
as you expected, what's disturbing is how you react
80 matches
Mail list logo