Re: Wildcards on multimethod matching

2010-10-25 Thread Sunil S Nandihalli
Hello ..
 Just my two cents.. I think the ability to specify an equality function
when creating the multi-method would solve the problem.

for example

(defmulti foo dispatch-fn equality-fn)

would be very nice. one can use arbitrary functions to match ... which may
be reimplemented at users wish to achieve say wild-card support..

Probably it is already happening .. I don't know.
Thanks,
Sunil.

On Sun, Oct 24, 2010 at 2:52 AM, Meikel Brandmeyer  wrote:

> Hi,
>
> if you only dispatch on types you can do it like this:
>
> (derive Object ::any)
> ; Also derive all of your ::keyword types from ::any.
>
> (defmulti foo #(vec (map type %&)))
>
> (defmethod foo [::any Integer] ...)
>
> But this won't work if you dispatch on actual values as you did in
> your example. For that there is no way to specify wildcars, AFAIK.
>
> Sincerely
> Meikel
>
> --
> 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 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
>

-- 
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 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: Wildcards on multimethod matching

2010-10-25 Thread Sunil S Nandihalli
and defn-match from the matchure library might be able to solve some of your
problems .. Just a wild guess .. to solve the wild-cards problem ... :)
Just look at
http://github.com/dcolthorp/matchure


On Mon, Oct 25, 2010 at 1:59 PM, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:

