Hi,
you could check to see whether a thing implements the interface.
(defn channel?
[x]
(satisfies? clojure.core.async.impl.protocols/Channel x))
Meikel
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to cl
Justin and Cedric: thank you for your suggestions. I removed all uses of
`with-precision`; instead, I used various BigDecimal methods directly, such
as .divide, .round, and .setScale by passing in a MathContext. Best I can
tell (so far), this solved my problem.
On Monday, January 6, 2014 9:19:5
Hi Bart,
!, alts! must happen within a _lexical scope_ of a (async/go block)
On Thu, Jan 16, 2014 at 1:32 PM, Bart Spiers wrote:
> I'm not really familiar with async, but why would you not be allowed to
> call that function inside a go block?
>
>
> On Saturday, January 11, 2014 8:45:08 PM UT
Hi Bart,
This is a bit expensive in the general case -- i.e. having to construct
an object every time I want to do a type check (and other objects may have
expensive constructors).
Now, technically, we could prebuild a gigantic map of "singleton objects"
representing one of each type, i.e.
(
I'm familiar with the path compression technique for union-find, but I tend
not to use it for two reasons:
1. That technique generally assumes you are going to continue to compress
the path with each *find* operation, not just the union. This means you
need to either use a mutable structure or el
Thank you for the example & pointing me to the official name of this
problem, Mark! Having done some more digging I found a solution which
still uses the "canonical nodes" idea (root nodes of component
clusters/subtrees) but does structure it differently and compresses
the paths of new nodes as the
I second the request to add a "count" field to the channel protocol.
I also agree that having to keep track of the buffer just to get the count
is hacky-ish.
On Thu, Jan 16, 2014 at 3:29 PM, Paul Viola wrote:
>
> Still finding my way around Clojure... sorry if this is trivial.
>
> I am using c
I'm not really familiar with async, but why would you not be allowed to
call that function inside a go block?
On Saturday, January 11, 2014 8:45:08 PM UTC+1, t x wrote:
>
> Hi,
>
> Consider this function:
>
> (defn try-put! [chan msg]
> (not (= (alts! [chan msg]
> :defau
Still finding my way around Clojure... sorry if this is trivial.
I am using core.async to implement a queue for a collection of workers that
pull jobs and complete them (there may be multiple producers as well).
All looks great so far. Except when it comes time to close down the pipe
(and dr
Hey t x,
You could use type to check it. It's not very robust (if there are
different types of channels, this might not work I guess) but will do the
trick:
(defn is-channel? [c]
(= (type (async/chan)) (type c)))
On Saturday, January 11, 2014 4:08:46 AM UTC+1, t x wrote:
>
> Hi,
>
> In cloju
Sweet! Thanks so much!
On 2014-01-16, at 1:17 PM, John Wiseman wrote:
(clojure.string/replace myText #"(?s)START.*?END" "==")
;; "a==\nee\nff\nggg\n==\n\n"
(?s) specifies multi-line mode, *? is the non-greedy form of *.
On Thu, Jan 16, 2014 at 1:02 PM, Kuba Rot
(clojure.string/replace myText #"(?s)START.*?END" "==")
;; "a==\nee\nff\nggg\n==\n\n"
(?s) specifies multi-line mode, *? is the non-greedy form of *.
On Thu, Jan 16, 2014 at 1:02 PM, Kuba Roth wrote:
> Hi,
> This is more of a regex specific question the clojure,
Hi,
This is more of a regex specific question the clojure, but anyway...
I have the a multiline string as follow:
(def myText "aSTART
END
ee
ff
ggg
START
ii E
END
")
.. and I need to replace all text between START END 'keywords' blocks.
Whoops, typo, should have been:
"(if (<= (count component1) (count component2))"
Corrected:
(defn register-same-as [{:keys [keys->canonical
canonical->components]
:as component-graph}
key1 key2]
(let [canonical1 (keys->canonical key1 key1)
If I understand you correctly, this is known as the "union-find" problem.
All you care about is whether two items are in the same component of the
graph. The key here is to keep track of two maps, one map from each item
to a "canonical item" in its component, and one map from each canonical
item
## Consider the following line:
lein do cljx once, pdo cljx auto, cljsbuild auto, run -m server.main
## it does not appear (by running it) to be equiv to:
lein cljx once
lein pdo cljx auto, cljsbuild auto, run -m server.main ?
## is there a way to generate a single lein command which is equiv t
After looking at edn/read-string and realizing I would have to modify Java
code, I have decided that modifying the sender in clojure land isn't so bad
after all.
On Thu, Jan 16, 2014 at 9:41 AM, Alex Miller wrote:
> I think I would change the sender to elide whatever parts you don't want
> to s
The isolation in Immutant is achieved (in part) by ShimDandy[1], which
can be used outside of Immutant with a bit of work. It's been on my list
for a while now to provide a sample application demonstrating usage -
there is a minimal example in the README.
Let me know if you are interested in the S
Hi, I need to build a data structure to store aliases of arbitrary
values (e.g. URIs), basically an undirected graph. Because I need a
fast lookup, I thought using a map with bi-directional mappings could
work well, e.g. stating "X" sameas "A" becomes this:
;; x == a : {a #{x} x #{a}}
Continuing
I think I would change the sender to elide whatever parts you don't want to
send rather than mess with the receiver.
On Thursday, January 16, 2014 2:11:02 AM UTC-6, t x wrote:
>
> Hi,
>
> Right now if I do (clojure.edn/read-string ...) on a string with a
> unreadable part, I get an exception.
Great job, David. Looking very sharp!
~Gary
--
--
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.
Yes, but this requires custom class loaders. AFAIK this is already
implemented in Immutant project (http://immutant.org/)
On Thursday, January 16, 2014 11:13:11 PM UTC+7, solo...@gmail.com wrote:
>
> Quick update and question: We've put together a preliminary migration plan
> and are considering
Quick update and question: We've put together a preliminary migration plan
and are considering options.
Can someone share information or point me to where I can learn whether two
different versions of Clojure (1.2 and 1.5) can run in the same JVM?
--
--
You received this message because you
I have been using Clojure for something more then 2 years, something more
then 1 year intensive...
But i think those feelings of frustration are absolutely OK, when i started
with Clojure for the very first
time, i was so frustrated (years of OOP mind-bending...) that i gave up for
some time an
Oh, yes, my mistake, it should be data instead of s
Dňa štvrtok, 16. januára 2014 15:56:18 UTC+1 James napísal(-a):
>
> Thank you for sharing.
>
> I think the final `s` needs to be `data`, right?
>
> On 16 Jan 2014, at 14:53, Jan Herich >
> wrote:
>
> Here we go, more generic solution:
>
> (defn
Thank you for sharing.
I think the final `s` needs to be `data`, right?
On 16 Jan 2014, at 14:53, Jan Herich wrote:
> Here we go, more generic solution:
>
> (defn transform [data delimiter]
> (reduce (fn [acc [k v]]
> (let [key-strs (-> k (name) (str/split delimiter))]
> (assoc-in
Here we go, more generic solution:
(defn transform [data delimiter]
(reduce (fn [acc [k v]]
(let [key-strs (-> k (name) (str/split delimiter))]
(assoc-in acc (mapv keyword key-strs) v))) {} s))
Dňa štvrtok, 16. januára 2014 14:46:46 UTC+1 James napísal(-a):
>
> Hello all,
>
> I've fo
Wow, I feel like a clumsy fool bashing parens together.
Have you been using Clojure for a long time Jan? I ask because I often
don't know where to begin when approaching a problem with Clojure, and it
can be quite frustrating.
On Thursday, January 16, 2014 2:45:48 PM UTC, Jan Herich wrote:
>
>
My solution would work only for fixed 2 level deep maps, but it would be
not so hard to modify it that it will be much more generic :)
Dňa štvrtok, 16. januára 2014 14:46:46 UTC+1 James napísal(-a):
>
> Hello all,
>
> I've found myself stuck trying to move matching keys in a hash into a
> nested
And here is the final piece of working code, which we're using to transform
results from Korma when we join a has one or belongs to association.
(def ^:private rel-attribute-pattern #"(.*)--(.*)$")
(defn- nested-key [k]
(some-> (re-matches rel-attribute-pattern (name k))
second
Another way of doing that:
(def data {:b--name "B", :a--id 1, :b--id 2, :a--name "A"})
(defn transform [data delimiter]
(reduce (fn [acc [k v]]
(let [[f-k s-k] (-> k (name) (str/split delimiter))]
(assoc-in acc [(keyword f-k) (keyword s-k)] v))) {} s))
(transform data #"--") ;; {:a
Whoops… that's missing an all important (merge (into {} top)).
On Thursday, 16 January 2014 14:36:45 UTC, James wrote:
>
> Thanks for the pointers. I've gotten as far as grouping the keys by the
> prefix using `group-by`, and added clunky support for keys that aren't
> nested like so:
>
> ``` cl
Thanks for the pointers. I've gotten as far as grouping the keys by the
prefix using `group-by`, and added clunky support for keys that aren't
nested like so:
``` clj
(defn- nested-key [k]
(some-> (re-matches #"^(.*)--(.*)$" (name k))
second
keyword))
(defn nest-relations
Oups, skipped the last part of your
emal. With edn I see no way to
do this.
Luc
> Either you misunderstood my question or I misunderstood your answer.
>
> I don't want the entire expression to return nil. I only want the
> _unparsable_ part to return nil.
>
> Thus, the above answer should be
Great initiative David!!
It seems the fastest path to learn ClojureScript by minimising any incidental
complexities generated by tools.
mimmo
On Jan 15, 2014, at 2:44 PM, David Nolen wrote:
> I've started what I hope will be a collaborative and comprehensive reference
> on the ClojureScr
You could do something like this:
(def v {:a--id 1 :a--name "A" :b--id 2 :b--name "B"})
(group-by #(-> % first str second str keyword) v)
=>{:b [[:b--name "B"] [:b--id 2]], :a [[:a--id 1] [:a--name "A"]]}
(reduce-kv #(assoc % %2 (into {} %3)) {} *1)
=> {:a {:a--id 1, :a--name "A"}, :b {:b--n
Hello all,
I've found myself stuck trying to move matching keys in a hash into a
nested hash.
For example,:
{:a--id 1 :a--name "A" :b--id 2 :b--name "B"} ;=> {:a {:id 1 :name "A"} :b
{:id 2 :name "B"}}
I've tried `clojure.walk`, I've tried building the args to `assoc-in`, and
using `apply`.
What you want is currently not possible.
If you need this functionality, I'll take a patch for tools.reader that
adds a :nil-on-unreadable option to clojure.tools.reader.edn/read.
Il giorno 16/gen/2014 11.05, "t x" ha scritto:
> Either you misunderstood my question or I misunderstood your answer
Either you misunderstood my question or I misunderstood your answer.
I don't want the entire expression to return nil. I only want the
_unparsable_ part to return nil.
Thus, the above answer should be
{:tag :message
:chan ni}
rather than
nil
On Thu, Jan 16, 2014 at 1:47 AM, Luc Prefontaine <
Wrap the read in a try catch just return nil in the catch clause
for this specific exception and wrap it in a function for ease
of use. You might want to throw up any other exceptions and
only catch this one
Luc P.
> I should add: this problem arises due to cljs / clojure talking over the
>
I should add: this problem arises due to cljs / clojure talking over the
network, so:
(*) not using serialization is NOT an option
(*) however, I don't have to use edn/read-string + pr-str
(*) it's perfectly fine to use different encoding/decoding methods
On Thu, Jan 16, 2014 at 12:11 AM, t x
Hi,
Right now if I do (clojure.edn/read-string ...) on a string with a
unreadable part, I get an exception. Instead, I would like to just get nil.
For example:
## code
(clojure.edn/read-string
(pr-str
{:tag :message
:chan (async/chan 10)}))
## currently returns
java.lang.RuntimeExcept
42 matches
Mail list logo