Re: Keeping a ref and a DB in sync

2009-04-06 Thread Brian Carper

On Apr 3, 12:42 pm, rzeze...@gmail.com rzeze...@gmail.com wrote:
 Brian, I imagine you are asking this in relation to your blog engine?

Yep.  Thanks everyone for the help and ideas.  Unfortunately I do have
a ton of data in a DB already so Terracotta would be a lot of work.  I
rewrote everything to do ref updates inside agents, and it worked
(almost), but when I fired up 1000 concurrent threads to do
simultaneous updates and set a certain percentage of them to throw an
exception mid-transaction, I still ended up with the DB and the in-
memory copy out of sync.  Cleaning up when something failed was a
nightmare to try to coordinate.

I ended up storing all of my data in a single ref that holds the state
of the universe and running a background thread in an agent that grabs
a snapshot of the ref and syncs it with the DB every so often.  I
guess it's probably a little more Clojure-ish that way anyways, since
the DB will always see a consistent snapshot.  If this doesn't work
I'll have to try watches I guess.
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: introspect namespace ?

2009-04-06 Thread Adrian Cuthbertson

Nice case of clojure reductio :-)

On Mon, Apr 6, 2009 at 7:51 AM, Stephen C. Gilardi squee...@mac.com wrote:
 (str *ns*)

 On Apr 6, 2009, at 1:27 AM, Kevin Downey wrote:

 (.toString *ns*)

 On Sun, Apr 5, 2009 at 12:39 PM, Stephen C. Gilardi squee...@mac.com
 wrote:


       (- *ns* ns-name name)


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: DISCUSS: clojure.contrib.java-utils/file

2009-04-06 Thread James Reeves

On Apr 6, 4:10 am, Stuart Sierra the.stuart.sie...@gmail.com wrote:
 I don't see an obvious way of combining them.

What about something like:

(defn- normalize-separator
  [filepath]
  (.. (str filepath)
(replace \\ File/separatorChar)
(replace \/ File/separatorChar)))

(defn file
  [filepath  more]
  (reduce
(fn [parent path] (File. parent path))
(File. (normalize-separator filepath))
(map normalize-separator more)))

- James
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: DISCUSS: clojure.contrib.java-utils/file

2009-04-06 Thread Michael Wood

On Mon, Apr 6, 2009 at 10:40 AM, James Reeves
weavejes...@googlemail.com wrote:

 On Apr 6, 4:10 am, Stuart Sierra the.stuart.sie...@gmail.com wrote:
 I don't see an obvious way of combining them.

 What about something like:

 (defn- normalize-separator
  [filepath]
  (.. (str filepath)
    (replace \\ File/separatorChar)
    (replace \/ File/separatorChar)))

What?  You mean I won't be able to use backslashes in my filenames
anymore? :)  (Yes, a backslash is perfectly legal in a filename on
Unix filesystems, although I agree it's probably not a good idea to
use them.)

 (defn file
  [filepath  more]
  (reduce
    (fn [parent path] (File. parent path))
    (File. (normalize-separator filepath))
    (map normalize-separator more)))

-- 
Michael Wood esiot...@gmail.com

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: DISCUSS: clojure.contrib.java-utils/file

2009-04-06 Thread Jason Sankey

James Reeves wrote:
 On Apr 6, 4:10 am, Stuart Sierra the.stuart.sie...@gmail.com wrote:
 I don't see an obvious way of combining them.
 
 What about something like:
 
 (defn- normalize-separator
   [filepath]
   (.. (str filepath)
 (replace \\ File/separatorChar)
 (replace \/ File/separatorChar)))
 
 (defn file
   [filepath  more]
   (reduce
 (fn [parent path] (File. parent path))
 (File. (normalize-separator filepath))
 (map normalize-separator more)))

I think there may be a misunderstanding over combining here - I read 
Stuart's mail to mean there was no obvious way to combine 
duck-streams/file and java-utils/file, whereas this implementation shows 
java-utils/file style behaviour only?

IMO even if the two functions could be combined, it would be confusing 
to understand how the arguments passed in would be joined.  Better not 
to try.

FWIW, the java-utils version is similar to a utility method that I use 
pretty heavily in Java code -- so I will find it useful.

Cheers,
Jason

-- 
Pulse - Continuous Integration made easy.
Does your project have a pulse?
Try it free at: http://zutubi.com

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



lazy seqs (was Re: proposed new contrib: java-utils)

2009-04-06 Thread Stuart Halloway

r652 is a breaking change to contrib. (powers-of-2) and (fibs) are now  
functions and do not hold their heads. primes is still a sequence  
because it needs to hold past values for efficiency.

Stuart

 On Apr 5, 2009, at 4:27 PM, Stuart Halloway wrote:

 At quick glance it looks to me that all three of the lazy-seqs should
 be functions. If you want me to I'll change this and add tests.

 Please do. Thanks.

 --Steve