> Hello ..
>  Just my two cents.. I think the ability to specify an equality function
> when creating the multi-method would solve the problem.
>
> for example
>
> (defmulti foo dispatch-fn equality-fn)
>
> would be very nice. one can use arbitrary functions to match ... which may
> be reimplemented at users wish to achieve say wild-card support..
>
> Probably it is already happening .. I don't know.
> Thanks,
> Sunil.
>
>
> On Sun, Oct 24, 2010 at 2:52 AM, Meikel Brandmeyer  wrote:
>
>> Hi,
>>
>> if you only dispatch on types you can do it like this:
>>
>> (derive Object ::any)
>> ; Also derive all of your ::keyword types from ::any.
>>
>> (defmulti foo #(vec (map type %&)))
>>
>> (defmethod foo [::any Integer] ...)
>>
>> But this won't work if you dispatch on actual values as you did in
>> your example. For that there is no way to specify wildcars, AFAIK.
>>
>> Sincerely
>> Meikel
>>
>> --
>> 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 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
>>
>
>

-- 
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 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: Emacs auto-complete plugin for slime users

2010-10-25 Thread Preecha P
Excellent, I still wonder why hook doesn't work but your solution work
perfectly here, thanks.

On Oct 21, 8:55 am, Paul  Mooser  wrote:
> I was having this problem, and what solved it for me was to customize
> the ac-modes variable (using M-x customize-variable RET ac-modes RET)
> and adding slime-repl-mode to the list. Once I added this, auto-
> complete gets automatically enabled on my repl buffers as well. Give
> it a try!
>
> On Oct 17, 10:00 am, Preecha P  wrote:
>
> > Same here. It seems like auto-complete-mode doesn't fire up
> > correctly.  I tried to hook it using (add-hook 'slime-repl-mode-hook
> > (lambda () (auto-complete-mode t) but it doesn't seems to do anything.
> > I have to open the mode manually.

-- 
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 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: Wildcards on multimethod matching

2010-10-25 Thread Mark Nutter
I tried to have a go at this, but then I realized it's a bit difficult
to specify. For example, if you have

(defmethod bar [42 _] ..) ; and
(defmethod bar [_ 16] ..)

which one should be called when you give it (bar 42 16)?

Mark

On Sat, Oct 23, 2010 at 5:16 PM, Paul Richards  wrote:
> Hi,
> I have a multimethod which is dispatched on two arguments:
>
> (defmulti bar (fn [x y] [x y]))
> (defmethod bar [1 2] ..)
> (defmethod bar [3 4] ..)
>
> Is there a way I can define methods on this which use "wildcards"?
>
> E.g.:
>
> ; To match any call with 42 as the 1st argument
> (defmethod bar [42 _] ..)
>
> ; To match any call with 16 as the 2nd argument
> (defmethod bar [_ 16] ..)
>
> The above syntax doesn't seem to work, neither does using ':default'
> in place of the '_'.
>
> If this is not possible, is there a common pattern I should implement instead?

-- 
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 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: Wildcards on multimethod matching

2010-10-25 Thread Paul Richards
So in this particular case I wouldn't care, but in general I'd expect
the prefer-method stuff to kick in. :)



On 25 October 2010 10:54, Mark Nutter  wrote:
> I tried to have a go at this, but then I realized it's a bit difficult
> to specify. For example, if you have
>
> (defmethod bar [42 _] ..) ; and
> (defmethod bar [_ 16] ..)
>
> which one should be called when you give it (bar 42 16)?
>
> Mark
>
> On Sat, Oct 23, 2010 at 5:16 PM, Paul Richards  
> wrote:
>> Hi,
>> I have a multimethod which is dispatched on two arguments:
>>
>> (defmulti bar (fn [x y] [x y]))
>> (defmethod bar [1 2] ..)
>> (defmethod bar [3 4] ..)
>>
>> Is there a way I can define methods on this which use "wildcards"?
>>
>> E.g.:
>>
>> ; To match any call with 42 as the 1st argument
>> (defmethod bar [42 _] ..)
>>
>> ; To match any call with 16 as the 2nd argument
>> (defmethod bar [_ 16] ..)
>>
>> The above syntax doesn't seem to work, neither does using ':default'
>> in place of the '_'.
>>
>> If this is not possible, is there a common pattern I should implement 
>> instead?
>
> --
> 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 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



-- 
Paul Richards
@pauldoo

-- 
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 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


understanding laziness

2010-10-25 Thread Tim Webster
I have an issue that I think is related to laziness, but I am not sure
I understand where the problem lies.

Let's say I have tabular data in a sequence of sequences. I get the
second column of the table like this:

(map #(nth % 1) my-table)

I can do some sequence things directly to the list returned by the
call to function, but not everything. For example,

(distinct (map #(nth % 1) my-table))

works fine, but

(frequencies (map #(nth % 1) my-table))

throws java.lang.RuntimeException: java.lang.IndexOutOfBoundsException

My own implementation of frequencies, which is maybe a little naive,
throws the same exception. However, if I bind the result of my map
call to a variable first and then call frequencies, it works fine:

(def my-list (map #(nth % 1) my-table))
(frequencies my-list)

It is my understanding that the def does not do anything but give the
list an entry in a symbol table, but something is obviously happening.
Am I causing a lazy sequence to be populated with concrete values?


-- 
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 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: Question about lein swank and emacs

2010-10-25 Thread rb
Check out this Emacs package: http://github.com/remvee/elein

The command you need is called `elein-reswank' there.

cheers,
rb


On Oct 25, 7:13 am, Mark Engelberg  wrote:
> When you start a swank server with lein swank, and then connect to it
> via slime-connect in emacs, is there any way from within emacs to
> restart the swank server and/or delete all definitions to start from a
> clean slate?

-- 
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 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: Setting Clojure “constants” at runtime (cros sposted to Stackoverflow)

2010-10-25 Thread Ralph
That's interesting... Hadn't thought of using delay. A user on
Stackoverflow (kotarak) suggested using alter-var-root. This method
will also support setting values for command line arguments.

On Oct 24, 3:33 pm, Stuart Sierra  wrote:
> Here's one way:
>
>     (def version (delay (... read the JAR ...))
>
>     (defn get-version [] (force version))
>
> -S
>
> On Oct 22, 11:56 am, Ralph  wrote:
>
>
>
> > I have a Clojure program that I build as a JAR file using Maven.
> > Embedded in the JAR Manifest is a build-version number, including the
> > build timestamp.
>
> > I can easily read this at runtime from the JAR Manifest using the
> > following code:
>
> > (defn set-version
> >   "Set the version variable to the build number."
> >   []
> >   (def version
> >     (-> (str "jar:" (-> my.ns.name (.getProtectionDomain)
> >                                    (.getCodeSource)
> >                                    (.getLocation))
> >                     "!/META-INF/MANIFEST.MF")
> >       (URL.)
> >       (.openStream)
> >       (Manifest.)
> >       (.. getMainAttributes)
> >       (.getValue "Build-number"
> > but I've been told that it is bad karma to use def inside defn.
>
> > What is the Clojure-idiomatic way to set a constant at runtime? I
> > obviously do not have the build-version information to embed in my
> > code as a def, but I would like it set once (and for all) from the
> > main function when the program starts. It should then be available as
> > a def to the rest of the running code.

-- 
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 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: Wildcards on multimethod matching

2010-10-25 Thread Tim Daly

 The issue of "what to call" and "when to call it" has been debated
in the common lisp world a long time ago. There are solutions
to these questions in the discussions around the CLOS facility
(Steele, "Common Lisp: The Language", chapter 28)

Prior to that there was a discussion of the same issues on the
Symbolics machine along with whoppers and wrappers.

Unfortunately all of my records of such discussions were on
pre-web email so I do not have copies. There may be some
people on this list who do.

A lot of thought went into the decisions. It might be worthwhile
reading about the choices they made.

Similarly I saw a discussion of the error handling facility.
Common lisp has a condition system that might be useful to follow.

The advantage of using already existing ideas is that it will
make it easier and less surprising to the existing lisp community.
It will also give a firm basis for discussing ideas.

Tim Daly


On 10/25/2010 5:54 AM, Mark Nutter wrote:

I tried to have a go at this, but then I realized it's a bit difficult
to specify. For example, if you have

(defmethod bar [42 _] ..) ; and
(defmethod bar [_ 16] ..)

which one should be called when you give it (bar 42 16)?

Mark

On Sat, Oct 23, 2010 at 5:16 PM, Paul Richards  wrote:

Hi,
I have a multimethod which is dispatched on two arguments:

(defmulti bar (fn [x y] [x y]))
(defmethod bar [1 2] ..)
(defmethod bar [3 4] ..)

Is there a way I can define methods on this which use "wildcards"?

E.g.:

; To match any call with 42 as the 1st argument
(defmethod bar [42 _] ..)

; To match any call with 16 as the 2nd argument
(defmethod bar [_ 16] ..)

The above syntax doesn't seem to work, neither does using ':default'
in place of the '_'.

If this is not possible, is there a common pattern I should implement instead?


--
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 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: understanding laziness

2010-10-25 Thread Ken Wesson
On Oct 24, 11:46 pm, Tim Webster  wrote:
> I have an issue that I think is related to laziness, but I am not sure
> I understand where the problem lies.
>
> Let's say I have tabular data in a sequence of sequences. I get the
> second column of the table like this:
>
> (map #(nth % 1) my-table)
>
> I can do some sequence things directly to the list returned by the
> call to function, but not everything. For example,
>
> (distinct (map #(nth % 1) my-table))
>
> works fine, but
>
> (frequencies (map #(nth % 1) my-table))
>
> throws java.lang.RuntimeException: java.lang.IndexOutOfBoundsException

I can't reproduce this with Clojure 1.2:

user=> (frequencies (map #(nth % 1) [[1 2 3][4 5 6][1 2 3]]))
{2 2, 5 1}

-- 
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 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: Test-driven development in Clojure

2010-10-25 Thread Brian Marick

On Oct 24, 2010, at 2:03 PM, Felix H. Dahlke wrote:

> I just read through this thread again and noticed that I didn't notice
> you mentioning that I can stub functions within tests. I had a look at
> the clojure.test documentation, but I didn't find an example of that.


In Midje , you stub by listing a function as a 
prerequisite to the function you're test-driving. For example:

(fact
(numerical-reverser 103) => 301
(provided 
  (string-reverser "103") => "301"))

(That's the "sweet" syntax, which is built on top of a plain functions-and-maps 
interface.) 

-
Brian Marick, independent consultant
Mostly on agile methods with a testing slant
Author of /Programming Cocoa with Ruby/
www.exampler.com, www.exampler.com/blog, www.twitter.com/marick

-- 
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 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: Setting Clojure “constants” at runtime (cros sposted to Stackoverflow)

2010-10-25 Thread Aaron Cohen
On Sat, Oct 23, 2010 at 8:53 AM, Ralph  wrote:
> Won't work. The "def" gets executed at compile time, before the JAR
> file exists.
>

I'm very confused by what you mean by this. If I do the following, I
get a new random value every time I run it, which does not seem to
match what you are saying:


(ns demo.core
 (:gen-class))

(def version (.nextInt (java.util.Random.)))

(defn -main []
  (prn version))

-- 
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 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: understanding laziness

2010-10-25 Thread Tim Webster
I thought that the issue might be that the concrete data still was not
populated in my list-of-lists, unlike your literal, so I started with
a clean environment and re-ran my repl session line by line from the
jline history file. I could not reproduce the error. (Which troubles
me even more...the error had to come from somewhere.)

For the record, here is how I build the table:

(def data (slurp "data.txt"))
(def lines (. data split "\n"))
(def my-table (map #(. % split "\t") lines))

On Oct 25, 9:28 am, Ken Wesson  wrote:
> On Oct 24, 11:46 pm, Tim Webster  wrote:
>
>
>
>
>
>
>
>
>
> > I have an issue that I think is related to laziness, but I am not sure
> > I understand where the problem lies.
>
> > Let's say I have tabular data in a sequence of sequences. I get the
> > second column of the table like this:
>
> > (map #(nth % 1) my-table)
>
> > I can do some sequence things directly to the list returned by the
> > call to function, but not everything. For example,
>
> > (distinct (map #(nth % 1) my-table))
>
> > works fine, but
>
> > (frequencies (map #(nth % 1) my-table))
>
> > throws java.lang.RuntimeException: java.lang.IndexOutOfBoundsException
>
> I can't reproduce this with Clojure 1.2:
>
> user=> (frequencies (map #(nth % 1) [[1 2 3][4 5 6][1 2 3]]))
> {2 2, 5 1}

-- 
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 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


Creating Java array of specific type

2010-10-25 Thread Hong Jiang
Hi,

I have been able to find answer to this on Google, so here it is:

If I have a seq of NameValuePair (a class in Apache HttpClient), how
do I get an array of that type (NameValuePair[])? I've tried a few
things but always got Object[].

Thanks.

--Hong

-- 
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 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: understanding laziness

2010-10-25 Thread Alan
#(nth % 1) is the same as clojure.core/second. You can also use
(.split data "\n") instead if you like; it's nice to have the function
first.

On Oct 25, 9:04 am, Tim Webster  wrote:
> I thought that the issue might be that the concrete data still was not
> populated in my list-of-lists, unlike your literal, so I started with
> a clean environment and re-ran my repl session line by line from the
> jline history file. I could not reproduce the error. (Which troubles
> me even more...the error had to come from somewhere.)
>
> For the record, here is how I build the table:
>
> (def data (slurp "data.txt"))
> (def lines (. data split "\n"))
> (def my-table (map #(. % split "\t") lines))
>
> On Oct 25, 9:28 am, Ken Wesson  wrote:
>
> > On Oct 24, 11:46 pm, Tim Webster  wrote:
>
> > > I have an issue that I think is related to laziness, but I am not sure
> > > I understand where the problem lies.
>
> > > Let's say I have tabular data in a sequence of sequences. I get the
> > > second column of the table like this:
>
> > > (map #(nth % 1) my-table)
>
> > > I can do some sequence things directly to the list returned by the
> > > call to function, but not everything. For example,
>
> > > (distinct (map #(nth % 1) my-table))
>
> > > works fine, but
>
> > > (frequencies (map #(nth % 1) my-table))
>
> > > throws java.lang.RuntimeException: java.lang.IndexOutOfBoundsException
>
> > I can't reproduce this with Clojure 1.2:
>
> > user=> (frequencies (map #(nth % 1) [[1 2 3][4 5 6][1 2 3]]))
> > {2 2, 5 1}
>
>

-- 
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 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: Creating Java array of specific type

2010-10-25 Thread Kyle R. Burton
> If I have a seq of NameValuePair (a class in Apache HttpClient), how
> do I get an array of that type (NameValuePair[])? I've tried a few
> things but always got Object[].

Two quick ways are make-array and into-array:

   (make-array String 10)

  (into-array String ["this" "that"])

These both result in a type of String[].


HTH,


Kyle

-- 
Twitter: @kyleburton
Blog: http://asymmetrical-view.com/
Fun: http://snapclean.me/

-- 
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 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: understanding laziness

2010-10-25 Thread Jürgen Hötzel
2010/10/25 Tim Webster :
> I thought that the issue might be that the concrete data still was not
> populated in my list-of-lists, unlike your literal, so I started with
> a clean environment and re-ran my repl session line by line from the
> jline history file. I could not reproduce the error. (Which troubles
> me even more...the error had to come from somewhere.)
>
> For the record, here is how I build the table:
>
> (def data (slurp "data.txt"))
> (def lines (. data split "\n"))
> (def my-table (map #(. % split "\t") lines))

You don't leverage laziness here: The whole file is read into the
java String "data" and "line" is just a primitive Java Array of
Strings realized all at once: This may cause  OutOfMemoryError on
large files and is not required in your use case. Consider to use of
"line-seq":

(with-open [f (reader "data.txt")]
  (->> (line-seq f)
   (map #(split % #"\t"))
   (map second)
   frequencies))

Jürgen

-- 
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 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 1.3 Alpha 2

2010-10-25 Thread Stuart Halloway
Clojure 1.3 Alpha 2 is now available at

http://clojure.org/downloads

= CHANGES =

 0 Changes from 1.3 Alpha 1 to 1.3 Alpha 2
 1 Changes from 1.2 to 1.3 Alpha 1
 2 About Alpha Releases

= 0 Changes from 1.3 Alpha 1 to 1.3 Alpha 2

  * code path for using vars is now *much* faster for the common case,
and you must explicitly ask for :dynamic bindability
  * new: clojure.reflect/reflect
http://dev.clojure.org/display/design/Reflection+API 
  * new: clojure.data/diff

= 1 Changes from 1.2 to 1.3 Alpha 1

  * enhanced primitive support 
(http://dev.clojure.org/display/doc/Enhanced+Primitive+Support)
  * better exception reporting
  * ancillary namespaces no longer auto-load on startup:
clojure.set, clojure.xml, clojure.zip

= 2 About Alpha Releases

1.3 is the first release of Clojure that will include a series of
alpha builds. We are adding these builds to support maven and
leiningen users, who want a specific artifact that they can target (as
opposed to building from master or "moving-target" snapshots).

If you are the kind of person who used to track master by building
from source, but no longer do so because you are using maven or
leiningen, alpha releases are for you.

-- 
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 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

Review Request: Validation in contrib.command-line

2010-10-25 Thread Andrew Gwozdziewycz
Hey All,

I'd have posted this to clojure-dev if I wasn't still pending access (I'm
sure the queue is large, so no worries), but, the fine folks in IRC said
here would be appropriate as well.

This morning I was looking to do some command line parsing and went with
clojure.contrib.command_line that chouser wrote. It's a great library, and
works as expected, but command line arguments are inherently typed in
certain cases, say a port number, which is one thing I was passing via the
command line.

So, I've attached a patch that makes it possible to specify a validation
function, which either throws an Exception or returns nil, in the case the
the attribute is not valid, or returns a coerced value if it is.

Here's an example:


user=> (pp (make-map ["--port" "80" "--ok-if-foo" "foo"]
[['port 'p "the port" 80 #(Integer/parseInt %)]
 ['ok-if-foo 'o "only ok if foo" #(= "foo" %)]]))
{"ok-if-foo" true,  ;;; coerced to true
"" [],
:cmdspec
[[port
  p
  "the port"
  80
  #]
 [ok-if-foo
  o
  "only ok if foo"
  #]],
"port" 80  ;;; coerced to integer 80
}

However, if we swap the arguments around --port foo --ok-if-foo 80, you see
we get an "Invalid value for port"
user=> (make-map ["--port" "foo" "--ok-if-foo" "80"]
 [['port 'p "the port" 80 #(Integer/parseInt %)]
  ['ok-if-foo 'o "only ok if foo" #(= "foo" %)]])
java.lang.Exception: Invalid value for port (NO_SOURCE_FILE:0)

And of course, it's still backwards compatible:

user=> (pp (make-map ["--verbose" "--port" "80"]
 [['verbose? 'v? "verbose" false]
  ['port 'p "port to listen on"]]))
{"port" "80",
 "verbose?" true,
 "" [],
 :cmdspec [[verbose? v? "verbose" false] [port p "port to listen on"]]}


I've attached the patch, and would love suggestions, feedback, criticism,
etc.

Thanks,

Andrew

-- 
http://www.apgwoz.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
Note that posts from new members are moderated - please be patient with your 
first post.
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

contrib.command-line.validation.diff
Description: Binary data


Re: understanding laziness

2010-10-25 Thread Tim Webster
Thanks, Jürgen. I think you are saying that there is no difference
with respect to laziness between my approach and Ken's literal, so I
can remove that from consideration as the cause of my problem. I have
looked at my repl session pretty closely and do not think that I
clobbered any of the variables in any way as I was experimenting, but
now that seems like the most likely explanation.

On Oct 25, 2:42 pm, Jürgen Hötzel  wrote:
> 2010/10/25 Tim Webster :
>
> > I thought that the issue might be that the concrete data still was not
> > populated in my list-of-lists, unlike your literal, so I started with
> > a clean environment and re-ran my repl session line by line from the
> > jline history file. I could not reproduce the error. (Which troubles
> > me even more...the error had to come from somewhere.)
>
> > For the record, here is how I build the table:
>
> > (def data (slurp "data.txt"))
> > (def lines (. data split "\n"))
> > (def my-table (map #(. % split "\t") lines))
>
> You don't leverage laziness here: The whole file is read into the
> java String "data" and "line" is just a primitive Java Array of
> Strings realized all at once: This may cause  OutOfMemoryError on
> large files and is not required in your use case. Consider to use of
> "line-seq":
>
> (with-open [f (reader "data.txt")]
>   (->> (line-seq f)
>        (map #(split % #"\t"))
>        (map second)
>        frequencies))
>
> Jürgen

-- 
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 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: Question about lein swank and emacs

2010-10-25 Thread Drew Raines
Mark Engelberg wrote:

> When you start a swank server with lein swank, and then connect to
> it via slime-connect in emacs, is there any way from within emacs
> to restart the swank server and/or delete all definitions to start
> from a clean slate?

In the *slime-repl ...* buffer enter:

  , restart-inferior-lisp RET

-Drew

-- 
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 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: Test-driven development in Clojure

2010-10-25 Thread Felix H. Dahlke
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Ah, I get it. This works really well!

(defn mock-page-fixture [f]
  (binding [load-page (fn [name] ...)]
(f)))

This approach feels very functional indeed, I'm going to use it. It's
not really the same as my original TDD inspired design, because that
would allow me to easily write additional providers - but why bother if
I don't read it right now?

On 10/24/2010 09:29 PM, Stuart Sierra wrote:
> In clojure.test, you can use the Clojure `binding` macro to provide
> local replacements for global functions.
> 
> In Lazytest, you can use the context objects provided by
> lazytest.context.stub.
> 
> -S
> 
> 
> On Oct 24, 3:03 pm, "Felix H. Dahlke"  wrote:
> Hi Stuart,
> 
> I just read through this thread again and noticed that I didn't notice
> you mentioning that I can stub functions within tests. I had a look at
> the clojure.test documentation, but I didn't find an example of that.
> 
> How would that apply to my case? Would I still have to pass a function
> in? (One wouldn't be enough actually, I have several load functions by now.)
> 
> Whether I'll do TDD or not, I decided that I definitely need unit tests.
> 
> On 10/12/2010 06:59 PM, Stuart Sierra wrote:
> 
> 
> 
> 
> 
 Datatypes that implement a single method can be more simply
 represented as ordinary functions, e.g.
> 
 (defn real-provider ...)
 (defn fake-provider ...)
> 
 (defn load-page [provider ...]
   (let [foo (provider)]
   ...))
> 
 That being said, you have other options: In clojure.test you can using
 `binding` to stub out functions within your tests. Lazytest >>> github.com/stuartsierra/lazytest> has explicit support for stubbing
 out functions during testing.
> 
 -S
> 
 On Oct 11, 6:06 pm, "Felix H. Dahlke"  wrote:
> Hi,
> 
> I'm new to Clojure, using it for a reasonably sized project for the
> first time, and I'm trying to do test-driven development.
> 
> While it does work well technically  - clojure.test is very nice to use
> and feels a lot like JUnit 4's assertThat() - I'm wondering if I'm
> trying to program Java in Clojure.
> 
> Here's an example:
> 
> I'm writing a class (Um. I mean, a ... namespace? Well, a horde of
> functions.) that accesses web pages from a backend, which can e.g. take
> these from the filesystem or from a database. In Java or C++, I'd use an
> interface for that and create one implementation for the filesystem and
> one for the database:
> 
> interface Provider {
> String loadPage(String name);
> 
> }
> 
> This is possible in Clojure:
> 
> (defprotocol Provider
>   (load-page [this name])
> 
> It can be implemented using deftype:
> 
> (deftype DatabaseProvider []
>   Provider
>   (load-page [this name]
> (have-fun-with-the-database)))
> 
> And I can call it like this:
> 
> (load-page (DatabaseProvider.) "foo")
> 
> Feels a little weird (especially since all examples of defprotocol and
> deftype use camel case for type names), but works.
> 
> Back to my question: Am I trying to do Java in Clojure? Is there a more
> Lisp-y way to do this?
> 
> As you may have suspected, this design wasn't my initial intention, it
> was driven by TDD: This allows me to create a mock implementation
> against which I can write my test cases without having having to depend
> on external resources. Typical TDD design. In fact, there will only be
> one backend for now.
> 
> This made me wonder if test-driven development was desirable in Clojure
> at all, or even in functional programming in general.
> 
> There's a few articles on the issue. Many seem to be from Clojure
> newcomers, asking questions themselves, and none handles design issues
> like mock objects [1].
> 
> One guy basically said that he stopped doing TDD because the REPL makes
> it possible to test specific functions directly [2]. I can see how he
> says that the *driven* aspect of TDD can be performed by the REPL, but I
> find it too inconvenient for extensive use.
> 
> Bob Martin says that, because functional programming differs from
> object-oriented programming (In my opinion, these paradigms are
> compatible - did he mean imperative programming?), test-driven
> development has to start by testing the details, and work up to testing
> the big picture. TDD in e.g. Java starts with the big picture and moves
> down. I don't understand his points completely, but if he's right, this
> might be a fundamental problem for TDD in functional languages.
> 
> One guy partly disagrees with him on some matters, but doesn't really
> mention the bottom-up thing [4].
> 
> What are your thoughts on these issues? Is anybody here doing TDD in
> Clojure? Is anybody against it?
> 
> [1]:http://www.magpiebrain.com/2010/02/16/struggling-with-test-driven-clo...
> [

Re: Wildcards on multimethod matching

2010-10-25 Thread Mark Nutter
> So in this particular case I wouldn't care, but in general I'd expect
> the prefer-method stuff to kick in. :)

Oops, forgot about prefer-method. My noobishness is showing again.
Well, in for a dime in for a dollar. Here's something I whipped up
just for the general amusement of the list. It's not quite what you
asked for, but it might be suitable as a source of ideas, instruction,
derision, or whatever.

(defmulti bar (fn [x y & more] [x y]))
(defmethod bar :default [x y & more]
  (if more ; did default loop back to itself?
nil
(some identity [(bar :wild y x)
  (bar x :wild y)])))
(defmethod bar [:wild 16] [x-wild y & more]
  (let [x (first more)]
(str "First arg wild " x ", " y)))
(defmethod bar [42 :wild] [x y-wild & more]
  (let [y (first more)]
(str "Second arg wild " x ", " y)))
(defmethod bar [10 20] [x y]
  (pr-str "Plain vanilla args " x ", " y))

user> (bar 10 20)
"\"Plain vanilla args \" 10 \", \" 20"
user> (bar 42 20)
"Second arg wild 42, 20"
user> (bar 10 16)
"First arg wild 10, 16"
user> (bar 42 16)
"First arg wild 42, 16"user> (bar 10 20)
"\"Plain vanilla args \" 10 \", \" 20"
user> (bar 42 20)
"Second arg wild 42, 20"
user> (bar 10 16)
"First arg wild 10, 16"
user> (bar 42 16)
"First arg wild 42, 16"

-- 
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 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: Wildcards on multimethod matching

2010-10-25 Thread Tim Daly

 Common lisp allows you to call DEFINE-METHOD-COMBINATION.
(Steele p830) There is a default generic method combination
defined which can be modified by this call.

If Clojure used a function to do the method resolution
then it would be possible to replace this with a user defined
function. This would allow all kinds of dispatching control.

Tim Daly

On 10/25/2010 5:55 PM, Mark Nutter wrote:

So in this particular case I wouldn't care, but in general I'd expect
the prefer-method stuff to kick in. :)

Oops, forgot about prefer-method. My noobishness is showing again.
Well, in for a dime in for a dollar. Here's something I whipped up
just for the general amusement of the list. It's not quite what you
asked for, but it might be suitable as a source of ideas, instruction,
derision, or whatever.

(defmulti bar (fn [x y&  more] [x y]))
(defmethod bar :default [x y&  more]
   (if more ; did default loop back to itself?
nil
(some identity [(bar :wild y x)
  (bar x :wild y)])))
(defmethod bar [:wild 16] [x-wild y&  more]
   (let [x (first more)]
(str "First arg wild " x ", " y)))
(defmethod bar [42 :wild] [x y-wild&  more]
   (let [y (first more)]
(str "Second arg wild " x ", " y)))
(defmethod bar [10 20] [x y]
   (pr-str "Plain vanilla args " x ", " y))

user>  (bar 10 20)
"\"Plain vanilla args \" 10 \", \" 20"
user>  (bar 42 20)
"Second arg wild 42, 20"
user>  (bar 10 16)
"First arg wild 10, 16"
user>  (bar 42 16)
"First arg wild 42, 16"user>  (bar 10 20)
"\"Plain vanilla args \" 10 \", \" 20"
user>  (bar 42 20)
"Second arg wild 42, 20"
user>  (bar 10 16)
"First arg wild 10, 16"
user>  (bar 42 16)
"First arg wild 42, 16"



--
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 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: post your feedback on the conj

2010-10-25 Thread lprefontaine
Hi Stu,

I came back from the Conj with 12 pages of notes in a 2 inches by 3 inches 
notebook. That represented 3 months of work at least.

On the return flight, I added another 3 pages of notes. I made some connections
between ideas exposed at the Conj in relation with our work here.
Now I have about 10 months worth of work at least.

The Conj opened my mind to a number of avenues to solve some issues
we are facing right now given our current design. Our design will change
a lot this year. I found a way to change it to make the current obstacles
vanish.

Great conference Stuart, every penny spent has been a high return investment
in a very short delay.
I needed a break from my day to day work and some breathing space to
re-evaluate the state of things and this is exactly what the Conj gave me.

Thank you, your team, the speakers and all the others involved for that great 
48 hours.

Luc P.

Stuart Halloway  wrote ..
> If you were at Clojure-conj, you can post your feedback on talks through
SpeakerRate
> at http://speakerrate.com/events/613-clojure-conj. Please do, so we can make
(second
> conj) even better!
> 
> It was terrific meeting so many of you for the first time. Thanks again to all
> the attendees, speakers, sponsors, and volunteers for making the conj great.
> 
> Stu
> 
> Stuart Halloway
> Clojure/core team at Relevance
> http://clojure.com
> http://thinkrelevance.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
> Note that posts from new members are moderated - please be patient with your 
> first
> post.
> 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

-- 
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 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


Images in autodoc?

2010-10-25 Thread Chris
Is it possible to add images to autodoc-generated pages like javadoc
can?  I'm interested in adding explanatory diagrams to function
documentation as opposed to adding things like logos to the HTML
pages.

Thanks,
Chris

-- 
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 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


Getting this error regarding duck-streams/spit ...

2010-10-25 Thread Victor Olteanu
Hi friends,

I am getting the following error and was hoping somebody may be able to
assist:

java.lang.IllegalStateException: spit already refers to:
#'clojure.contrib.duck-streams/spit in namespace: datatool.api (api.clj:1)

I realized it's because clojure.contrib.duck-streams/spit is overriding
clojure.core/spit.
It used to be just a warning when I start jetty, but now it is preventing my
app to run. (jetty starts, but when I try accessing the app in the browser,
I get that error)

Would you have any idea about how to solve it?

FYI what I have in my datatool/api.clj file is:

(ns datatool.api
  (:use compojure.core)
  (:use hiccup.core)
  (:use hiccup.page-helpers)
  (:use [ring.middleware reload stacktrace file file-info])
  (:use datatool.db)
  (:use clojure.contrib.json)
  (:use clojure.contrib.duck-streams))


Thank you,
Victor

-- 
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 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: Getting this error regarding duck-streams/spit ...

2010-10-25 Thread Michael Ossareh
On Mon, Oct 25, 2010 at 19:09, Victor Olteanu  wrote:
>
> java.lang.IllegalStateException: spit already refers to:
> #'clojure.contrib.duck-streams/spit in namespace: datatool.api (api.clj:1)
>

Hi Victor,

I solved this issue by using (require) instead of (use). i.e.

(ns myapp
 (require [other-ns :as ns]))

Then whenever you access a function in the other-ns you prefix it with
ns/function.

There may be other ways to solve this though.

-- 
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 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: Question about lein swank and emacs

2010-10-25 Thread Mark Engelberg
When I do restart-inferior-lisp, it says, "no inferior lisp process".

On Mon, Oct 25, 2010 at 1:31 PM, Drew Raines  wrote:
> Mark Engelberg wrote:
>
>> When you start a swank server with lein swank, and then connect to
>> it via slime-connect in emacs, is there any way from within emacs
>> to restart the swank server and/or delete all definitions to start
>> from a clean slate?
>
> In the *slime-repl ...* buffer enter:
>
>  , restart-inferior-lisp RET
>
> -Drew
>
> --
> 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 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

-- 
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 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: Getting this error regarding duck-streams/spit ...

2010-10-25 Thread Victor Olteanu
Thank you.

The following statement worked for me:
(:require [clojure.contrib.duck-streams :as d])

As I was using slurp and slurp*, I then had to do the following:

use the form "d/slurp*" instead (prefixed with d/)
use "slurp" without a change

This brings up a related point - I can see that there are functions with the
same name in different packages, which I believe it's quite unfortunate.
There is slurp in clojure.core and there is duck-streams/slurp* , along with
other functions such as spit...

I hope this kind of things might be addressed in future versions of
Clojure...

On Mon, Oct 25, 2010 at 10:25 PM, Michael Ossareh  wrote:

>
>
> On Mon, Oct 25, 2010 at 19:09, Victor Olteanu wrote:
>>
>>  java.lang.IllegalStateException: spit already refers to:
>> #'clojure.contrib.duck-streams/spit in namespace: datatool.api (api.clj:1)
>>
>
> Hi Victor,
>
> I solved this issue by using (require) instead of (use). i.e.
>
> (ns myapp
>  (require [other-ns :as ns]))
>
> Then whenever you access a function in the other-ns you prefix it with
> ns/function.
>
> There may be other ways to solve this though.
>
> --
> 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 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

-- 
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 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: Getting this error regarding duck-streams/spit ...

2010-10-25 Thread Btsai
I don't think it's a mistake or accident that spit exists in
clojure.core.  In 1.2, duck-streams became deprecated and functions
such as spit were incorporated into clojure.core:

http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/spit
http://clojure.github.com/clojure-contrib/duck-streams-api.html

Are you using anything beyond spit and slurp*?  If not, I think you
can switch to clojure.core's slurp and spit and drop duck-streams
altogether.

On Oct 25, 8:59 pm, Victor Olteanu  wrote:
> Thank you.
>
> The following statement worked for me:
> (:require [clojure.contrib.duck-streams :as d])
>
> As I was using slurp and slurp*, I then had to do the following:
>
> use the form "d/slurp*" instead (prefixed with d/)
> use "slurp" without a change
>
> This brings up a related point - I can see that there are functions with the
> same name in different packages, which I believe it's quite unfortunate.
> There is slurp in clojure.core and there is duck-streams/slurp* , along with
> other functions such as spit...
>
> I hope this kind of things might be addressed in future versions of
> Clojure...
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
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: Question about lein swank and emacs

2010-10-25 Thread David Jagoe
On 26 October 2010 04:36, Mark Engelberg  wrote:
> When I do restart-inferior-lisp, it says, "no inferior lisp process".

Yeah, that'll only work if you originally started swank from emacs as
the inferior lisp process. If you're doing 'lein swank' on the command
line it won't work - looks like elein is the way to go in that case.

-- 
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 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