Using macro to generate part of fn

2010-09-17 Thread Stuart Campbell
Hello,

In the following contrived example, I get an error when macroexpanding (defn
foo ...):

(defmacro special-fn-spec []
  '([bar baz] (println bar baz)))

(defn foo
  ([bar] (foo bar :default))
  (special-fn-spec))

The error is:
Parameter declaration special-fn-spec should be a vector
  [Thrown class java.lang.IllegalArgumentException]

I'm a bit confused about the order in which things are happening here. My
assumption was that (special-fn-spec) would be evaluated before the fn
definition. Is there a way to do something like this?

Thanks
Stuart

-- 
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: ctrim (with character)

2010-09-17 Thread blais
On Sep 17, 11:18 pm, Martin Blais  wrote:
> I'm still new here... what is the common procedure for
> outsiders to contribute? Fork on github and send link to
> branch? Like this? Let me know.

Never mind this bit; I found the relevant info on the Clojure website.
(Still interested in comments about the code bit above though, thx)


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


ctrim (with character)

2010-09-17 Thread Martin Blais
Hi,

I'd like to suggest a version trim for clojure.string that
can accept a specific character to be trimmed::


  (defn ^String ctrim
"Removes a character from the left side of string."
[char ^CharSequence s]
(let [slen (.length s)
  index-left (loop [index (int 0)]
   (if (= slen index)
 index
 (if (= (.charAt s index) char)
   (recur (inc index))
   index)))
  index-right (loop [index slen]
(if (zero? index)
  index
  (if (= (.charAt s (dec index)) char)
(recur (dec index))
index)))]
  (.. s (subSequence index-left index-right) toString) ))


(N.B. The code above is remashed from the existing triml/r
source.)

clojure.string/trim could be overloaded to accept either a
single parameter (current) or two (proposed above).

I'm still new here... what is the common procedure for
outsiders to contribute? Fork on github and send link to
branch? Like this? Let me know.

Thanks,


--
Martin

-- 
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: disk-backed memoize?

2010-09-17 Thread David McNeil
> I highly recommend using redis for this. There is even a clojure redis client.
>
> http://github.com/ragnard/redis-clojure

Thanks for the tip. It looks interesting, but in this case it is not
appropriate to add a separate process to the mix. I need to find a
good solution that is just a library.

-David

-- 
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: Displaying POSTed string from form text-field in Compojure

2010-09-17 Thread Miki
See http://clojure.pastebin.com/ncaULRbU (works for me).
I've changed the POST handler to use *params* and I also think you're
not closing the :h2 in view output.

On Sep 17, 3:11 pm, Victor Olteanu  wrote:
> Sure, here it is:
>
> (defn view-layout [& content]
>   (html
>    (doctype :xhtml-strict)
>    (xhtml-tag "en"
>               [:head
>                [:meta {:http-equiv "Content-type"
>                        :content "text/html; charset=utf-8"}]
>                [:title "Datum"]]
>               [:body content])))
>
> This was actually taken from an online tutorial with some changes 
> (http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applica...
>  )
> More specifically, in the original tutorial there was an additional
> intermediate step when the input was "parsed":
> (parse-input a b)
>
> with the function
> (defn parse-input [a b]
>   [(Integer/parseInt a) (Integer/parseInt b)])(parse-input a b)
>
> However in my case I'm just dealing with strings, so there's no "parseInt"
> involved. So I assumed my input is strings-- which doesn't seem to be the
> case, and there are no "parseString" methods that I could use instead.
>
> Thank you,
> Victor
>
>
>
> On Fri, Sep 17, 2010 at 5:30 PM, Miki  wrote:
> > My *guess* it's somehow connected to the code of "view-layout" since
> > it shows the representation of the function "str".
> > Can place the full code (including view-layout) somewhere?
>
> > On Sep 17, 12:35 pm, Victor  wrote:
> > > Hi all,
>
> > > I'm having a problem that may or may not be Compojure specific, so I
> > > thought I'd try this group since the answer is probably easy- I am
> > > just stuck.
>
> > > I am reading the string through a simple form
>
> > > (defn view-input []
> > >  (view-layout
> > >   [:h2 "Enter one datum:"]
> > >   [:form {:method "post" :action "/"}
> > >    [:input.datum {:type "text" :name "my_datum"}]
> > >    [:input.action {:type "submit" :value "Add"}]]))
>
> > > where the route for posting is
>
> > >  (POST "/" [a]
> > >   (view-output a)))
>
> > > I then simply want to display what I entered and submitted (say I
> > > typed the string "a").
>
> > > (defn view-output [a]
> > >  (view-layout
> > >   [:h2 (str "This is what you entered: " a)))
>
> > > However what I get is this:
>
> > > clojure.core$...@1e731e90
>
> > > Thanks in advance for your help!
> > > 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

-- 
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: partition-starting-every : yet another partition function

2010-09-17 Thread gary ng
On Fri, Sep 17, 2010 at 10:49 AM, Nicolas Oury  wrote:
> I was just saying that not returning something that is a pair, for
> example nil, is good enough.

The implement is equivalent, most languages I know that has unfold use
your approach(i.e. return Maybe or None).

This link use the unfold p f g form

http://webcache.googleusercontent.com/search?q=cache:ksRX1JVmxFgJ:www.comlab.ox.ac.uk/jeremy.gibbons/publications/unfold.ps.gz+unfold+p+f+g&cd=5&hl=en&ct=clnk&gl=ca

-- 
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: disk-backed memoize?

2010-09-17 Thread Wilson MacGyver
I highly recommend using redis for this. There is even a clojure redis client.

http://github.com/ragnard/redis-clojure


On Fri, Sep 17, 2010 at 9:00 PM, David McNeil  wrote:
> Is there a disk-backed memoize available? I have an application where
> I would like the cache of values to survive restarts of the app.
>
> Thank you.
> -David McNeil

-- 
Omnem crede diem tibi diluxisse supremum.

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


disk-backed memoize?

2010-09-17 Thread David McNeil
Is there a disk-backed memoize available? I have an application where
I would like the cache of values to survive restarts of the app.

Thank you.
-David McNeil

-- 
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: practical clojure

2010-09-17 Thread David J
I second faenvie's request for "applications of Clojure" books,
especially on AI. AI is the reason I started looking at a Lisp in the
first place. I'd also like to see Clojure become *the* language for
statistics, though I understand that R statisticians aren't so fond of
Lisps.

I just bought Practical Clojure and am enjoying it as well. After
browsing through an alternative at Barnes and Noble, I was thoroughly
confused about Clojure and did not think it a beautiful language.
After that, I picked up Practical Clojure and immediately connected
with it (and the language). Though it is described as "practical", you
don't spare us the theory, and I love that. (A detail I really liked
is that you save the ugliness that is Java till the end.)

