gt; better idea of what is going on.
>
> Sean
>
> On Feb 18, 10:34 am, Rowdy Rednose wrote:
>
> > Various interesting approaches to this problem... thanks guys!
>
> > Stu, you're right, distinct builds up a set of all items encountered,
> > which I don
ers--he
> only wanted to remove *adjacent* duplicates.
>
> That said, core/distinct is a better demo of "how do I maintain state
> across a lazy sequence without requiring any mutation?"
>
> Stu
>
> > Hi,
>
> > On Feb 18, 3:04 pm, Rowdy Rednose wrote
, 11:04 pm, Rowdy Rednose wrote:
> The filter documentation reads:
>
> "Returns a lazy sequence of the items in coll for which (pred item)
> returns true. pred must be free of side-effects."
>
> So that means I should not write a function like this:
>
> (defn uniqu
The filter documentation reads:
"Returns a lazy sequence of the items in coll for which (pred item)
returns true. pred must be free of side-effects."
So that means I should not write a function like this:
(defn unique [sc]
"Returns a lazy sequence with all consecutive duplicates removed"
(le
te:
> On Sat, Jan 30, 2010 at 7:31 PM, Rowdy Rednose wrote:
> > I want to have it in O(1). That's why I use a tree map in the first
> > place.
>
> > On Jan 31, 9:15 am, Sean Devlin wrote:
> >> If you can live with an O(n) operation, take/drop-with will do
I want to have it in O(1). That's why I use a tree map in the first
place.
On Jan 31, 9:15 am, Sean Devlin wrote:
> If you can live with an O(n) operation, take/drop-with will do the
> job.
>
> Sean
>
> On Jan 30, 6:59 pm, Rowdy Rednose wrote:
>
> > How would I d
How would I do something like these 3 TreeMap operations with
clojure's sorted-map?
The goal is to narrow down a map to include only keys with a given
prefix.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojur
Does anybody know an elegant way to have a regex pattern with
capturing groups like in this simple example:
user=> (def pat #"^foo=([^;]*);bar=([^;]*);$")
#'user/pat
user=> (re-seq pat "foo=F0o;bar=bAr;")
(["foo=F0o;bar=bAr;" "F0o" "bAr"])
And reuse that pattern to generate a text that replaces
On Jul 19, 12:53 pm, Richard Newman wrote:
> > * Can the body of the db-push function be simplified?
>
> I think so. Untested:
>
> (defn db-push
> ([key val] (db-push key val *default-db*))
> ([key val db]
> (swap! db assoc key (cons val (db key))
If I add an @ it runs:
(defn db-pu
Hi all,
in my quest to learn clojure (and lisp in general), I'm currently
trying to translate some the "On Lisp" code to clojure.
The first couple of functions and macros in Chapter 19 "A Query
Compiler" read:
(defun make-db (&optional (size 100))
(make-hash-table :size size))
(defvar *defau
As I said, the example was stripped down for simplicity, and that
simple version doesn't make much sense other than for communicating my
problem.
My real val-fn is not a map, it's indeed a couple of functions,
applied to some data that's passed in. But the result of that acts
like a map: it retur
Thanks Meikel,
your negative answer actually helped me analyze my problem better and
get the distinction run time / expansion time straight. I figured that
the names of the bindings are already there at expansion time and it's
only the values that I need to retrieve at run time.
So this version
How can I lexically bind names like "let" does in a macro, when names
and values for those bindings are passed in?
This here works fine when I pass a literal collection:
(defmacro let-coll
[coll & body]
`(let ~(vec coll) ~...@body))
user=> (let-coll [a 11 b 22] (list b a))
(22 11)
Doing th
Awesome! Works great! (After fixing the typo in "SwingUtilites". that
is :)
--~--~-~--~~~---~--~~
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
The idea is to have all existing code (that gets recompiled after my
redefinition) benefit from my changes automatically, although I fear
it's not considered good style to do this.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Go
But can't I somehow refer to the original dosync from my new dosync
macro?
On Jul 10, 11:52 pm, Rowdy Rednose wrote:
> This did the trick:
>
> (ns clojure.core)
> (defmacro dosync [& body]
> `(do
> (assert (not (javax.swing.SwingUtilities/isEventDispatchThrea
This did the trick:
(ns clojure.core)
(defmacro dosync [& body]
`(do
(assert (not (javax.swing.SwingUtilities/isEventDispatchThread)))
(#'dosync ~...@body)))
This is great for testing!
Thanks for your help, Stu. And btw the book is really great so far
(and I'm almost through)! It pr
On Jul 10, 10:28 pm, Stuart Halloway
wrote:
> binding to a thread. The snake game could be extended to be a
> simulation that runs on multiple threads (or perhaps even multiple
Makes sense. For the example in the book it just seemed completely
redundant. And when writing Swing code, at least
Why does the Snake example in the book use refs when all mutation is
done from the EDT?
To verify that, I put a call to "assert-edt" in front of every dosync
in snake.clj. assert-edt is defined like this:
(defn assert-edt [] (assert (javax.swing.SwingUtilities/
isEventDispatchThread)))
And it n
07.2009 um 07:27 schrieb Rowdy Rednose:
>
> > user=> (dosync (alter gnu-rms update-in [:key1 :key2 :key3] #(conj %
> > "foo")))
>
> > {:key1 {:key2 {:key3 #{"foo"
>
> You actually don't need the anonymous function...
>
> (dosy
On Jul 5, 1:20 pm, Adrian Cuthbertson
wrote:
> (dosync (alter rms assoc-in [:key1 :key2 :key3] "foo"))
> {:key1 {:key2 {:key3 "foo"}}}
I just found update-in, which is even better, as I want to update a
set:
user=> (def gnu-rms (ref {:key1 {:key2 {:key3 #{))
#'user/gnu-rms
user=> (dosync
On Jul 5, 1:23 pm, Richard Newman wrote:
> However, I'd point out that:
>
> * This might be a sign that you're doing things 'wrong'.
Could be. I'm still figuring out how to do things the functional way.
The reason I have these nested maps is to give my data structure. I
don't want to have a loos
Much better! Thanks.
On Jul 5, 1:20 pm, Adrian Cuthbertson
wrote:
> You could use assoc-in...
>
> (def rms (ref {:key1 {:key2 {:key3 #{))
>
> (dosync (alter rms assoc-in [:key1 :key2 :key3] "foo"))
> {:key1 {:key2 {:key3 "foo"}}}
>
> Rgds, Adria
Say I have a data structure like this
(def ref-map-map-map-set (ref {:key1 {:key2 {:key3 #{))
If I want to add a new member to the set which is the value of :key3,
I currently do this:
(dosync
(let [key1 (:key1 @ref-map-map-map-set)
key2 (:key2 key1)
key3 (:key3 key2)]
(re
ctional
Relational Programming", I'll probably immediately dump my code and
just use that... :)
On Jul 1, 9:18 pm, Matt Culbreth wrote:
> On Jul 1, 8:02 am, Rowdy Rednose wrote:
>
>
>
> > But it looks like I have to implement that myself - which is not a
> > compl
On Jul 1, 12:02 am, Chouser wrote:
> You could wrap a Ref around every value, if you chose, to
> allow independent changes to different "rows" at the same
> time -- though this would not help when inserting rows.
I guess having millions of Refs would not perform too well. Plus you
don't need tha
Would it be easy to implement an in-memory database in clojure that
allows concurrent access?
It sounds pretty easy, as most of the features are already provided by
Clojure. I'm not sure though about the "locking granularity".
Of course you don't pessimistically lock in Clojure, but if you have a
I find the pdf actually pretty useful as a quick reference until I'm
familiar with all the function names.
There's however a small mistake on page 28. The 'd' doesn't belong
there in the 2nd line of this example:
(let [{a :a, b :b, c :c, :as m :or {a 2 b 3}} {:a 5 :c 6}]
[a b c d m])
-> [5 3 6
Was it a deliberate decision to make io! optional or is this by
accident? I know it came in later
I guess it's hard to do considering all access to Java would have to
be categorized, which is impossible, I guess.
It just seems like Clojure loses a lot by not guaranteeing side-effect-
freeness, l
You are absolutely right about the names. Unfortunately all the good
ones are already taken by Rich. ;)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@goog
p is
> to decode the specific key it is assigned to.
>
> (def decoder-map {0 "Awesome" 1 "Not Awesome"})
>
> ;This will decode the key :a
> user=> (deftrans decoder :a decoder-map)
> #'user/decoder
>
> user=> (decoder test-map)
> {:a &q
e (fn [m k] (assoc m k (f (m k default map keys)))
On Jun 18, 5:06 pm, Rowdy Rednose wrote:
> Thanks for the ideas guys
>
> I especially like the reduce/assoc approach. It's the one most clear
> to me so far and also the most efficient one, I guess, as it does only
> one
inc 0) map keys))
>
> But its longer than yours :)
>
> On Jun 18, 3:21 pm, Rowdy Rednose wrote:
>
> > Say I've got this map of keys to integer values:
>
> > (def m {:one 0 :two 0 :three 0})
>
> > I want to write a function "inc-values-in-map"
Say I've got this map of keys to integer values:
(def m {:one 0 :two 0 :three 0})
I want to write a function "inc-values-in-map" that takes such a map,
a collection of keys and will increment those keys' values in the map.
In other words, calling
(inc-values-in-map m [:one :three])
should ret
Thanks all,
microbenchmarking shows that a simple
(time (doseq [[a b] (map vector list-a list-b)]))
is ~50% faster on my system than
(def par-doseq-fn (comp dorun map))
(defmacro par-doseq [bindings & body]
(let [bindings (partition 2 bindings)]
`(par-doseq-fn (fn ~(vec (map first b
On Mar 24, 12:01 am, Rowdy Rednose wrote:
>
> >> Hi group,
>
> >> say I have 2 sequences
>
> >> (def seq-a '("a1" "a2" "a3"))
> >> (def seq-b '("b1" "b2" "b3"))
>
> >&g
Hi group,
say I have 2 sequences
(def seq-a '("a1" "a2" "a3"))
(def seq-b '("b1" "b2" "b3"))
and want to iterate over them in parallel, like this
(par-doseq [a seq-a b seq-b] (prn a b))
which should print
"a1" "b1"
"a2" "b2"
"a3" "b3"
The way I do it currently is using "map" (and "last" to
What is the easiest way to make clojure's get function evaluate the
value for 'not-found' only if the key is not found? Do I have to write
a macro like
(defmacro my-get [map key not-found]
`(if (contains? ~map ~key)
(get ~map ~key)
~not-found))
--~--~-~--~~~--
s. You could then do something like
> (map = old_vec new_vec)
>
> And then look for false results in the array and send a notification to
> Swing.
>
> On Fri, Feb 20, 2009 at 5:40 AM, Rowdy Rednose wrote:
>
>
>
> > All the clojure swing examples I've seen s
All the clojure swing examples I've seen so far use JTables in a
static way, i.e. the data is not programmatically modified once the
table got created.
Has anyone actually tried to implement a TableModel that is backed by
a clojure Vector/Map and fires events to TableModelListeners when the
under
, levand wrote:
> Wow... that actually fixes it. Still a minor problem, since according
> to the Sun website, it is legal to create a Swing object in another
> thread as long as long as it is not "realized" yet...
>
> Still, this definitely is a doable workaround. Thanks!
it is not "realized" yet...
>
> Still, this definitely is a doable workaround. Thanks!
>
> -Luke
>
> On Dec 29, 9:17 pm, Rowdy Rednose wrote:
>
> > What if you run the Swing code in the Event Dispatch Thread?
>
> > In other words, does t
What if you run the Swing code in the Event Dispatch Thread?
In other words, does this:
(. javax.swing.SwingUtilities (invokeAndWait #(.
javax.swing.JOptionPane (showMessageDialog nil "Hello World"
or
(. javax.swing.SwingUtilities (invokeLater #(. javax.swing.JOptionPane
(showMessageDialog
ry&cells=tiles
So it will probably not be in 1.0
On 20 Dez., 11:30, Chouser wrote:
> On Fri, Dec 19, 2008 at 8:35 PM, Rowdy Rednose wrote:
>
> > Apart from being blasphemous - would it be a good idea to override
> > clojure.lang.Ref in Java land?
>
> > I want to c
ojure) the
relevant functions like ref-set etc.
Or is there anything else I missed?
On 20 Dez., 10:35, Rowdy Rednose wrote:
> Apart from being blasphemous - would it be a good idea to override
> clojure.lang.Ref in Java land?
>
> I want to create (children of?) refs in clojure that sen
elop this in Clojure land in an easy manner?
On 16 Dez., 20:58, Rowdy Rednose wrote:
> Can I listen on changes done to refs?
>
> Let's say in a scenario like that
> onhttp://en.wikibooks.org/wiki/Clojure_Programming#Mutation_Facilities
> could I add a facility that allows the reg
That's great news. Thanks Dave!
Re-reading http://clojure.org/agents I found it mentioned somewhere at
the end, almost like a small, unimportant footnote, easy to
overlook...
Now before I start working on a small and handy framework to handle
stuff similar to what's called biz objects / biz mode
If Rich adds watchers for refs, would watchers be notified inside the
transaction?
I'm actually trying to get a notification after a transaction
successfully finished. Although there might be use cases for firing
events inside the transaction.
On 17 Dez., 00:37, Stuart Sierra wrote:
> On Dec 16
The structure of the wikibook page has changed and that link doesn't
work any more.
This will:
http://en.wikibooks.org/wiki/Clojure_Programming/Concepts#Mutation_Facilities
On 16 Dez., 20:58, Rowdy Rednose wrote:
> Can I listen on changes done to refs?
>
> Let's say in a
There must be a smarter way to achieve this than polling the
collection for changes, I guess.
On 16 Dez., 21:43, Dave Griffith wrote:
> Right now, you add listeners to agents, but not refs. IIRC, there
> was talk of adding listeners to refs to enable just the sort of
> reactive programming you
Can I listen on changes done to refs?
Let's say in a scenario like that on
http://en.wikibooks.org/wiki/Clojure_Programming#Mutation_Facilities
could I add a facility that allows the registration of listeners that
get called on certain changes to the refs?
For example I'd like to be notified on
51 matches
Mail list logo