Perhaps this is so invalid character streams (e.g. mismatched or orphaned
surrogate pairs) can survive encoding and decoding (I haven't tested)?
Strictly speaking not every CharacterSequence is validly encode-able to
utf-8. Java just kind of hides this. For example, this is a reversed
I haven't used lein-package but I am surprised it doesn't handle this case.
This issue I think describes a similar use case, perhaps it helps you?
https://github.com/pliant/lein-package/issues/9
`lein deploy` has a long form which accepts arbitrary filenames:
$ lein help deploy
Deploy
I'm not certain I know what use case you're getting at. It sounds like you
want to take the current state of the global hierarchy and "fork" it into a
private hierarchy? Even though the var is private you can still access its
value:
@#'clojure.core/global-hierarchy (same as (deref (var
keyword has two arities:
(keyword x) will attempt to parse "x" into a keyword with name and
namespace parts.
(keyword namespace-part name-part) will make a keyword with name and
namespace set explicitly.
So to create a keyword dynamically (i.e. not using literal syntax) and be
*absolutely
Even though evaluation and realization of sequences is lazy, they cache
their result after evaluation. If you consume an object from the `sequence`
function more than once, the work is only done once. Sequences are iterable
and reducible, but not as efficiently because of the caching and
Import does not demand name mapping. You can import a full path without
aliasing. This will work fine:
(ns multi.core
(:require [multi.ns1]
[multi.ns2])
(:import [multi.ns1.Animal]
[multi.ns2.Animal]))
(multi.ns1.Animal. "hi")
(But remember to use the keyword
Not all intermediates appear because in between your completed swap! and your
log (really the deref of the atom) the value in the atom changed.
You are using atoms correctly. Your swap! function would me more idiomatic if
it used the threading macro (->) but otherwise is fine.
If you really
There are two different concerns in what people refer to as "pattern
matching": binding and flow-control. Destructuring only addresses binding.
Pattern matching emphasizes flow control, and some binding features
typically come along for free with whatever syntax it uses. (But you could
in
On Tuesday, January 10, 2017 at 9:27:24 AM UTC-6, hiskennyness wrote:
>
> Whenever I code something like this I get the feeling a clojure guru could
> do it more simply, and I love learning new tricks.
>
> Here is my simple (real-world, btw) problem and solution. Is there a
> better way?
>
>
A list/seq (not a vector) which is destructured as a map will be first read
into a map as by (apply hash-map the-seq)
This curiosity exists so the "keyword argument" idiom works:
(defn my-options [_ & {:keys [a b] :as options}]
options)
=> #'user/my-options
(my-options nil :a 1 :b 2 :c 3)
=>
doseq is a macro that accepts comprehension clauses like "for", so doseq is
a straight translation of for that is eager (but still uses seqs
internally) and swallows its body's results.
run! is like more like (doall (map f xs)), except it swallows results and
uses "reduce" for speed and
Let bindings are immutable bindings, not refs. They must act as if their value
could be substituted at the moment they are referenced. Def (i.e. a ref) is a
mutable container whose contents is examined when it is used (not when
referenced), which is why your second example works.
Why doesn't
Your spec names need different namespaces, but your functions do not:
(s/def :catalog-a/type #{"a" "b" "c"})
(s/def :catalog-a/ref string?)
(s/def :catalog-b/type #{:x :y :z})
(s/def :catalog-b/ref number?)
Then you need to say that the keys are unqualified when they appear in the
map for
You could try https://github.com/jumblerg/ring.middleware.cors as your cors
lib instead. This would at least help you isolate if it is a liberator
issue or not.
On Friday, October 14, 2016 at 7:22:29 AM UTC-5, Kenny Liu wrote:
>
> Anyone know if this all works out of the box? Preflight OPTIONS
BTW I noticed that sequence got hotter and eventually became the fastest,
but it took many more runs:
(time (dorun (sequence (map side-effect) col1 col2)))
"Elapsed time: 31.321698 msecs"
=> nil
(time (dorun (sequence (map side-effect) col1 col2)))
"Elapsed time: 15.492247 msecs"
=> nil
(time
Well, you pay a cost whenever you use seqs instead of reduce, so it/s
strange to think of doseq as "as fast as possible". If it/s argument is a
true collection, its IReduce is usually faster than its seq. If it is a
sequence already, its IReduce is usually just using seqs anyway.
Let's get
> Francis, thanks for separating out the different types of intermediate
> collections. I'm not entirely clear on type 1. It sounds like those are
> just collections that are already there before processing them. Or are you
> saying that Clojure has to convert them to a seq as such? Why
arguments! So it really is
> not better than clojure.core/map as far as allocation is concerned.
>
> Timothy
>
> On Fri, Sep 23, 2016 at 5:15 PM, Francis Avila <fav...@breezeehr.com
> > wrote:
>
>> There are a few intermediate collections here:
>>
>&
There are a few intermediate collections here:
1. The source coll may produce a seq object. How costly this is depends
on the type of coll and the quality of its iterator/ireduce/seq
implementations.
2. You may need to collect multiple source colls into a tuple-like thing
to
Leinigen uses maven repos to satisfy project clj dependencies, but there is
nothing stopping you from putting your jar directly on the classpath. The
idiom for local jars is to put them in "libs/". In this case you do *not*
mention
this dependency in your project.clj, but the jar will be on
It's not crystal clear to me what you are after, either from this post or the
one you link to. I think you want a map that does not produce intermediate
collections and accepts multiple colls as input at a time? Do you have some
pseudocode example so we can be precise?
What about (run!
The only way to have diff consider internal structures is to have a diff
protocol (with access to internals) to speed up comparison between items of
the exact same Java class.
However, much of the slowdown you see is from intermediate vectors created
during the reductions in diff-associative
I wasn't aware Clojure had an IReduce protocol! I thought CollReduce was just
what IReduce is called in Clojure.
--
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
oesn't require the accumulator to function
> properly, then there is no reason why `(map my-fn)` won't work.
>
>> On Sat, Jun 11, 2016 at 12:13 AM, Travis Daudelin
>> <travis.daude...@gmail.com> wrote:
>>> On Friday, June 10, 2016 at 3:03:38 PM UTC-7, F
A higher-order function can do what this macro
does: https://gist.github.com/favila/ecdd031e22426b93a78f
On Friday, June 10, 2016 at 1:07:58 PM UTC-5, Travis Daudelin wrote:
>
> Hi all!
>
> I'm current working on a project where I am ingesting events off a stream
> and processing them. There
Sorted maps sort their keys, but keywords and strings are not comparable:
(sorted-map "a" 1 :b 2)
ClassCastException java.lang.String cannot be cast to clojure.lang.Keyword
clojure.lang.Keyword.compareTo (Keyword.java:114)
On Thursday, April 28, 2016 at 3:54:33 PM UTC-5, JPatrick Davenport
On Tuesday, April 26, 2016 at 4:38:02 PM UTC-5, Martin Grześlowski wrote:
>
> I'm trying to compile String that contains Clojure Script code in
> Java/Groovy.
>
> I'm not really happy with using *"java -jar ...".execute()*.
>
>
> Is there any way to invoke clojurescript library (version 1.8.51)
On Monday, April 25, 2016 at 6:45:13 PM UTC-5, JvJ wrote:
>
> What I want to know is this: Will the JVM benchmarking numbers reflect
> how the JS implementation performs?
>
No
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this
Your reduction function uses when, which returns nil for the false case. You
need to use if instead and return %1 unchanged in the else case so the
reduction can continue.
There may still be other problems, but that is the cause of your NPE
--
You received this message because you are
I believe by "several different mem-dbs" he means different instances, not
implementations, i.e. they differ by name and (maybe) config, but share an
implementation.
There are two ways this can happen: two system graphs in the same clojure
runtime, or one system graph that uses the same
If you can model the authentication process as a state machine, have a pure
function which accepts auth-state and data and returns either a new state
or an operation to get new data to determine the next state.
E.g. (next-auth-state {:stage :not-authed :login "login" :password "pass"}
nil) =>
On Monday, April 4, 2016 at 6:30:07 PM UTC-5, Howard M. Lewis Ship wrote:
>
> David Nolen had an early ClojureScript core.async demo with thousands of
> channels, controlling individual pixels.
>
This is the demo you are referring to:
http://swannodette.github.io/2013/08/02/10-processes/
The backtick namespace-qualifies symbols automatically:
(macroexpand-1 '(switch-foo-library! x))
;=>
(clojure.core/defn
user/foo
[y__3652__auto__]
((clojure.core/resolve (clojure.core/symbol (clojure.core/str x "/foo")))
y__3652__auto__))
The error is about the "user/foo" name of the defn.
I had some fun with playing around with faster
solutions. https://gist.github.com/favila/0573e3f644dea252bdaaed5be9d1519f
The biggest speedup comes from avoiding set creation in expanded-range
(i.e., the function that produces the collection of affected coordinates)
and ensuring that the ops
Even stranger - the parallel version seems to at least produce an output
> (not sure how correct) if run for the first 50 commands instead of 300.
>
I forgot to mention: the reason why r/fold sometimes seems to still work is
because there is only one chunk (i.e., no parallelism), so the
kash wrote:
>
> Just verified - it works and gives the correct answer for shorter
> collections.
> No performance boost though. And fails (?) on larger collections.
> Not sure what's happening. The foldvec implementation is also pretty hard
> to understand.
>
> On Sunday, April 3, 2016
Your input collection to r/fold is provided by cmds-from-input which
returns a lazy-seq (from map) which is not a parallel-foldable type. You
can try mapv instead: vectors are parallel-foldable. (Note only
PersistentVector and PersistentHashMap have useful coll-fold
implementations: all other
Are you sure that it changes the child element order? It hasn't in my
experience. Example:
(clojure.xml/parse (io/input-stream (.getBytes
"" "UTF-8")))
=>
{:tag :a,
:attrs nil,
:content [{:tag :b1, :attrs nil, :content nil}
{:tag :a1, :attrs nil, :content nil}
{:tag :a2,
A wonderful hack I read about somewhere is to just use the clojure.test/is
macro, which I now do all the time:
(require '[clojure.test :refer [is]])
=> nil
(defn get-key [m k]
{:pre [(is (map? m) "m is not a map!")]}
(m k))
=> #'user/get-key
(get-key [] 0)
FAIL in
I think the difficulty here is that Chord has a bidirectional channel,
where putting and taking operate on different "streams" inside the channel.
(Internally, Chord is actually using a different channel for reads and
writes. It constructs the "joined" channel using chord.channels/bidi-ch)
I
Your problem is unrelated to clojurescript.
Your script runs before the body is loaded, so the test-content element doesn't
exist yet.
Either load your script at the end of the body, or wrap your code in a
document.onload event handler.
--
You received this message because you are subscribed
In clojurescript you can just "override" the necessary protocols inline in the
defrecord. You will get a warning, but everything will work. You can silence
the warning by using extend-type instead of an inline implementation.
In clojure, doing this will give you a compile-time error, meaning
e shows cljs 1.7.170 is used.
So,
On Saturday, November 7, 2015 at 3:30:05 AM UTC-6, Maria Geller wrote:
> Try using 0.5.0-SNAPSHOT for figwheel ;)
>
> On Saturday, November 7, 2015 at 9:59:24 PM UTC+13, Francis Avila wrote:I'm
> getting the following exception w
I'm getting the following exception with figwheel builds (using 0.4.1):
java.lang.AbstractMethodError: Method
clojurescript_build/core/CompilableSourcePaths._find_sources(Ljava/lang/Object;)Ljava/lang/Object;
is abstract
at clojurescript_build.core.CompilableSourcePaths._find_sources
Not-found is not the same is not-nil. Is it possible that
this-users-converstation *does* have an :incoming-message key with a nil
value?
See the difference between these two cases:
(get {} :a :not-found)
=> :not-found
(get {:a nil} :a :not-found)
=> nil
Notice also that records always
There are only two steps: filter to select maps to use (e.g. :name =
"abc"), map to transform them (e.g. extract :value). Here are some examples:
(def xs [{:src "a.png", :name "abc", :value "a"} {:name "def", :src
"b.gif", :value "b"}])
=> #'user/xs
(->> xs
(filter (comp #{"abc" "def"}
Does he actually need a real arraylist, or will something fulfilling a
collection interface (Collection, Iterable, or List for example) be ok? Many
clojure types do not require any casting at all as long as the java code writes
to a collection interface and doesn't expect to be able to mutate
I don't quite understand why you are not calling the Protocol method as a
function, i.e.
(new-node this t-2 lev l r c)
(no leading dot on new-node).
I also don't see anything which actually *implements* INode.
Note that the meaning of "method" in "Protocol method" is not the same as
in "Java
Futures automatically capture exceptions raised in their bodies and reraise
them when the future is derefed. Promises also throw exceptions when
derefed.
Unlike promises, futures are created with the code that delivers their
value, so calling fail and deliver explicitly on a future makes no
with a promise? It seems that there is
no fail method.
On Friday, August 7, 2015 at 4:52:47 PM UTC-4, Francis Avila wrote:
Futures automatically capture exceptions raised in their bodies and
reraise them when the future is derefed. Promises also throw exceptions
when derefed.
Unlike promises
There is no equivalent to set-car!, because conses are not mutable. Only
vars, refs, atoms, and agents are mutable, and they are simply containers
for immutable values. You could put a cons inside an atom and put a new
transformed list into the atom. (Note even among schemes set-car! is highly
assoc-in works for vectors in the sense that both vectors and maps
implement ILookup (get) and IAssoc (assoc). assoc-in can navigate any
collection that understands get (including sets!), and add to any
collection that understands assoc.
However, assoc-in will *always* create *maps* when it
Note: my knowledge of soap is not very deep, but I have done the following
in a production system.
If you have a WSDL available, a good approach is to generate the (Java)
client code and then use it via Java interop. You can smooth out the rough
edges and shed the extra java types by using
I've never used ring.middleware.reload, but I do run client figwheel and
server in the same jvm.
In your project.clj, make figwheel listen on an nrepl port:
:figwheel
{:nrepl-port 7888
:server-port 3000 ; http
:repl false ; Optional: keep this off and bootstrap to
do not appear
to be escaped. I amazed by this:
user= (count *1)
3
Perhaps the error is something entirely different from what I was
assuming.
On Thursday, July 9, 2015 at 7:52:54 PM UTC-4, Francis Avila wrote:
This is what I am doing with Carmine and it seems to work properly
-4, Francis Avila wrote:
This is what I am doing with Carmine and it seems to work properly.
First some setup in the repl:
user=(require '[taoensso.carmine :as car])
nil
user= (def conn {:pool {} :spec {}})
#'user/conn
user= (defn raw-str-set [k ^String v] (car/set k (car/raw (.getBytes v
Reducers can perform fewer allocations than lazy seqs, but that does not
automatically translate into a big speed difference, especially with your
trivial example.
Try comparing chained lazy seq ops (map, mapcat, filter, take, drop, etc) to an
equivalent chain of reducer calls: you may see a
to
and from JSON.
Any suggestions are welcome.
On Wednesday, July 8, 2015 at 8:58:53 PM UTC-4, Francis Avila wrote:
Who is saving these strings, and who is reading them? Do you have
complete control over both apps, or does one of them need to be aligned
with the other?
If the Java app
are sometimes escaped, but most of the time they are not.
I need to avoid having those quote marks escaped. I am not clear what is
causing the escaping.
On Thursday, July 9, 2015 at 12:01:51 PM UTC-4, Francis Avila wrote:
your document-as-byte-array is wrong--it only handles ascii
You are running into Carmine's automatic nippy
serialization. https://github.com/ptaoussanis/carmine#serialization
Redis only stores byte arrays (what it calls strings). Carmine uses the
nippy library (the meaning of NPY in your byte stream) to represent rich
types compactly as bytes.
is that happening?
On Wednesday, July 8, 2015 at 5:38:20 PM UTC-4, gingers...@gmail.com
wrote:
Francis Avila,
Thank you for your response. The Java app is using Jedis and the Clojure
app is using Carmine. I'm wondering if you can suggest what you think would
be the easiest way to allow these 2
(This question is more appropriate to the datomic
group: https://groups.google.com/forum/#!forum/datomic)
Datomic/datalog queries always perform aggregation as a last step so the
results of aggregation are unavailable to the :where clause. In other
words, what you want is impossible with a
This is exactly the approach to take: a macro which expands to a defn with
all your arities filled out.
Here's a simple approach which might be enough for your problem: it will
splice in argument names whenever some marker symbol is encountered, and
repeat for the range of arities you want.
Possibly you are also including the dependencies in the non-profile part of
the project.clj? You shouldn't: the :provided profile is normally included,
but excluded when running the uberjar task.
More concrete example:
(defproject myproj 0.1.0
:dependencies [[org.clojure/clojure 1.6.0]] ;;
Your two functions can be written more succinctly (and with fewer explicit
conditionals) like these, but they will be harder for a beginner to
understand. (The nested update-in with fnil in particular may cause
confusion.)
(defn add-placeholder-to-history [users]
(reduce-kv (fn [users uk
Core.async issues are reported on Clojure's
JIRA: http://dev.clojure.org/jira/browse/ASYNC
pipeline does not have an incidental return value: it returns a channel
which closes when there are no more transformation results, i.e. when the
pipelining process is finished. There is no other way to
Separate out traversal from selection to make this clearer.
We make a generic traversal function get-in-via. It accepts a via function
which takes the current result and some value which determines the next
result, and returns the next result.
(defn get-in-via [m via ks]
(reduce (fn [m' k]
.
On Tuesday, March 24, 2015 at 4:55:23 PM UTC-5, Francis Avila wrote:
Separate out traversal from selection to make this clearer.
We make a generic traversal function get-in-via. It accepts a via function
which takes the current result and some value which determines the next
result, and returns
The reduce in your mapped function is already implemented by get-in. Other
possible implementations using get-in:
(defn map-in [coll ks f args]
(- coll
(map #(get-in % ks))
(map #(apply f % args
Or:
(defn map-in [coll ks f args]
(map #(apply f (get-in % ks) args) coll))
Yet another way:
(vec (reduce
(fn [m [k v]]
(assoc m k (+ (m k 0) v)))
{}
[[1 0.5] [1 0.7] [2 1.0] [3 0.1] [3 0.1]]))
= [[3 0.2] [2 1.0] [1 1.2]]
On Friday, March 20, 2015 at 8:45:10 AM UTC-5, Emrehan Tüzün wrote:
Yet another way to solve it:
*user=
Wishlist: for macros, metadata about the vars a macro will define. (E.g.,
(defmacro defrecord [...]) will define (-NAME arg...), (map-NAME m) when
executed.)
This would allow a lot more source analysis for the common case of def*
macros which are just fancy ways of def-ing vars, but without
You can work around this by using a symbol for the dispatch function
instead of inlining the function:
(defn create-fact-dispatch [item-vector]
(do
(print item-vector)
(first item-vector)))
(defmulti create-fact create-fact-dispatch)
When you reload in the REPL the defmulti will
This is probably easier if you do it in two passes: one to assemble the
get-in path down to a value, and another to stringify that path.
(def input {:name {:first Rich :last Hickey} :number [1 415 123 4567]})
;= #'user/input
(def expected {$.number[0] 1, $.number[1] 415, $.number[2] 123,
This is nice to have, thank you! uuid v5 generation seems to be something I
reimplement over and over, but which is never big enough for a library. I
would like to stop doing that and just include your library in the future.
However, I think your v3/v5 implementations need much more control
Not fundamentally different from your approach:
(apply set-style (apply concat {:color red :cursor pointer}))
On Friday, February 13, 2015 at 11:30:44 AM UTC-6, Wilker wrote:
Hi guys,
I'm trying to find the best way to call a function that accepts keyword
arguments (in my case it's the
There is also a jar of v8
(https://github.com/circleci/clj-v8 https://clojars.org/clj-v8) which can
run js scripts in a v8 subprocess. With some plumbing code in Clojure you
could run your tests in v8 as a jar, but again you won't be able to test
anything that requires a browser stack.
If you
The difference is how rest args are handled. From the recur documentation:
In particular, if the recursion point was the top of a variadic fn method,
there is no gathering of rest args - a single seq (or null) should be
passed.
So your two calls are not the same. f1 calls (recur x some-seq)
You will probably have more luck getting help in the Clojurescript group.
The clojurescript-in-clojurescript project you found is defunct. In the
meantime normal Clojurescript has gotten much closer to being self-hosted
and work towards that end is probably best done on Clojurescript itself
It will be inconvenient to use transducer functions without the transducer
support added in 1.7.0, but there's nothing magical about transducers that
requires Clojure 1.7.
Core.async 0.1.346.0-17112a-alpha does not depend on clojure 1.7 (it only
depends on Clojure 1.6) and you don't need
If you need parallelism, you need to do an indexing pass first to determine
the group boundaries. Then you can process them in parallel because you
know the units-of-work.
Iota is an ok fit for this, so I suggest trying it first. (You may have to
dial down the parallelism of r/fold to avoid
For completeness and internet posterity, this issue produced the following
ticket and resolution: http://dev.clojure.org/jira/browse/CLJ-1620
On Thursday, December 18, 2014 9:16:06 AM UTC-6, Alex Miller wrote:
The problem is in the static initializer (which is gigantic), not the
particular
Cursive Clojure can do this: alt-f7 the symbol. (But it's not a lightweight
tool if that's what you mean by not emacs.)
On Wednesday, December 3, 2014 9:16:52 AM UTC-6, Yehonathan Sharvit wrote:
Is there a tool to display all the references to a symbol in a project?
Preferably without using
I had a need for this too some time ago. It's not very hard to write
yourself. Whatever trickiness there is in these functions is in handling
exceptions and orchestrating shutdown.
I put my version up in a gist with some other async utility functions I
wrote:
What you are describing is not url-encoding but xml-entity-quoting. The
problem is not with the http-kit client but somewhere else in your stack.
On my system (http-kit 2.1.16) I get the expected result:
In a terminal:
$ nc -l localhost -p
In a repl:
@(org.httpkit.client/post
Your loop pattern should work. (I've used this pattern before.)
Just a sanity check: you *are* running this function in a different thread,
right? Because whatever thread calls this function *will* block forever,
whether the queue is empty or not. And unless you provide some
side-effecting
There is nothing *exactly* like this for clojurescript. The problem is
clojurescript compiler is implemented in Clojure and thus requires a JVM to
compile the code. Brython's compiler is implemented in js so it can run in
the browser.
There was a cljs-in-cljs (self-hosted clojurescript)
It would probably help if you said more about the source of this
atom-holding object. Is it a plain Java class? A deftype/defrecord? Is it
final?
If you can control the construction of this object and its class is not
final, you can subclass it and add an IObj implementation. (Note that most,
FYI, using the :psuedo-names compiler option is very handy for debugging
advanced-compile munging issues, e.g.:
:compiler {:optimizations :advanced
:pseudo-names true
...}
On Wednesday, July 30, 2014 10:11:17 AM UTC-5, Thomas Heller wrote:
Geez, 2277
88 matches
Mail list logo