The flow is excellent and well-thought-out, and I'm glad you start by
describing the Clojure philosophy and don't shirk explanations of its
complexity under the hood. For me, this book (so far) feels like "The
C Programming Language".

Well done.

On Sep 16, 8:00 pm, Stuart Sierra  wrote:
> Thanks! Glad you liked the book.
> -S
>
> On Sep 14, 8:37 am, faenvie  wrote:
>
>
>
> > i just emerged from a whirlwind read
> > through 'practical clojure'. i like this book
> > very much.
>
> > it's a very well structured, carefully written
> > book. kind of a minimalistic approach but minimalistic
> > in the positive sense clojure itself is.
>
> > so now 'students' have really good choices
> > among 4 high quality introductions and can
> > combine them.
>
> > for the future: some books about solving state of
> > the art problems with clojure would be nice to come.
> > something like peter norvigs book on AI programming.

-- 
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: Displaying POSTed string from form text-field in Compojure

2010-09-17 Thread Victor Olteanu
Sure, here it is:

(defn view-layout [& content]
  (html
   (doctype :xhtml-strict)
   (xhtml-tag "en"
  [:head
   [:meta {:http-equiv "Content-type"
   :content "text/html; charset=utf-8"}]
   [:title "Datum"]]
  [:body content])))


This was actually taken from an online tutorial with some changes (
http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applications.html
 )