--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: DISCUSS: clojure.contrib.java-utils/file

2009-04-06 Thread James Reeves

On Apr 6, 11:29 am, Jason Sankey ja...@zutubi.com wrote:
 I think there may be a misunderstanding over combining here - I read
 Stuart's mail to mean there was no obvious way to combine
 duck-streams/file and java-utils/file, whereas this implementation shows
 java-utils/file style behaviour only?

As far as I'm aware, it has most of both behaviours.

 IMO even if the two functions could be combined, it would be confusing
 to understand how the arguments passed in would be joined.  Better not
 to try.

That's true. Conceptually, I prefer the java-utils/file method, which
is basically the same as an identically named function I wrote for
Compojure.

The problem with having java-utils/file and duck-streams/file is that
you lose the ability to load both namespaces at the same time without
defining an exception for the file function. This does not seem like
an ideal solution. I think we should choose one or the other, give
them different names, or attempt to merge their functionality.

- James
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: No I/O in STM transactions?

2009-04-06 Thread Hugh Winkler

On Mon, Apr 6, 2009 at 12:58 AM, Dex Wood slash2...@gmail.com wrote:

 If you want to do I/O from a transaction, just use an agent to do the
 I/O.  Since the agent is only sent off at commit, you don't have to
 worry about retries.  This doesn't answer your questions about
 idempotent I/O, but I think it is a strategy that you can use.

Yes, thanks very much for this tip! I have to admit I didn't (don't)
understand the agent concept. I've been avoiding the subject I guess.
Going to have a look now...



 On Apr 5, 2:11 pm, Hugh Winkler hwink...@gmail.com wrote:
 Hi all,

 Fromhttp://clojure.org/refs: I/O and other activities with
 side-effects should be avoided in transactions, since transactions
 will be retried. The io! macro can be used to prevent the use of an
 impure function in a transaction.

 Isn't it OK to do I/O in a transaction as long as doing the operation
 multiple times has the same effect as doing it once (i.e. it's
 idempotent)?

 Isn't it also OK to read data in a transaction, in many circumstances?
 Even if retrying the reads results in a different end state, that's OK
 for lots of systems. Example: couldn't I safely read a stock price
 from a ticker stream within a transaction, if the purpose was only to
 have a cached value from sometime in the last 5 minutes?

 (I imagine there are performance considerations. Retrying some I/O
 operations could be expensive. Right now, I'm concerned with the
 logic, not the performance, but if you know something about the
 performance implications, please jump in).

 Just hoping someone can straighten me out if I'm wrong... I'd like to
 remove some io! macros from my code!

 Thanks,
 Hugh
 

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: DISCUSS: clojure.contrib.java-utils/file

2009-04-06 Thread Jason Sankey

James Reeves wrote:
 On Apr 6, 11:29 am, Jason Sankey ja...@zutubi.com wrote:
 I think there may be a misunderstanding over combining here - I read
 Stuart's mail to mean there was no obvious way to combine
 duck-streams/file and java-utils/file, whereas this implementation shows
 java-utils/file style behaviour only?
 
 As far as I'm aware, it has most of both behaviours.

I guess the confusion is mine :).  I saw the primary difference as 
joining args with or without separators in between.

 IMO even if the two functions could be combined, it would be confusing
 to understand how the arguments passed in would be joined.  Better not
 to try.
 
 That's true. Conceptually, I prefer the java-utils/file method, which
 is basically the same as an identically named function I wrote for
 Compojure.

I also feel the java-utils version is more generally-applicable - it 
makes composing files easier without any assumptions about its input. 
The duck-streams version does other handy things like separator 
normalisation and tilde expansion, but that means it can't be used for 
all cases.  It feels like the latter is convenient for composing 
filenames from literals or at the repl, but not so good for handling 
arbitrary files/paths.

 The problem with having java-utils/file and duck-streams/file is that
 you lose the ability to load both namespaces at the same time without
 defining an exception for the file function. This does not seem like
 an ideal solution. I think we should choose one or the other, give
 them different names, or attempt to merge their functionality.

Generally speaking I'm happy to use (require [ ... :as ...]) to solve 
this problem (I expect as contrib grows name clashes will become 
inevitable).  In any case your point still stands from a conceptual 
point of view - having two functions named file in contrib with 
similar goals but different semantics is a recipe for confusion.

Cheers,
Jason

-- 
Pulse - Continuous Integration made easy.
Does your project have a pulse?
Try it free at: http://zutubi.com

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: proposed new contrib: java-utils

2009-04-06 Thread Perry Trolard

Hi Stuart,

I had occasion to wrap java.util.Properties. If there's interest, may
be a good candidate for c.c.java-utils.

