Re: Block on structure until some data appear

2010-05-14 Thread ka
@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

Artificial Intelligence in Clojure

2010-05-14 Thread nathaniel
I saw a post about this from June 2009 or thereabouts, but it did not get much follow-up. I'm curious about AI libraries for Clojure, partly since I imagine some Lisp AI code could be translated to Clojure fairly easily. I am doing some work on using Clojure with applications including some AI-in

Re: Splitting a string with the characters between each split?

2010-05-14 Thread joshua-choi
Excellent! This is exactly what I'm looking for; thanks everyone for their help. On May 13, 10:13 pm, Justin Kramer wrote: > clojure.contrib.string/partition does exactly what you're looking for. > > (require 'clojure.contrib.string) > (clojure.contrib.string/partition #"\s+" "ab c  de") > ;; ("a

Re: Block on structure until some data appear

2010-05-14 Thread Meikel Brandmeyer
Hi, On Fri, May 14, 2010 at 01:47:00PM -0700, ka wrote: > Isn't ensure necessary? Because http://clojure.org/refs says that - > "No changes will have been made by any other transactions to any Refs > that have been ref-set/altered/ensured by this transaction." It > doesn't guarantee that a ref

Re: Block on structure until some data appear

2010-05-14 Thread ka
> 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

Re: Block on structure until some data appear

2010-05-14 Thread Michael Jaaka
Thanks for help. I have just used synchronization mechanizm from Java. Here is a code: monitor.clj (ns michael.ds.monitor (:import [java.util.concurrent.locks ReentrantLock Condition ])) (defn create-monitor[] (ReentrantLock.)) (defn create-cond[m] (.newCondition m

Re: Microsoft drops Software Transactional Memory

2010-05-14 Thread Brian Hurt
The problem with STM is that it adds significant overheads to modification costs. In a "classic" imperative programming language like Java or C#, stores to variables compile down to simple memory writes- very cheap. An STM memory write, by contrast, is 10x or 100x more expensive (depending upon p

Re: Block on structure until some data appear

2010-05-14 Thread Meikel Brandmeyer
Hi, On Fri, May 14, 2010 at 10:59:34AM -0700, ka wrote: > (defn report-status [] > (dosync > (ensure my-hash) > (ensure new-keys) > (println @my-hash) > (println @new-keys) > )) You can get rid of the I/O in the transaction and still see a consistent snapshot by simply ret

Re: Block on structure until some data appear

2010-05-14 Thread ka
Few notes - 1. report status is not particularly good as it has io in a dosync. 2. Spelling of consume fn. 3. The consumers are not at all fair as they always take the first of the set. Please let me know if anyone sees some issues with the above code or how to make it better. On May 14, 10:59 pm

Re: Block on structure until some data appear

2010-05-14 Thread ka
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

Re: Microsoft drops Software Transactional Memory

2010-05-14 Thread Angel Java Lopez
Hi people! A 2008 paper, I just received today via twitter *Software transactional memory**: why is it only a research toy?* http://portal.acm.org/citation.cfm?id=1400228&coll=ACM&dl=ACM&CFID=90273999&CFTOKEN=67127907&ret=1#Fulltext Angel "Java" Lopez http://www.ajlopez.com http://twitter.com/aj

Re: ANN: try clojure

2010-05-14 Thread Raoul Duke
sweet. needs parenthesis match hilighting, tho ;-) -- 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.

Microsoft drops Software Transactional Memory

2010-05-14 Thread Brian
Not directly related to Clojure but I thought this would be of interest to folks: http://www.infoq.com/news/2010/05/STM-Dropped http://www.reddit.com/r/programming/comments/c4367/microsofts_experiments_with_software/ -- You received this message because you are subscribed to the Google Groups "C

Re: code review request: clojure.java.io

2010-05-14 Thread Michael Wood
On 14 May 2010 13:50, Stuart Halloway wrote: >> So if program runs from a particular directory and references files as >> file:///some/file, then if someone can create a directory called file: >> in that directory with some/file inside that, the program will >> suddenly try to access the wrong thi

Re: How can we replace an element in a deeply nested list?

2010-05-14 Thread Lee Spector
Ooo -- postwalk-replace, which I didn't know about, is much better than what I was going to suggest! But since this still might be of some interest to the OP here is the message I had composed before ajuc's message came through: --- Setq doesn't do that in Lisp, but subst does. I've defined su

Re: How can we replace an element in a deeply nested list?

2010-05-14 Thread ajuc
Setq isn't functional - equivalent in clojure would be def, but it isn't meant to be used in that way. For your purpose there is better fit: postwalk-replace http://richhickey.github.com/clojure/clojure.walk-api.html#clojure.walk/postwalk-replace Greetings. -- You received this message because

How can we replace an element in a deeply nested list?

2010-05-14 Thread krsnewwave
Hi all, I'm new to this language and is working on a few problems on my own. I have this deep list, (of arbitrary depth, because I am trying to work out a genetic program..) and I want to change, say, all x's in this list. Replace doesn't work. Do I really have to define a recursive function to "

Re: Getting line numbers in stack traces

2010-05-14 Thread LordGeoffrey
As a newbie, this is the biggest frustration i have with clojure. Coming from a scheme background i regularly type (defn (func a b v) .. ) That produces a completely non-specific and non-locatable error message. I occasionally resort to cutting my files in halves until i locate the offending li

Re: ANN: try clojure

2010-05-14 Thread David Nolen
Pretty cool. Been waiting for this. My main criticism is that it isn't very pretty :) Is there a github repo for it so people can fork it and play around with CSS? Also how difficult would it be to build a tutorial for it like the ones that http://tryhaskell.org and http://tryruby.org have? Would b

Re: code review request: clojure.java.io

2010-05-14 Thread Stuart Halloway
So if program runs from a particular directory and references files as file:///some/file, then if someone can create a directory called file: in that directory with some/file inside that, the program will suddenly try to access the wrong thing? Seems suspicious to me. Two points: (1) This is n

Re: Adding docstrings to def?

2010-05-14 Thread ka
> 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

Re: ANN: try clojure

2010-05-14 Thread Heinz N. Gies
On May 13, 2010, at 9:11 , Michael Wood wrote: > By the way, I don't get StackOverflowErrors when I expect to. e.g.: > > ((fn blah [] (+ 1 (blah > > just sits there, apparently doing nothing. On May 13, 2010, at 10:10 , Wilson MacGyver wrote: > Great work, but the tryhaskell link is wr

Re: Getting line numbers in stack traces

2010-05-14 Thread Meikel Brandmeyer
Hi, On Thu, May 13, 2010 at 09:17:54PM -0700, MarkSwanson wrote: > If there are problems, just switch buffers, edit, \ef, switch back to > the REPL and call (higher-up 12) again. rinse, repeat... Just some gotchas: * With \ef the file buffer will be evaluated. That means the line numbers are

Re: code review request: clojure.java.io

2010-05-14 Thread Laurent PETIT
2010/5/14 Michael Wood : > On 14 May 2010 04:32, Stuart Halloway wrote: >>> On 13 May 2010 03:02, Stuart Halloway wrote: > >  * Decidedly, I have bad feelings when I read about the "magic" of > "coercing" a String first as a URL, and if not possible, fall back and > consider it a