More specifically, in the original tutorial there was an additional
intermediate step when the input was "parsed":
(parse-input a b)

with the function
(defn parse-input [a b]
  [(Integer/parseInt a) (Integer/parseInt b)])(parse-input a b)

However in my case I'm just dealing with strings, so there's no "parseInt"
involved. So I assumed my input is strings-- which doesn't seem to be the
case, and there are no "parseString" methods that I could use instead.

Thank you,
Victor

On Fri, Sep 17, 2010 at 5:30 PM, Miki  wrote:

> My *guess* it's somehow connected to the code of "view-layout" since
> it shows the representation of the function "str".
> Can place the full code (including view-layout) somewhere?
>
> On Sep 17, 12:35 pm, Victor  wrote:
> > Hi all,
> >
> > I'm having a problem that may or may not be Compojure specific, so I
> > thought I'd try this group since the answer is probably easy- I am
> > just stuck.
> >
> > I am reading the string through a simple form
> >
> > (defn view-input []
> >  (view-layout
> >   [:h2 "Enter one datum:"]
> >   [:form {:method "post" :action "/"}
> >[:input.datum {:type "text" :name "my_datum"}]
> >[:input.action {:type "submit" :value "Add"}]]))
> >
> > where the route for posting is
> >
> >  (POST "/" [a]
> >   (view-output a)))
> >
> > I then simply want to display what I entered and submitted (say I
> > typed the string "a").
> >
> > (defn view-output [a]
> >  (view-layout
> >   [:h2 (str "This is what you entered: " a)))
> >
> > However what I get is this:
> >
> > clojure.core$...@1e731e90
> >
> > Thanks in advance for your help!
> > 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
>

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

concurrency example about java x clojure

2010-09-17 Thread anderson_leite
I'm new to clojure, so sorry if this is a dummie question.

Studyng clojure I can understand the syntax and so onbut I would
like a real example comparing clojure and java.

Do you know some benchmark using first just java and than showing the
best results with 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


Clojure-conj speaker abstracts posted

2010-09-17 Thread liebke
The abstracts for the talks at the first Clojure-conj have been
posted.

http://first.clojure-conj.org/speakers

Looking forward to seeing many of you there,
David

-- 
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: datastore not saving? [appengine-clj]

2010-09-17 Thread Miki
Found it, should be "user" (singular)

On Sep 17, 2:56 pm, Miki  wrote:
> Greetings,
>
> I'm trying to use appengine-clj (http://github.com/r0man/appengine-
> clj) datastore and having a problem. This is probably not a bug but
> something I'm missing.
>
> I'm trying the following:
>
> (defentity User ()
>   ((id)
>    (phone)))
>
> (save-entity (user {:id "1" :phone "2"}))
> (count (select "users"))
>
> The last statement return 0, so it looks to me that nothing was saved.
> What am I doing wrong?
>
> Thanks,
> --
> Miki

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


datastore not saving? [appengine-clj]

2010-09-17 Thread Miki
Greetings,

I'm trying to use appengine-clj (http://github.com/r0man/appengine-
clj) datastore and having a problem. This is probably not a bug but
something I'm missing.

I'm trying the following:

(defentity User ()
  ((id)
   (phone)))

(save-entity (user {:id "1" :phone "2"}))
(count (select "users"))

The last statement return 0, so it looks to me that nothing was saved.
What am I doing wrong?

Thanks,
--
Miki

-- 
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: Displaying POSTed string from form text-field in Compojure

2010-09-17 Thread Miki
My *guess* it's somehow connected to the code of "view-layout" since
it shows the representation of the function "str".
Can place the full code (including view-layout) somewhere?