It's pasted in below,  attached in the group at

http://clojure.googlegroups.com/web/props.clj

Feel free to change as you see fit.

Best,
Perry



(ns props
  ; Convenience lib for interacting with java.util.Properties
  (:use [clojure.contrib.duck-streams  :only (reader writer)]
[clojure.contrib.java-utils:only (the-str)])
  (:import (java.util Properties)))

(defn props-to-map
  Convert Properties to map.
  [p]
  (into {} p))

(defn map-to-props
  Convert map to Properties.
  {:tag Properties}
  [m]
  (let [p (Properties.)]
(doseq [[k v] m]
  (.setProperty p (the-str k) (str v)))
p))

(defn read-props
  Read Properties from file into map. Uses duck-streams/reader to
read from file,
  so duck-streams/*default-encoding* determines character decoding.
  [file]
  (props-to-map
(with-open [rdr (reader file)]
  (doto (Properties.)
(.load rdr)

(defn write-props
  Write Properties from map into file. Uses duck-streams/writer to
write to file,
  so duck-streams/*default-encoding* determines character encoding.
  {:tag Properties}
  ([m file] (write-props m file nil))
  ([m file comments]
(with-open [wtr (writer file)]
  (doto (map-to-props m)
(.store wtr comments)




--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: A syntax feature request: splitting literal strings

2009-04-06 Thread Nathan Kitchen

On Apr 4, 4:16 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote:
 This can be macro-ized:

 (defmacro bigstr [ strings]
   Concatenates strings at compile time.
   (apply str strings))

 user (macroexpand-1 '(bigstr This is a really long string 
   that I just felt like using 
   in my program.))
 This is a really long string that I just felt like using in my
 program.

Umm...how is bigstr different from str itself?

-- Nathan
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: A syntax feature request: splitting literal strings

2009-04-06 Thread Laurent PETIT
2009/4/6 Nathan Kitchen nathan.kitc...@gmail.com


 On Apr 4, 4:16 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote:
  This can be macro-ized:
 
  (defmacro bigstr [ strings]
Concatenates strings at compile time.
(apply str strings))
 
  user (macroexpand-1 '(bigstr This is a really long string 
that I just felt like using 
in my program.))
  This is a really long string that I just felt like using in my
  program.

 Umm...how is bigstr different from str itself?


bigstr is a macro, that will only work at compile with literal strings.

HTH,

-- 
Laurent

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: A syntax feature request: splitting literal strings

2009-04-06 Thread Laurent PETIT
2009/4/4 samppi rbysam...@gmail.com


 I don't really want it so much for documentation strings—they're
 already formatted in a standard way [...]


Well, they certainly are formatted in *a* standard way :-), e.g. they have a
hard-coded formatted only suitable as-is for 80 columns wide terminals :-)

Indeed, for IDEs that allow users to resize the windows providing this
documentation information (e.g. with auto-completion features), they
generally end up with lots of unused spaces.

Or the IDEs have to guess (but maybe some rules are written somewhere I
didn't find) the proper algorithm to be used to reconstitutes sentences
that should not have been breaked by newlines in the source code.

I intend to do the following in clojuredev: split the docstrings at every
occurence of 2 consecutive line breaks. For each item of this list, if it is
only made of line breaks, leave as is, else remove the line breaks.
Recompose a String by interposing 2 consecutive line breaks between each
item.

-- 
Laurent

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: How do you handle different string encodings?

2009-04-06 Thread Daniel Jomphe

I finally worked it all out.

For future reference, here's a record of my research on this:
http://stackoverflow.com/questions/715958/how-do-you-handle-different-string-encodings


Daniel Jomphe wrote:
 I made some progress.

 [By the way, NetBean's console displays *everything* 100% fine.
  I decided to use one of the worst repl consoles: that of IntelliJ.
  I want to make sure I really understand what's the point behind all
 this.]

   (import '(java.io PrintWriter PrintStream FileInputStream)
           '(java.nio CharBuffer ByteBuffer)
           '(java.nio.charset Charset CharsetDecoder CharsetEncoder)
           '(org.xml.sax InputSource))

   (def   utf8 UTF-8)
   (def d-utf8 (.newDecoder (Charset/forName utf8)))
   (def e-utf8 (.newEncoder (Charset/forName utf8)))

   (def   latin1 ISO-8859-1)
   (def d-latin1 (.newDecoder (Charset/forName latin1)))
   (def e-latin1 (.newEncoder (Charset/forName latin1)))

   (defmacro with-out-encod
     [encoding  body]
     `(binding [*out* (PrintWriter. (PrintStream. System/out true
 ~encoding) true)]
               ~...@body
               (flush)))

   (def s québécois français)

   (print s)                         ;quÔøΩbÔøΩcois franÔøΩaisnil
   (with-out-encod latin1 (print s)) ;qu?b?cois fran?aisnil
   (with-out-encod utf8   (print s)) ;qu?b?cois fran?aisnil

   (def encoded (.encode e-utf8
                         (CharBuffer/wrap québécois français)))
   (def s-d
     (.toString (.decode d-utf8 encoded)))

   (print s-d)                         ;quÔøΩbÔøΩcois franÔøΩaisnil
   (with-out-encod latin1 (print s-d)) ;qu?b?cois fran?aisnil
   (with-out-encod utf8   (print s-d)) ;qu?b?cois fran?aisnil

   (def f-d
     (:content (let [x (InputSource. (FileInputStream. french.xml))]
          (.setEncoding x latin1)
          (clojure.xml/parse x

   (print f-d)                         ;quÔøΩbÔøΩcois franÔøΩaisnil
   (with-out-encod latin1 (print f-d)) ;québécois français
   (with-out-encod utf8   (print f-d)) ;québécois français

 So my theory, which is still almost certainly wrong, is:

 1. When the input is a file whose encoding is, say, latin-1, it's easy
 to decode it and then encode it however one wants.
 2. When the input is a literal string in the source file, it looks
 like it's impossible to encode it correctly, unless one first decodes
 it from the source file's encoding. But then, I don't yet know how to
 do this without actually reading the source file. :\

 Daniel Jomphe wrote:
  I tried under eclipse.

  Default console encoding configuration (MacRoman):

    #'user/s
    quÔøΩbÔøΩcois franÔøΩaisnil
    qu?b?cois fran?aisnil

    #'user/snc
    qu?b?cois fran?aisnil
    qu?b?cois fran?aisnil

  Console configured to print using ISO-8859-1:

    #'user/s
    qu�b�cois fran�aisnil
    qu?b?cois fran?aisnil

    #'user/snc
    qu?b?cois fran?aisnil
    qu?b?cois fran?aisnil

  Console configured to print using UTF-8:

    #'user/s
    québécois françaisnil
    québécois françaisnil

    #'user/snc
    québécois françaisnil
    québécois françaisnil

  So as I come to understand it, it looks like UTF-8 should be the rolls-
  royce for my needs.

  May I correctly conclude the following?

    Don't bother about encodings unless you're displaying something and
  it's unreadable; then, don't bother about it in the code; find a
  proper console or viewer.

  Doesn't that sound like offloading a problem to users? Isn't there
  something reliable that can be done in the code?

  Daniel Jomphe wrote:
   Sorry for all these posts.

   I pasted my last post's code into a fresh repl (not in my IDE), and
   here's what I got (cleaned up):

     #'user/s
     québécois françaisnil
     qu?b?cois fran?aisnil

     #'user/snc
     québécois françaisnil
     qu?b?cois fran?aisnil

   I'm not sure what to make out of it.

   My terminal (Apple Terminal) supports the encoding, and prints
   correctly s and snc out of the box.
   When I use with-out-encoded, I actually screw up both s and snc's
   printing.

   Daniel Jomphe wrote:
Now that I know for sure how to bind *out* to something else over
System/out, it's time to bring back my encoding issues into scope:

  (import '(java.io PrintWriter PrintStream))

  (defmacro with-out-encoded
    [encoding  body]
    `(binding [*out* (java.io.PrintWriter. (java.io.PrintStream.
System/out true ~encoding) true)]
              ~...@body
              (flush)))

  (def nc ISO-8859-1)

  ;;; with a normal string
  (def s québécois français)

  (print s)
  ; quÔøΩbÔøΩcois franÔøΩaisnil

  (with-out-encoded nc (print s))
  ; qu?b?cois fran?aisnil

  ;;; with a correctly-encoded string
  (def snc (String. (.getBytes s nc) nc))

  (print snc)
  ; qu?b?cois fran?aisnil

  (with-out-encoded nc (print snc))
  ; qu?b?cois fran?aisnil

I'm certainly missing something fundamental somewhere.

Re: DISCUSS: clojure.contrib.java-utils/file

2009-04-06 Thread Victor Rodriguez

Hello,

On Mon, Apr 6, 2009 at 10:06 AM, James Reeves
weavejes...@googlemail.com wrote:

...
 The problem with having java-utils/file and duck-streams/file is that
 you lose the ability to load both namespaces at the same time without
 defining an exception for the file function. This does not seem like
 an ideal solution. I think we should choose one or the other, give
 them different names, or attempt to merge their functionality.

IMHO. what you want to avoid is having similar utility functions in
different projects.  Thus, duck-streams could just use the version of
file of java-utils, or keep its own version private.

Cheers,

Victor Rodriguez.

 - James
 


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Simple dosync/alter question

2009-04-06 Thread bgray

I have a some what (I believe) easy question.  Could someone let me
know what I'm doing wrong?  A simplified version of what I'm trying to
do looks like this:

user= (def foo (ref 0))
#'user/foo
user= (defn square [x] (* x x))
#'user/square
user= (defn square-ref [x] (dosync (alter foo square x)))
#'user/square-ref
user= (square-ref 2)
java.lang.IllegalArgumentException: Wrong number of args passed to:
user$square (NO_SOURCE_FILE:0)
user= (doc square)
-
user/square
([x])
  nil
nil
user=

Thanks,
Brandon
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Simple dosync/alter question

2009-04-06 Thread Paul Stadig
Alter expects a function that take the current value of the ref it will
alter as the first arg. I think what you want to do is ref-set.

user= (doc alter)
-
clojure.core/alter
([ref fun  args])
  Must be called in a transaction. Sets the in-transaction-value of
  ref to:

  (apply fun in-transaction-value-of-ref args)

  and returns the in-transaction-value of ref.
nil
user= (doc ref-set)
-
clojure.core/ref-set
([ref val])
  Must be called in a transaction. Sets the value of ref.
  Returns val.
nil

user= (defn square-ref [x] (dosync (ref-set foo (square x
#'user/square-ref
user= (square-ref 2)
4
user= @foo
4


Paul

On Mon, Apr 6, 2009 at 3:02 PM, bgray graybran...@gmail.com wrote:


 I have a some what (I believe) easy question.  Could someone let me
 know what I'm doing wrong?  A simplified version of what I'm trying to
 do looks like this:

 user= (def foo (ref 0))
 #'user/foo
 user= (defn square [x] (* x x))
 #'user/square
 user= (defn square-ref [x] (dosync (alter foo square x)))
 #'user/square-ref
 user= (square-ref 2)
 java.lang.IllegalArgumentException: Wrong number of args passed to:
 user$square (NO_SOURCE_FILE:0)
 user= (doc square)
 -
 user/square
 ([x])
  nil
 nil
 user=

 Thanks,
 Brandon
 


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Simple dosync/alter question

2009-04-06 Thread David Nolen
I think what you want is:
(def foo (ref 0))
(defn square [x] (* x x))
(defn square-ref [x] (dosync (ref-set foo (square x
(square-ref 2)

On Mon, Apr 6, 2009 at 3:02 PM, bgray graybran...@gmail.com wrote:


 I have a some what (I believe) easy question.  Could someone let me
 know what I'm doing wrong?  A simplified version of what I'm trying to
 do looks like this:

 user= (def foo (ref 0))
 #'user/foo
 user= (defn square [x] (* x x))
 #'user/square
 user= (defn square-ref [x] (dosync (alter foo square x)))
 #'user/square-ref
 user= (square-ref 2)
 java.lang.IllegalArgumentException: Wrong number of args passed to:
 user$square (NO_SOURCE_FILE:0)
 user= (doc square)
 -
 user/square
 ([x])
  nil
 nil
 user=

 Thanks,
 Brandon
 


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: ANN: Pretty printer is now part of contrib

2009-04-06 Thread Tom Faulhaber

There are a bunch of things in the build file that do nothing without
complaining when clojure.jar isn't set.

I didn't want to make a radical change to the build file with this
checkin but I didn't want users to not get the pretty printer and
wonder why either.

More generally, I think we need to think through how we want contrib
built and tested. I would say that we probably want to force the
compile and fail if clojure.jar isn't specified. And as you say, make
test running dependent on clojure-contrib.jar having been built. (In
general, ant's predilection for ignoring failure has always befuddled
me.)

Another question is whether we should duplicate the classes and
the .clj files in the jar or should we just compile all of them. Is
there some value to having the source there?

I'm happy to tweak these things if we have consensus on how we'd like
to do it.

Tom

On Apr 6, 5:37 am, Stuart Halloway stuart.hallo...@gmail.com wrote:
 Hi Tom,

 I think that the ant test tasks should depend on the compilation  
 tasks, and that users will just have to specify a clojure.jar.

 Either that or the default test suite should be smart enough to skip  
 the pretty printer tests with ant.jar not specified.

 Stuart

  By (semi-)popular demand, I have added the pretty printer and the
  Common Lisp format function (which are really the same package) into
  clojure.contrib. It all lives in the namespace clojure.contrib.pprint.

  Important: If you want to use pretty printing, you will have to
  compile all the source code in clojure.contrib and not just put it in
  in the jar. To do this, need to tell ant where clojure.jar is so that
  it can run the compiler. For example, I use:

   ant -Dclojure.jar=../clojure/clojure.jar

  (This is necessary because pretty printing uses a couple of gen-
  classed classes to wrap java Writers.)

  I haven't done that much work on the pretty printer since my last
  announcement, but there are a few improvements:

  - I added support for *print-level* and *print-length* to control how
  much output you get.
  - Support for a bunch more special forms and let-like structures in
  *code-dispatch*
  - Support for pretty printing Java arrays
  - ~3x basic speedup (or 3x less slow, depending on how you look at
  it). On my machine, this translates into about 300 lines of code/
  second. More to come here...
  - Some fixes to allow for deeper structures (as in very deep)
  without blowing the stack.

  All in all, it should be a pretty serviceable pretty printer. More
  coming, though...

  The documentation is still on github, but I've updated it for
  clojure.contrib. Look here:http://github.com/tomfaulhaber/cl-format.

  Please let me know if you have issues, suggestions, stuff you'd like
  to see first, etc.
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Simple dosync/alter question

2009-04-06 Thread David Sletten


On Apr 6, 2009, at 9:02 AM, bgray wrote:


 I have a some what (I believe) easy question.  Could someone let me
 know what I'm doing wrong?  A simplified version of what I'm trying to
 do looks like this:

 user= (def foo (ref 0))
 #'user/foo
 user= (defn square [x] (* x x))
 #'user/square
 user= (defn square-ref [x] (dosync (alter foo square x)))
 #'user/square-ref
 user= (square-ref 2)
 java.lang.IllegalArgumentException: Wrong number of args passed to:
 user$square (NO_SOURCE_FILE:0)


Paul and David N. have already given you the right advice. But to  
help you understand why your square-ref function didn't work, compare  
it to this:
(defn square-ref [x] (dosync (alter foo (fn [_] (square x)

Do you see the difference?

Aloha,
David Sletten


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Experiments in unit testing

2009-04-06 Thread James Reeves

Hi folks,

A while ago I started writing a unit testing library called Fact that
was a cross between Haskell's QuickCheck, and Ruby's RSpec. I've done
a lot of work with it, and some people might conceivably be interested
in how I got on with it, so this post is to chart what I found whilst
playing around with Fact.

I had two basic ideas for Fact. The first was to allow tests to be
labelled with a string, rather than with a symbol:

(fact One plus one equals two []
  (= (+ 1 1) 2))

This seemed like a good idea, but it turned out to have some problems.
Plain-English descriptions tend to change around more than symbols, so
aren't very good at uniquely identifying an object. To get around
this, I used gensym to create a random symbol to use as an identifier,
but this broke namespace reloading, as each time the file was loaded,
it generated completely new symbols.

So in retrospect, labelling tests with strings turned out to be a bit
more trouble than it was worth.

The second major idea for Fact was to make it simple to generate large
amounts of random test data, and to apply this data to a single
predicate or 'fact':

(fact x + y  x if x  0
  [x (random-int)
   y (random-int)]
  (if ( x 0) ( (+ x y) x)))

The above syntax generates a list of random numbers and applies them
to the bottom predicate. This makes it pretty simple to test
predicates with large amounts of data.

This seemed like an interesting idea, so I used Fact to unit test my
web framework, to see how it would work in practise. It turned out
that it worked quite well for functions that manipulated simple data
structures, like numbers or strings, and less well for functions that
manipulated more complex arrangements of maps and vectors.

The problem with this is that functions that manipulate simple data
tend to be quite easy to test, anyway. A few carefully chosen points
of test data can vastly reduce the probability the function is
incorrect. And when your input data becomes more complex, and thus
more prone to error, creating a function to randomly generate this
complex data becomes difficult enough that I started to find myself
avoiding writing tests for these complex cases.

So I decided to rewrite my unit tests using test-is. Symbols aren't as
descriptive as strings, but they have the advantage of being able to
be reloaded easily, so I could run a Nailgun server for seriously
quick unit tests. Since I wasn't generating all that random data any
more, my tests ran several orders of magnitude faster - down from half
a minute to under half a second. I also found that my tests were
easier to write, with only a few exceptions.

My conclusion is that automatically generated test data is probably
more trouble than it's worth in most cases. I'm going to keep Fact
around in case anyone wants to play with it, but I think I'll wind up
the experiment and mark it down as a lesson learned.

- James
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure, Android and Emacs on Ubuntu tutorials

2009-04-06 Thread Nick Levine

I've been trying to get Clojure/Android up and running today.

The pure java example in http://riddell.us/tutorial/android/android.html
works fine.

I tried the hello world example as in
http://riddell.us/tutorial/clojure_android/clojure_android.html and
get the following message from the emulator: The application
TestProject (process us.riddell) has stopped unexpectedly. Please try
again.

I have no idea where to hit this to get it to be nicer to me. I'm
running on Windows, jdk version 1.6.0_13, in case that matters.

Thanks in advance.

- nick

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



clojure + android

2009-04-06 Thread Nick Levine

Apologies for what might be multiple postings. Looks like google
swallowed the first one without chewing.

I've been trying to get clojure + android going but without much
success. In case it's relevant, I'm on Windows (XP) and the java
version is 1.6.0_13.

I followed http://riddell.us/tutorial/android/android.html and
http://riddell.us/tutorial/clojure_android/clojure_android.html
(expect that I'm driving the Android emulator from the command line
rather than emacs).

I've got the pure Java verison working OK. I've got clojure working OK
at the command line. When I try the hello-world example in the
clojure_android tutorial I get a message from the Emulator telling me
that the application has stopped unexpectedly (and it doesn't say
hello).

Does anyone know how to debug this? (Other than Eclipse.) Or even:
what might cause this message?

Thanks,

- nick


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



keyword and /

2009-04-06 Thread Andrew Rimes

Hello,

This tripped me up today:

user= (:the/key { :the/key the val}) ; ok
the val

user= (:the/key { (keyword the/key) the val}) ; returns nil?
nil

Shouldn't both return the val?

Thanks,

Andrew

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: keyword and /

2009-04-06 Thread Stephen C. Gilardi

The call to keyword here:

user= (:the/key {(keyword the key) the val})
the val

creates a keyword whose namespace part is the and whose name part is  
key just like :the/key.


Does this accomplish what you're after or are you specifically  
requesting that (keyword the/key) be made to work?


--Steve

On Apr 6, 2009, at 2:45 AM, Andrew Rimes wrote:



Hello,

This tripped me up today:

user= (:the/key { :the/key the val}) ; ok
the val

user= (:the/key { (keyword the/key) the val}) ; returns nil?
nil

Shouldn't both return the val?

Thanks,

Andrew

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---





smime.p7s
Description: S/MIME cryptographic signature


Re: keyword and /

2009-04-06 Thread Andrew Rimes


On 6-Apr-09, at 6:22 PM, Stephen C. Gilardi wrote:

 The call to keyword here:

   user= (:the/key {(keyword the key) the val})
   the val

 creates a keyword whose namespace part is the and whose name part  
 is key just like :the/key.

 Does this accomplish what you're after or are you specifically  
 requesting that (keyword the/key) be made to work?

Yeah, that is alright. Thanks.

 --Steve

 On Apr 6, 2009, at 2:45 AM, Andrew Rimes wrote:


 Hello,

 This tripped me up today:

 user= (:the/key { :the/key the val}) ; ok
 the val

 user= (:the/key { (keyword the/key) the val}) ; returns nil?
 nil

 Shouldn't both return the val?

 Thanks,

 Andrew

 



--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



New release of the enclojure plugin is up.

2009-04-06 Thread Eric Thorsen

There is a new release of the Enclojure plugin that addresses many of
the items I have seen discuss here recently with regards to managing
classpaths in REPLs as well as many other Clojure development
scenarios.  The plugin supports several use cases for the clojure.main
REPL use:
a. Project based REPLs where the REPL is started using the
dependancies on the project in the IDE.
b. Remote REPLs where some shim code can be included in your
application(s) and you can attach a REPL (or REPLs) to running VMs.
c. Ad-hoc REPLs - manually set your classpaths and start a REPL up.
All of these scenarios have strong integration with the editor
supporting integrated Clojure/Java completion, debugging with viewable
clojure data, syntax highlighting, code loading, expression
evaluation, s-expression nav and many more features.  There have been
well over 100 patches since the last release in February.
For more information, please see:
http://enclojure.wikispaces.com
Plugin can be downloaded at:
http://code.google.com/p/enclojure-nb-clojure-plugin/downloads/list

Feedback welcome!
Eric


Eric Thorsen
ThorTech Solutions
www.thortech-solutions.com
(914) 302-7638  [work]
(914) 302-7641  [fax]
(914) 804-4954  [cell]
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure + android

2009-04-06 Thread Onorio Catenacci

On Apr 6, 12:28 pm, Nick Levine n...@ravenbrook.com wrote:
 Apologies for what might be multiple postings. Looks like google
 swallowed the first one without chewing.

 I've been trying to get clojure + android going but without much
 success. In case it's relevant, I'm on Windows (XP) and the java
 version is 1.6.0_13.

 I 
 followedhttp://riddell.us/tutorial/android/android.htmlandhttp://riddell.us/tutorial/clojure_android/clojure_android.html
 (expect that I'm driving the Android emulator from the command line
 rather than emacs).

 I've got the pure Java verison working OK. I've got clojure working OK
 at the command line. When I try the hello-world example in the
 clojure_android tutorial I get a message from the Emulator telling me
 that the application has stopped unexpectedly (and it doesn't say
 hello).

 Does anyone know how to debug this? (Other than Eclipse.) Or even:
 what might cause this message?


Hi Nick,

I've been able to get the example app that Remco was kind enough to
provide working and I'm pretty sure I got it working on Windows XP
(I'm on a MacBook now).  I'd try Remco's example and see what you get.

--
Onorio
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure + android

2009-04-06 Thread Onorio Catenacci

On Apr 6, 12:28 pm, Nick Levine n...@ravenbrook.com wrote:
 Apologies for what might be multiple postings. Looks like google
 swallowed the first one without chewing.

 I've been trying to get clojure +androidgoing but without much
 success. In case it's relevant, I'm on Windows (XP) and the java
 version is 1.6.0_13.

 I 
 followedhttp://riddell.us/tutorial/android/android.htmlandhttp://riddell.us/tutorial/clojure_android/clojure_android.html
 (expect that I'm driving theAndroidemulator from the command line
 rather than emacs).

 I've got the pure Java verison working OK. I've got clojure working OK
 at the command line. When I try the hello-world example in the
 clojure_android tutorial I get a message from the Emulator telling me
 that the application has stopped unexpectedly (and it doesn't say
 hello).

 Does anyone know how to debug this? (Other than Eclipse.) Or even:
 what might cause this message?


Sorry Nick--forgot to include the link:

http://github.com/remvee/clojurehelloandroid/

--
Onorio
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: DISCUSS: clojure.contrib.java-utils/file

2009-04-06 Thread samppi

In addition, it's a bad idea to have these two superficially similar
functions have the same name, file. If, in the end, both are to be
kept public, then I think they should at least be given different
names.

On Apr 6, 10:35 am, Victor Rodriguez vict...@gmail.com wrote:
 Hello,

 On Mon, Apr 6, 2009 at 10:06 AM, James Reeves

 weavejes...@googlemail.com wrote:

 ...
  The problem with having java-utils/file and duck-streams/file is that
  you lose the ability to load both namespaces at the same time without
  defining an exception for the file function. This does not seem like
  an ideal solution. I think we should choose one or the other, give
  them different names, or attempt to merge their functionality.

 IMHO. what you want to avoid is having similar utility functions in
 different projects.  Thus, duck-streams could just use the version of
 file of java-utils, or keep its own version private.

 Cheers,

 Victor Rodriguez.

  - James
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: ANN: Pretty printer is now part of contrib

2009-04-06 Thread Laurent PETIT
Hi,

2009/4/6 Tom Faulhaber tomfaulha...@gmail.com


 Another question is whether we should duplicate the classes and
 the .clj files in the jar or should we just compile all of them. Is
 there some value to having the source there?


There certainly some value for both scenario : having classes seems an
absolute requirement for some libraries to work, but having .clj files is
really interesting for those that want either (show-source) ... in their
REPL to work (or in IDEs for jumping to a read-only syntax-colored version
of the source file).

But there is also certainly value in having a build with just the classes ?
(Though since the whole thing is open source, it's not a problem related to
rights, but maybe for some platforms such as Android, some people might want
the lightest possible jar ?)

Regards,

-- 
Laurent

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: New release of the enclojure plugin is up.

2009-04-06 Thread billh04

I downloaded and installed NetBeans and the Enclojure plugin.

I am not clear on how to setup the main class.

I modified the main class generated by the template to look like the
following:

=
(defn -main ([args] (startNewAchiTask))
  ([ ] (-main nil)))
=

This works, but I am not sure what is going on.

Why are there parentheses around [args] (startNewAchiTask)?

What is ([ ] (-main nil))?

Thanks for any help on these questions.

On Apr 6, 7:43 pm, Eric Thorsen ethor...@enclojure.org wrote:
 There is a new release of the Enclojure plugin that addresses many of
 the items I have seen discuss here recently with regards to managing
 classpaths in REPLs as well as many other Clojure development
 scenarios.  The plugin supports several use cases for the clojure.main
 REPL use:
 a. Project based REPLs where the REPL is started using the
 dependancies on the project in the IDE.
 b. Remote REPLs where some shim code can be included in your
 application(s) and you can attach a REPL (or REPLs) to running VMs.
 c. Ad-hoc REPLs - manually set your classpaths and start a REPL up.
 All of these scenarios have strong integration with the editor
 supporting integrated Clojure/Java completion, debugging with viewable
 clojure data, syntax highlighting, code loading, expression
 evaluation, s-expression nav and many more features.  There have been
 well over 100 patches since the last release in February.
 For more information, please see:http://enclojure.wikispaces.com
 Plugin can be downloaded 
 at:http://code.google.com/p/enclojure-nb-clojure-plugin/downloads/list

 Feedback welcome!
 Eric

 Eric Thorsen
 ThorTech Solutionswww.thortech-solutions.com
 (914) 302-7638  [work]
 (914) 302-7641  [fax]
 (914) 804-4954  [cell]
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---