What's happening is that you have multiple optional arguments chained
together. Optional arguments are passed as a list (or seq?) of arguments,
so if you pass them down to another function that also takes optional
arguments they get wrapped in yet another list. An option to stop this is
to use
How are you accessing the data?
I suppose that if you were accessing (maybe you are) the data via helper
functions, that's where most of the refactoring should happen.
On 22 May 2014 09:17, Jakub Holy jakub.h...@iterate.no wrote:
I have a nested data structure, used by a bunch of functions
Thanks for the pointer Jakob. I've updated the form accordingly.
Cheers,
On 28 April 2014 10:56, Jakub Holy jakub.h...@iterate.no wrote:
I too have booked a session with Ulises and am excited about it :-)
@Ulises It would be nice if the timezone of the session was mentioned on
the booking
And if you are in Europe, remember that Ulises is still offering, at what
looks like 1300-1400 UTC (I think):
https://ucb.youcanbook.me/https://www.google.com/url?q=https%3A%2F%2Fucb.youcanbook.me%2Fsa=Dsntz=1usg=AFQjCNGoo6exDmYGhdu-4qu3L9tL2v8AkQ
It's actually 9-10am BST, but thanks
Inspired by Leif's offer, I've decided to offer Clojure office hours as
well.
I'm based in the UK so I reckon the times will be more amenable to those in
Europe (not sure the times will be good for those in Asia unfortunately.)
Sadly the offer is limited to 1h a day, but hopefully it'll still be
sharing, as well as Google hangouts.
Once you've booked an appointment with me please email me privately to
arrange the pairing set up so that I can be ready for you :)
Cheers
On 18 April 2014 10:35, Ulises ulises.cerv...@gmail.com wrote:
Inspired by Leif's offer, I've decided to offer Clojure
When I started learning clojure back in 2010 I decided to give a
presentation about it at work. That set a deadline (about 3 months) in
which I had to learn the language. Having said that, I learnt /the
language/ however wroting code (toy or not) reading other people's code,
getting code reviews
While we're on the subject, I found no way of decoding/interpreting an
already existing sequence (ByteBuffer) of bytes, but only one that had
been created with compose-buff. Am I missing something?
On 4 December 2013 07:28, Cesar Canassa cesar.cana...@gmail.com wrote:
Hi,
I see that the
Thank you! The book is published very recently and I noticed it took a while
for the printed editions to appear on Amazon. I am getting in touch with
Packt to find out why the kindle editions not on Amazon and whether this is
temporary.
Great! Thanks for the diligence.
If you're getting in
Could you please let me know which URL and page no. did you find the images
missing on? I noticed the images are visible (for example on page number 21)
when I visited http://www.amazon.com/dp/1782165606/?tag=packtpubli-20 and
clicked on the book image to open the preview.
Apologies for the
If you're not planning on changing the value of your defined index,
you can always use partial, e.g.:
(def search (partial es/search es-index))
On 9 September 2013 09:42, Mark Mandel mark.man...@gmail.com wrote:
Hey all,
Relatively new to Clojure, and I'm wondering if there is a
I'm sure it's a bit early but is there a mailing list for this?
I've ran into trouble trying EEP on a really simple flow (the even vs.
odds in the docs.) and I'd like to ask a few questions.
U
On 6 September 2013 02:24, Timothy Pratley timothyprat...@gmail.com wrote:
Awesome!
Thank you for
Perhaps you're looking for fixtures?
http://thornydev.blogspot.co.uk/2012/09/before-and-after-logic-in-clojuretest.html
U
On 21 May 2013 15:17, Colin Yates colin.ya...@gmail.com wrote:
Howdy,
I am using clojure.test and have some questions of how to write idiomatic
Clojure. This really
Hey Colin,
Apologies, I missed your First - I know about fixtures... line :)
I'd probably +1 Gaz's macro (I've not tested it either but it looks
reasonable.)
On 21 May 2013 16:05, Colin Yates colin.ya...@gmail.com wrote:
Hi Ulises,
I don't think I am as that would require essentially
Code that matters is code that's used by other people. For me personally
the ability to share my code with others is the thing that makes
programming worth doing in the first place.
This is a rather important point. One of the most asked questions
(random made up fact) by newcomers to a
The biggest 'ah - got it' for me was when I realised IDEs are great for
navigating huge object models which are relatively narrow but deep (i.e. lots
of nested relationships). This requires a special set of navigation skills
(cntrl-click to go to declaration, autocompletion etc). Clojure
?
On 1 May 2013 12:13, Ulises ulises.cerv...@gmail.com wrote:
The biggest 'ah - got it' for me was when I realised IDEs are great for
navigating huge object models which are relatively narrow but deep (i.e.
lots of nested relationships). This requires a special set of navigation
skills
Have you tried replacing all your calls to map for pmap yet?
On 11 April 2013 03:33, Bruno Kim Medeiros Cesar brunokim...@gmail.comwrote:
Hello. I am replicating the study made by John D. Cook in
thishttp://www.johndcook.com/blog/2013/02/25/exact-chaos/post about exact
chaos in Clojure,
Forgive me if I completely misunderstood your question. Replies inline.
One way is to use `with-redefs`. This technique would be used at every
level along the pyramid (except the bottom level which doesn't call
anything else).
This would be similar to mocking, correct? If so, what'd be wrong
I've been using drip with quite some success (with the exception of midje
tests which seem to launch their own jvm every time.)
On 20 February 2013 15:53, Buck Golemon workithar...@gmail.com wrote:
I see that lein2 has factored out the 'interactive' command.
Can I use lein1 and expect the
How about having your methods access an atom provided in a closure like
it's done here:
http://kotka.de/blog/2010/03/proxy_gen-class_little_brother.html
U
On 14 February 2013 13:58, Joachim De Beule joachim.de.be...@gmail.comwrote:
Hi All,
I want to turn a clojure sequence into an
-stream [input-seq]
(let [remaining (atom input-seq)]
(proxy [EventStream] []
(next [] (let [current (first @remaining)]
(swap! remaining rest)
(elt-event current)))
(hasNext [] (not (empty? @remaining))
2013/2/14 Ulises
+1 on pdf
On 8 February 2013 10:30, Konrad Hinsen
googlegro...@khinsen.fastmail.netwrote:
The article
Clojure for Number Crunching on Multicore Machines
by Martin Kalin and David Miller
Computing in Science and Engineering Nov/Dec 2012
is in free access at the moment:
Try clj-http (https://github.com/dakrone/clj-http)
On 5 November 2012 12:12, N8Dawgrr nathan.r.matth...@gmail.com wrote:
Hi All,
Does anyone know of a good simple library to call/consume web-services
from Clojure? Note I don't want to create a web-service just call one.
--
You
Does anyone use Midje currently?
I most definitely do!
And thanks for porting midje-mode to nrepl. I've recently been
migrating to nrepl and friends and I was missing my midje-mode!
U
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this
Hi,
I've translated the code in
http://experthuman.com/programming-with-nothing to Clojure and here's
the result:
- https://www.refheap.com/paste/5073/fullscreen (code)
- https://www.refheap.com/paste/5074/fullscreen (tests)
Cheers,
Ulises
--
You received this message because you
Binding to the var instead of the value will allow it to be udpated.
Alternatively you could ns-unmap the multimethod before redefining it.
U
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to
Don't know why nil is returned instead of {}, but
(+) = 0
(*) = 1
following that line of reasoning:
(merge nil {:a 1})
{:a 1}
(merge {} {:a 1})
{:a 1}
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to
Apologies in advance if this is a silly question but have you tried
profiling your code to see where the hotspots are?
U
--
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
Here's an edge case for you:
(has22 [1 2 2 1]) ; false
:)
U
--
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
Please excuse my ignorance and my late comment, but can you make your
1hr operation shorter?
The general advice I've always been given has been whenever you need
to use a resource that might cause contention do it quickly, in and
out in a blink.
I know that the argument then would be why do I
I'd forgotten that 'into adds things in the default place for whatever type
you're using, hence the reversal on lists. I'm not sure if there's a simple
way to get the same type out again while preserving order.
How about:
(defn sub-seq [start end coll]
(take (- end start) (drop start
Additional to all the positive comments, I'd suggest you use an
operator which is not commutative, otherwise the differences between
- and - are less evident.
U
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to
I have a contest going with a colleague, where we each have to render a
network layout in SVG. My gut says that Synthetic Annealing is the right
tool for the job here.
I haven't heard of synthetic annealing (I have heard of simulated
annealing though) but if you're looking to draw a network
I am unsure about the atom of api-key, in theory i won't need to change my
api-key, but idk... You can get a lot of api-key gratis which are a little
limited or just one payed api-key that can do everything...
My point was that once you've declared api-key {:dynamic true} (which
by the way is
Looking the code again I believe that I should use a future and not an
agent...
I am right ???
I would think so. AFAIK, the advice has always been if you need to do
some computation on another thread don't (ab)use agents, use futures.
Additionally, you have[1]:
(def #^{:dynamic true}
Apologies for hijacking this thread, but this is probably the most
relevant place to point you to a simple web-frontend to cld I cooked
up in a couple of hours:
http://detector-de-idioma.herokuapp.com/index.html
Additionally, you can call it as a service like
$ url
I'm more curious about why the output isn't even deterministic. The
same input string produced three different results.
You can see in the FAQ
(http://code.google.com/p/language-detection/wiki/FrequentlyAskedQuestion)
that:
Langdetect uses random sampling for avoiding local noises(person
name,
Here's a paper that might be interesting to folk discussing in this
thread: http://www.jstatsoft.org/v46/i03/paper
Cheers
U
--
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
Interesting plugin.
I've been pondering for a while about whether it'd be interesting to
write clojure (or language X) blog posts in a literate fashion, i.e.
with weave and tangle that knew how to download the post and then
extract and execute the code.
This would come in rather handy since more
Alternatively you can just do:
$ lein plugin install swank-clojure 1.3.3
and have swank across projects without having to add your
:dev-dependencies for each one.
U
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to
How about using juxt:
sandbox ((juxt :foo :bar) {:foo 1 :bar 2 :baz 0})
[1 2]
sandbox
This only works, however, if you use keywords for keys (as they are
functions themselves).
U
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group,
I understand that lazy sequences are very useful but sometimes, I want to
compute everything, go away, and have it there when I come back.
How do I do that with a map?
(def x (map fn coll))
you could do (last x) and drop that value.
U
--
You received this message because you are subscribed
Here's my take on it (all caveats apply, e.g. performance):
(defn indices-of
Returns the indices of the given char in the string (0 based).
[c string]
(map second (filter #(= c (first %)) (partition 2 (interleave string
(iterate inc 0))
(indices-of \a abba) ; (0 3)
and hence
Whenever I see a question like this asked anywhere (and even when I
ask the question to myself or others) I usually recommend reading (or
read myself): http://prog21.dadgum.com/80.html
:)
U
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to
I failed to mention that both the files are in a directory named
mybot
I could be wrong but I think they have to be in the root of the zip
file, i.e. no directories.
I just zip up ants.clj and MyBot.clj into a file and it works.
HTH,
U
--
You received this message because you are
The problem with identities of actors comes in when you consider code
like the following:
(def trantor (get-actor Trantor world-state))
(:hit-points trantor)
= 10
(def new-world-state ((command Trantor :eat apple) world-state))
(:hit-points trantor)
= 10 (still!! because we
inside the universe and updating it,
then you should be good to go.
Cheers,
Ulises
--
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
How about a potentially ugly workaround:
user (defn sum [ {:keys [x y]} ] (+ x y))
#'user/sum
user (sum :x 1 :y 2)
3
user (def inc-sum (partial sum :x 1))
#'user/inc-sum
user (inc-sum :y 1)
2
user (inc-sum :y 2)
3
user
I know this is a trivial example, but I do quite fancy named arguments
and
Are you arguing for my option b) then? In which case actors don't have
distinct identities, they are just part of the overall world?
Not necessarily as your option b) already gives implementation details
(using ids to find actors, etc.). I was mostly thinking out loud to
see if anything
Maybe the world's state is that player Trantor is at position [15 34]. Now
Trantor eats an appel. The appel is removed from his inventory and his
health is raised by 5 hit points. Did the state of the world change? No.
Trantor is still at position [15 34]. Does the world have to know about the
your subject contains the answer :)
sandbox (def s1 (seq [s1 (seq [s2 s3]) s4 s5 (seq [s6
(seq [s7 s8]) s9])]))
#'sandbox/s1
sandbox s1
(s1 (s2 s3) s4 s5 (s6 (s7 s8) s9))
sandbox (flatten s1)
(s1 s2 s3 s4 s5 s6 s7 s8 s9)
sandbox (doc flatten)
-
clojure.core/flatten
([x])
Not the right answer. I tried to use the apply function with no
success.
How can I wrap the expression inside a function.
Why not use partition and interleave?
user (partition 2 (interleave [:a :b] [:c :d]))
((:a :c) (:b :d))
U
--
You received this message because you are subscribed to the
I believe contains? tests for the presence of a key in a collection:
user (contains? {:a 1 :b 2} 1)
false
user (contains? {:a 1 :b 2} :a)
true
user (get [0 2 3] 1)
2
user (contains? [0 2 3] 1)
true
user
From the docstring:
Returns true if key is present in the given collection, otherwise
An alternative is to use partition together with interleave:
user (partition 2 (interleave [ 1 2 ] [ \a \b ]))
((1 \a) (2 \b))
Combined with (map vec ...) you should get:
user (map vec (partition 2 (interleave [ 1 2 ] [ \a \b ])))
([1 \a] [2 \b])
user
U
--
You received this message because
try passing a map such as {:query-params {CA ca, street street ...}}.
On 20 July 2011 16:24, Mark Rathwell mark.rathw...@gmail.com wrote:
(require '[clj-http.client :as client])
(defn make-url [ca street-1 street-2 city state zip]
(let
[url
jackson can read/parse large JSON files through its streaming API:
http://wiki.fasterxml.com/JacksonInFiveMinutes#Streaming_API_Example
U
--
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
You could use identity as a predicate to filter:
user= (def s [nil nil 1 2 3])
#'user/s
user= (first (filter identity s))
1
user=
U
--
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
false is not nil.
Ugh! Well spotted :)
U
--
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
Ugh!
Actually, I was more after a wrapper around the Rserve client more
than anything however RIncanter is the closest thing I could find.
Sortof. The original author is updating thing so that they work more
cleanly. In the interim if you want to get it to work modify the project.clj
It's a way older older version of clojure but it's in there. I've played
around with it.
You can always replace the jars (and include others such as support
for Jython) and even add contrib. I've done that and it works just fine :)
The one grief I had with GRefine is that once you create a
Hi,
Is RIncanter still alive?
Cheers,
U
--
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
I usually use identity as a predicate for functions such as filter,
drop-while, take-while, etc.
Consider this silly example: imagine you had an operation that fetches
stuff from a resource (DB, network, etc.) and that upon failing it
returns nil. Additionally, imagine that you're interested in
If your keys were keywords, e.g. :key1, you could simply map them as
they are also functions:
(map :key1 ({:key1 value1} ...)
U
--
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
I just clicked on Try it and only got to a short blurb and a
subscribe form. Is this the right behaviour?
U
--
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
So, questions to Carin, Alex and Alan (and Ulises): What interests
you? What problems do you have that you'd like solutions for? Knowing
that, folks might be able to point you at existing projects to take
part in (or might confirm no such project exists and they'd be
interested
Not long ago I was faced with the same dilemma: I am learning clojure
and to practise and improve my skills I'd like to contribute to an
open source project. Which one should I pick?
And then I came across this: http://prog21.dadgum.com/80.html
Enjoy :)
U
--
You received this message because
I disapprove of discouraging people from offering to help with OSS:
that's how you get started and how you get good.
Well, it's not really discouraging. Or at least, I don't see it that
way. I see it more like encouraging to contribute but not regardless
of personal interest. Personal interest
user= (- p (map :b) (reduce +))
Alternatively:
user (def p '({:a 1 :b 2 :c 4}, {:a 2 :b 3 :c 5}, {:a 3 :b 4 :c 6}))
#'user/p
user (:b (apply merge-with + p))
9
Depending on whether you'll want the other sums or not, this approach
might be appropriate.
U
--
You received this message because
This has worked for me. Modify depending on your case.
CAVEAT: I built a fatjar using $ lein uberjar which I then added as an
external dependency in Eclipse. This included the clojure jar, the
contrib and potentially lots of other stuff I had in my project. It is
not entirely clear to me if one
Sorry for hijacking but I wouldn't mind some clarification on the subject.
Right now I can get java classes and interfaces with defprotocol and
defrecord and the world is good.
Can somebody please educate me in the uses/needs for :gen-class and friends?
Keep in mind that I haven't really done
You need gen-class when you want (or have to) derive from another
class. defrecord/deftype/reify don't allow that, while gen-class/proxy
do.
I suppose this is for when you want to add fields to an already
existing class? (I'm assuming that adding methods could be done with
I'd love to assit too (I like the fact that it'd be interactive). Just
to let you know I'm on GMT (for when you schedule things).
Cheers,
U
--
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
Hi,
I've just implemented a simplistic map-reduce framework which mimics
the steps involved in the workflow of a Hadoop job. It basically
amounted to implementing a helper function to emit results and the
shuffle-combine step which happens in between a map and a reduce task.
Please consider that
Hi,
I've just implemented a simple map-reduce framework which mimics the
steps involved in the workflow of a Hadoop job. It basically amounted
to implementing a helper function to emit results and the
shuffle-combine step which happens in between a map and a reduce task.
Please consider that I am
I would still like to see slime in action, however. I have two emacs
installed, GNU and Aquamacs. macports is still not able to do anything
Sorry if this sounds silly but have you tried with carbon emacs? I
heard from old time hardcore emacsers that that is the best emacs for
OS X (I'm not one
Does anybody know of an implementation for a priority queue that can
be used for scheduling events in the future? I would like to put a
map associated with a timestamp into the queue and be able to pull out
all maps at or before a given time in order.
You can do so with a combination of
This is how I'm running the test in the slime-connect buffer:
How are you running the swank process? I usually run it as lein swank.
Whenever I print inside a spawned thread I get the output in the
console where I started swank.
U
--
You received this message because you are subscribed to the
A little stuck on how to do this efficiently. I have data that looks
like this
( [ [1 2] [3 4] [5 6] ... ] [ [5 6] [7 8] [9 0] ... ] ...)
I am trying to sum the vector pairs, e.g
[6 8] [10 12] [14 6]
Try:
user (def all-pairs '([ [1 2] [3 4] [5 6] ] [[5 6] [7 8] [9 0]]) )
Is it possible to write such a function?
Perhaps you're looking for partial?
user (def x 10)
#'user/x
user (let [y 5] (partial + x y))
#core$partial$fn__3680 clojure.core$partial$fn__3...@beebcd
user ((let [y 5] (partial + x y)) 1)
16
user
U
--
You received this message because you are
I know this may be a silly question but: how does one get started
helping with contrib/etc.? I'm only starting to learn clojure but I've
found the community so helpful and thriving that I cannot help but to
want to help ... what is the first step?
U
--
You received this message because you are
Alternatively you can do:
user (def x 5)
user (def y 7)
user (take (* x y) (cycle (range x)))
(0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4)
user
U
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send
Hi,
I'm sure this has been asked before (although I couldn't find anything
other than this StackOverflow thread
http://stackoverflow.com/questions/2320348/symbols-in-clojure) and, in
addition to that thread, I have a clarifying question:
Am I right if I say that when I do (def foo 1) I'm
I guess one should use mapping instead of binding. The var is mapped to
the symbol foo in the namespace *ns*.
I'm saying that because functions for inspecting namespaces are (ns-map),
Ah! Excellent, thanks.
U
--
You received this message because you are subscribed to the Google
Groups
So I would say: Unqualified symbols in the namespace the def happened
in will resolve to the def'd Var. (of course only after the def
happened!)
so in theory one could have a symbol foo bound to a var bar?
U
--
You received this message because you are subscribed to the Google
Groups
Eh. No. I don't think so. The Var has a name and the symbol has a
name. And an unqualified symbol is resolved to the closest Var with
the same name (conveniently derefing the var to get its contents).
This might be in the same namespace or in a different namespace which
was :use'd. I'm still
Hope, that helps.
It does indeed.
So, def either creates or looks up a var of the name of the symbol
given and then every time eval comes across a symbol it tries to
lookup a var of the same name?
(just read http://clojure.org/special_forms#def which I should've read
before posting)
Cheers
My take on this. I know it's convoluted, I know this is probably not
the best and not even a good-enough solution, but it's what I have so
far (needless to say, I'd welcome comments on my code :)
(defn explode [ [k vals ] ] (map #(vector key %) vals))
(defn update-map [ m ] (partial apply assoc
There is a subtle difference in how fixed arguments are handled.
partial evaluates the arguments only once while fn evaluates them on
each call. For side-effects free code the former can yield better
performance. To recap:
Ah! What a nice caveat! (also applies to taking macros as arguments).
Hi,
Newbie here with a simple question: what is the preferred way of
mapping a function to a seq? Use an anonymous function or use a
partial?
Consider this:
user= (map (fn [n] (+ 2 n)) [1 2 3 4 5])
(3 4 5 6 7)
user= (map (partial + 2) [1 2 3 4 5])
(3 4 5 6 7)
user=
I know that the answer is
You can also consider the following: (map #(+ % 2) [1 2 3 4]), which
I did consider #(...) but didn't include it in the example as I tend
to prefer (fn [..] ...). For some reason my brain parses (fn...) much
better than #() (it looks more explicit).
If partial is a special case of #(..) could
Think about it for a moment. What should ((+ 2) 1) return? A
function with the next elment add on to it? So it would return a
function that adds 3 to its args or the result? How can you know what
the caller wants?
That's a very good point which I hadn't considered.
Perhaps the evaluation
The two styles are ok.
Matter of taste.
(partial ...) have probably a slight cost I wouldn't worry about
except if profiler tells me to worry.
Excellent.
If you want to have something looking like (+ 2) with multiple args
possible, I would advocate the best way might be to
add a reader
93 matches
Mail list logo