On Sep 17, 12:35 pm, Victor  wrote:
> Hi all,
>
> I'm having a problem that may or may not be Compojure specific, so I
> thought I'd try this group since the answer is probably easy- I am
> just stuck.
>
> I am reading the string through a simple form
>
> (defn view-input []
>  (view-layout
>   [:h2 "Enter one datum:"]
>   [:form {:method "post" :action "/"}
>    [:input.datum {:type "text" :name "my_datum"}]
>    [:input.action {:type "submit" :value "Add"}]]))
>
> where the route for posting is
>
>  (POST "/" [a]
>   (view-output a)))
>
> I then simply want to display what I entered and submitted (say I
> typed the string "a").
>
> (defn view-output [a]
>  (view-layout
>   [:h2 (str "This is what you entered: " a)))
>
> However what I get is this:
>
> clojure.core$...@1e731e90
>
> Thanks in advance for your help!
> 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: thinking in clojure

2010-09-17 Thread Michael Ossareh
On Fri, Sep 17, 2010 at 08:58, Michael Wood  wrote:
> On 17 September 2010 00:56, Michael Ossareh  wrote:
>> Meikel,
>>
>>>
     (recur (cond (not (nil? (data key)))
                (true? true)
>>>
>>> *ieeck* Please do (cond ... :else default-clause). Not true, or (true?
>>> true) or other stuff.
>>
>> Wow, I somehow missed the :else option in cond? I've got that (true?
>> true) stuff scattered all over my code - going to change that right
>> now. Thanks for showing me this.
>
> It's not actually an ":else option in cond".  Anything that is not
> false or nil can work there, so :any-arb-keyword would work just as
> well as :else.  But by convention, Clojure programmers tend to use
> :else.
>

Thanks for confirming my thoughts, Michael. Indeed I immediately
checked the docs and couldn't find :else referenced.

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


Displaying POSTed string from form text-field in Compojure

2010-09-17 Thread Victor
Hi all,

I'm having a problem that may or may not be Compojure specific, so I
thought I'd try this group since the answer is probably easy- I am
just stuck.

I am reading the string through a simple form

(defn view-input []
 (view-layout
  [:h2 "Enter one datum:"]
  [:form {:method "post" :action "/"}
   [:input.datum {:type "text" :name "my_datum"}]
   [:input.action {:type "submit" :value "Add"}]]))


where the route for posting is

 (POST "/" [a]
  (view-output a)))

I then simply want to display what I entered and submitted (say I
typed the string "a").

(defn view-output [a]
 (view-layout
  [:h2 (str "This is what you entered: " a)))

However what I get is this:

clojure.core$...@1e731e90



Thanks in advance for your help!
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: Feature idea: meta-macros

2010-09-17 Thread Alessio Stalla
On 17 Set, 17:34, Doug Philips  wrote:
> On Fri, Sep 17, 2010 at 08:50, Alessio Stalla  wrote:
> > On Sep 16, 4:10 pm, Nicolas Oury  wrote:
> > Note also that the OP's original example does not require anything
> > more than what defmacro already provides. And turning function calls
> > into macro calls is not a great idea; it won't cover the use of apply
> > and similar.
>
> Hmmm, that's odd. Perhaps I've missed a message somehow, but I'm not
> sure why name-space manipulation isn't the right thing to use.
> To condense, I want to "change the behaviour" of (foo ...), is that right?
> If so, then instead of getting the definition of foo from its usual
> name space, couldn't I get it from a 'tracing foo' name space or
> 'wrapping foo in bar' name space?  I think I could do this with
> macros, such that the usual name space that foo comes from is used,
> but foo is 'redefined' with a macro to do something that masquerades
> as foo and probably/maybe calls the 'real' foo eventually. Problem is
> that macros interact with apply, etc. so I'm back to thinking name
> space manipulations are the right thing, or that I've skimmed too much
> and don't understand the problem. :-)

Hmm. I can't quite understand what you mean by namespace
manipulations, because my Clojure-fu is really limited, I'm just
lurking here to keep in touch with what happens in "the other camp" ;)
Anyway, I don't think it's *you* the one who "gets the definition of
foo from the  namespace"; it's the Clojure system that does.
So if you want to make Clojure see a different foo, you have to
redefine - or rebind, with the appropriate caveats - foo. Redefining
it as a function is sufficient; introducing a macro doesn't buy
anything in this case: it forces you to recompile all the code that
uses foo, even third-party code, and makes the new foo lose its first-
class object status. In general, using a macro to modify the behaviour
of existing code is dangerous and smells a little too much like C ;)

Just my €.02,
Alessio

-- 
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: partition-starting-every : yet another partition function

2010-09-17 Thread Nicolas Oury
(defn unfold
  ([grow seed]
   (lazy-seq
(if-let [[elt next-seed] (grow seed)]
(cons elt (unfold grow next-seed)
  ([grow  finished? seed]
   (unfold #(when (not (finished? %)) (grow %)) seed)))

(unfold (fn [x] [(* x x) (inc x)]) #(> % 10) 0)
(0 1 4 9 16 25 36 49 64 81 100)

(unfold (fn [x] (when (<= x 10) [(* x x) (inc x)]))  0)
(0 1 4 9 16 25 36 49 64 81 100)

I think it can be proved that any sequence can be build with a call to unfold.
Which makes it useful and solves the
"why reduce is not lazy?" question.

-- 
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: partition-starting-every : yet another partition function

2010-09-17 Thread Nicolas Oury
I was just saying that not returning something that is a pair, for
example nil, is good enough.

 (unfold (fn [x] (when (<= x 10)  [(* x x) (inc x)])) would work.

Both function can be written with each other anyway.

And they don't have the same number of args so they are compatible
with each other.

On Thu, Sep 16, 2010 at 8:05 PM, Gijs S.  wrote:
> Finished is a predicate which designates when the seed is exhausted.
> Because seed is not necessary a sequence, finished is not always
> empty?.
>
>
>
> For instance:
>
>
>
> => (unfold (fn [x] [(* x x) (inc x)]) #(> % 10) 0)
>
> (0 1 4 9 16 25 36 49 64 81 100)
>
>
>
> Or the zipmap (zip2) example from the wikipedia page.
>
>
>
> Although the first example wanders back into territory where the
> existing sequence functions such as iterate, take-while and for would
> suffice.
>
> -Gijs
>
> --
> 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



-- 
Sent from an IBM Model M, 15 August 1989.

-- 
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: ClassCastException: class to interface

2010-09-17 Thread JonnyB
> "[L..." is an array of ..., so it looks like you need to create a Java
> array to give it.

Oh, dear,  i could have expected something like that :)
But i spent a lot of time, just being clueless.

Thank you a lot for your help!
and big shout outs to everyone making this language possible!

JonnyB


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


The failing test cases in c.c.logging

2010-09-17 Thread Hugo Duncan
While debugging tests (hudson only failures) in pallet, I noticed that  
there was some interaction between my tests, as if they were running in  
parallel.  To solve the issues I added binding calls inside each test  
case, which solved my issues.


The c.c.logging test cases failures look similar, so might I suggest  
adding a binding for log/*logging-agent* inside each of the failing tests.


I am unable to explain why there is an interaction.

--
Hugo Duncan

--
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: thinking in clojure

2010-09-17 Thread Michael Wood
On 17 September 2010 00:56, Michael Ossareh  wrote:
> Meikel,
>
>>
>>>     (recur (cond (not (nil? (data key)))
>>>                (true? true)
>>
>> *ieeck* Please do (cond ... :else default-clause). Not true, or (true?
>> true) or other stuff.
>
> Wow, I somehow missed the :else option in cond? I've got that (true?
> true) stuff scattered all over my code - going to change that right
> now. Thanks for showing me this.

It's not actually an ":else option in cond".  Anything that is not
false or nil can work there, so :any-arb-keyword would work just as
well as :else.  But by convention, Clojure programmers tend to use
:else.

-- 
Michael Wood 

-- 
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: Feature idea: meta-macros

2010-09-17 Thread Doug Philips
On Fri, Sep 17, 2010 at 08:50, Alessio Stalla  wrote:
> On Sep 16, 4:10 pm, Nicolas Oury  wrote:
> Note also that the OP's original example does not require anything
> more than what defmacro already provides. And turning function calls
> into macro calls is not a great idea; it won't cover the use of apply
> and similar.

Hmmm, that's odd. Perhaps I've missed a message somehow, but I'm not
sure why name-space manipulation isn't the right thing to use.
To condense, I want to "change the behaviour" of (foo ...), is that right?
If so, then instead of getting the definition of foo from its usual
name space, couldn't I get it from a 'tracing foo' name space or
'wrapping foo in bar' name space?  I think I could do this with
macros, such that the usual name space that foo comes from is used,
but foo is 'redefined' with a macro to do something that masquerades
as foo and probably/maybe calls the 'real' foo eventually. Problem is
that macros interact with apply, etc. so I'm back to thinking name
space manipulations are the right thing, or that I've skimmed too much
and don't understand the problem. :-)

-Doug

-- 
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: inline vs extended types

2010-09-17 Thread grinnbearit
Thanks for replying,

Would definterface be the right thing to do in this case? I'm trying
to understand how best to solve similar problems and not this one in
particular.

sincerely
Sidhant

-- 
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: thinking in clojure

2010-09-17 Thread Michael Ossareh
Meikel,

>
>>     (recur (cond (not (nil? (data key)))
>>                (true? true)
>
> *ieeck* Please do (cond ... :else default-clause). Not true, or (true?
> true) or other stuff.

Wow, I somehow missed the :else option in cond? I've got that (true?
true) stuff scattered all over my code - going to change that right
now. Thanks for showing me this.

-- 
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: thinking in clojure

2010-09-17 Thread Michael Ossareh
>> (loop [data (sorted-map)
>>          collection newData
>>          meeting (first collection)]
>>
>>   (def key (  ))
>
> As a general rule, def should only be used at the top level. You
> probably want (let [key ...] (if ...) here.

Hey, thanks for pointing this out - I was actually just trying to
avoid passing these values in the loop signature. Your point is very
well taken and I've now replaced those (def)'s with a let inside the
loop.

>
>>   (if (not (nil? (next collection)
>
> Minor nit: (not (nil? X)) is better spelled (seq? X))

Right!


> That's actually a standard idiom, except you missed the assoc-in and
> get-in functions:
>
> (assoc-in data key :meetings (conj (get-in data key :meetings) meeting)

Thanks for the advice. I've taken Laurent's feedback and ended up with:

 (update-in data [week-difference]
  (fnil update-in (struct week title []))
  ["meetings"] into [decorated])

Which certainly reads far better than what I had. Thanks for pointing
out get-in, another *key* fn I've missed.

The standard library is rather large, I guess this'll take a while.

-- 
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: thinking in clojure

2010-09-17 Thread Michael Ossareh
On Thu, Sep 16, 2010 at 07:53, Laurent PETIT  wrote:
> 2010/9/16 Meikel Brandmeyer 
>>
>> Hi Laurent,
>>
>> On 16 Sep., 15:54, Laurent PETIT  wrote:
>>
>> > you don't like my one-liner ? :-)
>>
>> I saw your message only after I sent mine. :)
>>
>> > (update-in coll [k] (fnil update-in *default-value*) [:meetings] (comp
>> > vec
>> > concat) data)
>>
>> Hmm... (comp vec concat) == into?
>
> Yep.
> so this is the killer one : :-)
> (update-in coll [k] (fnil update-in *default-value*) [:meetings] into data)

Awesome, thank you for returning concision to my code! I'd certainly
missed the update-in, and related, functions.

Cheers 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
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: partition-starting-every : yet another partition function

2010-09-17 Thread Gijs S.
Finished is a predicate which designates when the seed is exhausted.
Because seed is not necessary a sequence, finished is not always
empty?.



For instance:



=> (unfold (fn [x] [(* x x) (inc x)]) #(> % 10) 0)

(0 1 4 9 16 25 36 49 64 81 100)



Or the zipmap (zip2) example from the wikipedia page.



Although the first example wanders back into territory where the
existing sequence functions such as iterate, take-while and for would
suffice.

-Gijs

-- 
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 eval + records + protocols

2010-09-17 Thread Todd
I'm able to eval forms and strings defined at the root of a clojure file 
(example below). Then I extended this pattern to records and protocols.


Q: Is this idiomatic clojure? Is there a better pattern for 
encapsulating data/code in clojure?


Q: How would one guard against the brittleness of encapsulating api 
details like this in the data? As the Protocol and Record 
implementations are rev'd, how would one make the underlying data 
flexible to this (backwards compatible?)


-Todd

-
CODE
-

$ cat context.clj
(def dsl-form '(foo "bar from dsl-form"))
(def dsl-text "(foo \"bar from dsl-text\")")

(defn foo [t] (println "foo: " t))

(println "--")
(println "direct eval and load-string")
(println "--")

(eval dsl-form)
(load-string dsl-text)

(println "--")
(println "eval via a record and protocol")
(println "--")

; This implementation does not work, because there is an implicit 'this'
; implied in the record.
;(defprotocol TestProtocol1
;  (foo [t] "test method")
;  (process [s] "evaluate inpt") )
;
;(defrecord MyRecord1 [name]
;  TestProtocol1
;(foo [t] (println "MyRecord" t))
;(process [s] (eval s)))
;
;(def r1 (MyRecord1. ["somename"]))
;  (doto r1
;(.process dsl-form)
;(.process dsl-text)))
;

;(def dsl-form2 '(foo this "bar from dsl-form"))
;(def dsl-text2 "(foo this \"bar from dsl-text\")")
;
;(defprotocol TestProtocol2
;  (foo [this t] "test method")
;  (process [this s] "evaluate inpt") )
;
;(defrecord MyRecord2 [name]
;  TestProtocol2
;(foo [this t] (println "MyRecord2" t))
;(process [this s] (eval s)))
;
;(def r2 (MyRecord2. ["somename"]))
;
;(doto r2
; (.process dsl-form2)
; (.process dsl-text2))


(def *record* nil)

(def dsl-form3 '(foo *record* "bar from dsl-form"))
(def dsl-text3 "(foo *record* \"bar from dsl-text\")")

(defprotocol TestProtocol3
  (foo [this t] "test method")
  (process [this s] "evaluate inpt") )

(defrecord MyRecord3 [name]
  TestProtocol3
(foo [this t] (println "MyRecord3" t))
(process [this s]
  (binding [*record* this]
(eval s

(def r3 (MyRecord3. ["somename"]))

(doto r3
 (.process dsl-form3)
 (.process dsl-text3))


-
OUTPUT
-
t...@greenmachine:~/Documents/projects/clojure/lein-test/clojure-cad$ 
clj.sh  context.clj
java -server -cp 
/Users/todd/bin/jline/jline-0_9_5.jar:/Users/todd/bin/clojure/clojure.jar:/Users/todd/bin/clojure/clojure-contrib.jar 
jline.ConsoleRunner clojure.main context.clj

--
direct eval and load-string
--
foo:  bar from dsl-form
foo:  bar from dsl-text
--
eval via a record and protocol
--
Warning: protocol #'user/TestProtocol3 is overwriting function foo
MyRecord3 bar from dsl-form

--
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: Feature idea: meta-macros

2010-09-17 Thread Alessio Stalla
On Sep 16, 4:10 pm, Nicolas Oury  wrote:
> The logged function would have to be already a generic method, no?

Yes, and in idiomatic Common Lisp that's not particularly common
(pardon the pun). Generic functions are typically only used when
dynamic dispatch is actually needed. However, you can achieve what the
OP asked by doing something like (untested):

(let ((original-fn (symbol-function 'foo)))
  (setf (symbol-function 'foo) (lambda (&rest args) ...whatever...
(apply original-fn args

which is similar to the alter-var-root solution proposed upthread.
Note also that the OP's original example does not require anything
more than what defmacro already provides. And turning function calls
into macro calls is not a great idea; it won't cover the use of apply
and similar.

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