Re: Ring startup processing?

2010-11-27 Thread lprefontaine
>From http://docstore.mik.ua/orelly/java-ent/servlet/ch03_03.htm
-
Just like applets, servlets can define init() and destroy() methods. A servlet's
init(ServletConfig) method is called by the server immediately after the server
constructs the servlet's instance. Depending on the server and its
configuration, this can be at any of these times:

* When the server starts
* When the servlet is first requested, just before the service() method is
invoked
* At the request of the server administrator

In any case, init() is guaranteed to be called before the servlet handles its
first request. 

--
We use a dedicated servlet for every web app to make sure all prerequisites
are met. Since it's loaded first, we can find problems by looking at a single
piece of the log files just after the container messages announcing that
it's loading the app. 

We also avoid variable load times depending on the container's behavior
and setup.

Of course Mike does not need to do that if he has a only few inits related
to a single servlet.

Luc P.


Rob Lachlan  wrote ..
> The servlet interface includes the init method for this exact
> purpose.  In java, this would be used by subclassing one of the
> abstract servlet classes, and filling in the init method with whatever
> initialization you need.  Or by implementing the servlet interface
> directly.
> 
> From the javadoc, the init method "Initializes the servlet. The method
> is called once, automatically, by the servlet engine when it loads the
> servlet. It is guaranteed to finish before any service requests are
> accepted."  I find this approach more straightforward than having an
> entire separate servlet for initialization.
> 
> I was hoping that initialization of this kind would make it into the
> ring spec, but there wasn't much support.  See the thread below for
> more details:
> 
> http://groups.google.com/group/ring-clojure/browse_thread/thread/ec5a30b5bb4ec823#
> 
> Rob
> 
> 
> On Nov 27, 4:50 pm, Mike Meyer  620...@mired.org> wrote:
> > My simple web app
> > (http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has
> > some stuff that needs to happen just once (in this case, opening the
> > serial port). It's not clear how to get this to happen using ring. If
> > I do it inside my ring handler, then it gets run on every request, and
> > I have to check to make sure it's not run multiple times. If I run it
> > outside the handler, then it gets run when I do "lein uberwar", which
> > is simply wrong.
> >
> > When the deployment platform activates the war would seem to be the
> > right time to run this ("war load time"?). So maybe this is a question
> > that depends on the deployment platform, or war? However, a quick
> > google search didn't turn up anything that looked interesting.
> >
> > Anyone got suggestions on how to set up code to be run when Jetty (or
> > tomcat, or ...)?
> >
> >         thanks,
> >          > --
> > Mike Meyer           http://www.mired.org/consulting.html
> > Independent Network/Unix/Perforce consultant, email for more information.
> >
> > O< ascii ribbon campaign - stop html mail -www.asciiribbon.org
> 
> -- 
> 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
Luc P.


The rabid Muppet

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

2010-11-27 Thread Alex Osborne
Andreas Kostler  writes:

> Is this a 'bug' with eval?

No, eval is a simply a function and so like any other function it can't
"see" the lexical (local) environment which it was called from.

Doing this:

(let [a 1, b 2] (eval '(+ a b)))

Is similar to doing this:

(defn cake []
  (+ a b))

(let [a 1, b 2] (cake))

Anyway, here's my take on a eval macro which captures the lexical
environment.  It's similar to Ken's but avoids the need to explicitly
specify the environment.

First we need a version of eval which takes some let bindings.  This is
straightforward, just wrap the form in a let statement:

(defn eval-let [bindings form]
  (eval `(let [...@bindings] ~form)))

Note that's just a regular function again.  We can use it like so:

(eval-let '[a 1, b 2] '(+ a b))
;; => 3

Next we need a way of getting at the lexical environment.  Since 1.2
there's a nice supported way to do it.  There's an implicit argument
passed to macros called &env.  (keys &env) will get us a list of symbols
in the lexical environment, so:

(defmacro lexical-bindings []
  (let [symbols(keys &env)
quoted-symbols (for [sym symbols] `(quote ~sym))]
(vec (interleave quoted-symbols symbols

What the heck does that do?  Simple, if the environment contains
bindings 'a and 'b then it expands to the code ['a a 'b b].

Let's try it:

(let [a 1, b 2] (lexical-bindings))
;; => [b 2 a 1]

Perfect!  That's actually all we need:

(let [a 1, b 2] (eval-let (lexical-bindings) '(+ a b)))
;; => 3

But for brevity we could define one last macro:

(defmacro lexeval [form]
  `(eval-let (lexical-bindings) ~form))

And thus a version of eval which does what you're expecting:

(let [a 1, b 2] (lexeval '(+ a b)))
;; => 3

-- 
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: Wolfram: 100 years since Principia Mathematica

2010-11-27 Thread Duane Searsmith
I thought his blog had some interesting points.  I enjoyed reading it.  Do I
wish Mathematica was more affordable and/or open source?  Yes.  So what.
That doesn't make Wolfram a lunatic or a fraud.  Remember that
mathematicians like Mandelbrot where also considered frauds at first.

On Fri, Nov 26, 2010 at 6:45 PM, Alec Battles wrote:

> > Thought some Clojure folk might enjoy this:
> >
> >
> http://blog.stephenwolfram.com/2010/11/100-years-since-principia-mathematica/
>
> Though I don't use Clojure (I follow this list out of curiosity), I
> have a hard time imagining why anything Wolfram writes is interesting,
> and furthermore why any a user of any not-so-mainstream language would
> find it interesting, and even furthermore why a mathematician would.
>
> "And in mathematics, the difference between open-source and
> closed-source is more important, for the reason that any part of a
> mathematical solution that cannot be fully examined is fatal to the
> result."
>
> --http://www.arachnoid.com/sage/
>
> Sorry if members of this group consider this off-topic, but I honestly
> couldn't restrain myself...
>
> --
> 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: REQUEST for feedback on http://clojure.org

2010-11-27 Thread Tom Faulhaber
Jason,

Actually Alex was a little off the mark here. The problem was in the
templates that generate the autodoc so they were pretty easy to fix
for all versions.

The github links are now fixed and I expect to modify the assembla
pointers to the new confluence/jira stuff tonight or tomorrow.

Please *do* continue to point out errors in the autodoc (formatting,
content, things missing, etc.) and I will fix them (though sometimes
it might take just a little bit).

Thanks,

Tom

On Nov 2, 1:58 pm, Alex Miller  wrote:
> Jason - that's a good catch but out of my purview.  Also, those are
> autodocs generated from the (released and thus immutable :) 1.2
> afaik.
>
> On Nov 2, 4:12 pm, Jason Wolfe  wrote:
>
> > Not sure if you count this as off limits as part of the API page, but
> > its first line points to a stale "official source code for clojure"
> > -- should be updated to the new github repo.
>
> > -Jason

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

2010-11-27 Thread Tim Robinson
This works as I would expect it to.

'rule' brings in 'state' from the global binding into it's scope
giving it priority over the outer scope bindings found in the parent
function.

On Nov 27, 9:15 pm, Andreas Kostler  wrote:
> Is this a 'bug' with eval?
>
> On 28 November 2010 14:09, Ken Wesson  wrote:
>
>
>
> > On Sat, Nov 27, 2010 at 10:42 PM, Andreas Kostler
> >  wrote:
> > > Hi all,
> > > Sorry for my noob question (again). I'm trying to understand clojures
> > > binding model.
> > > Typing:
> > > (def state {:status "foo"})
> > > (def rule '(if (= (:status sate) "foo") (println "foo") (println
> > > ("bar")))
>
> > > (defn fn []
> > >  (let [state {:status "bar"}]
> > >    (eval rule)))
>
> > > This prints "foo". However, I would have expected the binding of state
> > > created by let would shadow the global binding of state.
> > > Now
>
> > > (defn fn1 []
> > >  (binding [state {:status "bar"}]
> > >    (eval rule)))
> > > Does the right thing. Can someone explain what's going on here please?
>
> > This is eval not seeing local bindings. There is a workaround:
>
> > (defmacro eval-with-local-vars [vars sexp]
> >  (let [quoted-vars (vec (map #(list 'quote %) vars))]
> >   `(let [varvals# (vec (interleave ~quoted-vars ~vars))]
> >      (eval (list 'clojure.core/let varvals# ~sexp)
>
> > user=> (let [a 1 b 2] (eval-with-local-vars [a b] '(+ a b)))
> > 3
> > user=> (def state {:status "foo"})
> > #'user/state
> > user=> (def rule
> >         '(if (= (:status state) "foo")
> >            (println "foo")
> >            (println "bar")))
> > #'user/rule
> > user=> (let [state {:status "bar"}]
> >         (eval rule))
> > foo
> > nil
> > user=> (let [state {:status "bar"}]
> >         (eval-with-local-vars [state] rule))
> > bar
> > nil
>
> > --
> > 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
>
> --
> **
> Andreas Koestler, Software Engineer
> Leica Geosystems Pty Ltd
> 270 Gladstone Road, Dutton Park QLD 4102
> Main: +61 7 3891 9772     Direct: +61 7 3117 8808
> Fax: +61 7 3891 9336
> Email: andreas.koest...@leica-geosystems.com
>
> www.leica-geosystems.com*
>
> when it has to be right, Leica Geosystems
>
> Please  consider the environment before printing this email.

-- 
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: Ring startup processing?

2010-11-27 Thread Rob Lachlan
The servlet interface includes the init method for this exact
purpose.  In java, this would be used by subclassing one of the
abstract servlet classes, and filling in the init method with whatever
initialization you need.  Or by implementing the servlet interface
directly.

>From the javadoc, the init method "Initializes the servlet. The method
is called once, automatically, by the servlet engine when it loads the
servlet. It is guaranteed to finish before any service requests are
accepted."  I find this approach more straightforward than having an
entire separate servlet for initialization.

I was hoping that initialization of this kind would make it into the
ring spec, but there wasn't much support.  See the thread below for
more details:

http://groups.google.com/group/ring-clojure/browse_thread/thread/ec5a30b5bb4ec823#

Rob


On Nov 27, 4:50 pm, Mike Meyer  wrote:
> My simple web app
> (http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has
> some stuff that needs to happen just once (in this case, opening the
> serial port). It's not clear how to get this to happen using ring. If
> I do it inside my ring handler, then it gets run on every request, and
> I have to check to make sure it's not run multiple times. If I run it
> outside the handler, then it gets run when I do "lein uberwar", which
> is simply wrong.
>
> When the deployment platform activates the war would seem to be the
> right time to run this ("war load time"?). So maybe this is a question
> that depends on the deployment platform, or war? However, a quick
> google search didn't turn up anything that looked interesting.
>
> Anyone got suggestions on how to set up code to be run when Jetty (or
> tomcat, or ...)?
>
>         thanks,
>          --
> Mike Meyer           http://www.mired.org/consulting.html
> Independent Network/Unix/Perforce consultant, email for more information.
>
> O< ascii ribbon campaign - stop html mail -www.asciiribbon.org

-- 
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: clojure 1.3 alpha3 and swank

2010-11-27 Thread Michael Ossareh
I had no issues with swank-clojure 1.3.0:

in project.clj [swank-clojure "1.3.0"]

I had plenty of issues using other libraries as there are some breaking
changes in 1.3. YMMV.

On Thu, Nov 25, 2010 at 05:52, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:

> Hello Everybody,
>  I would like to have a go at 1.3 alpha3 .. but having a lot of trouble
> with the swank.. can somebody suggest me a version of swank-clojure that has
> worked for them along with 1.3 alpha3
>
> Thanks,
> Sunil.
>
> --
> 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 At True Values Of Predicate

2010-11-27 Thread Benny Tsai
Huh, didn't know that about 'distinct'.  Thank you for the tip.

On Nov 27, 9:18 pm, Ken Wesson  wrote:
> On Sat, Nov 27, 2010 at 11:03 PM, Benny Tsai  wrote:
> > That's what I get for coding without taking my afternoon nap :)
>
> > Try 3.  Tweaked 'subsequence' and 'split-when' so that it is no longer
> > necessary to calculate the index for the end of the collection.  Also
> > added a check to 'split-when' to return an empty list when called on
> > an empty collection; otherwise it would return (()), which seemed like
> > a strange result.
>
> > (use '[clojure.contrib.seq :only (indexed)])
>
> > (defn index-filter [pred coll]
> >  (when pred
> >    (for [[idx elt] (indexed coll) :when (pred elt)] idx)))
>
> > (defn subsequence
> >  ([coll start]
> >     (drop start coll))
> >  ([coll start end]
> >     (take (- end start) (drop start coll
>
> > (defn split-when [pred coll]
> >  (if (empty? coll)
> >    '()
> >    (let [indices (distinct (conj (index-filter pred coll) 0))
> >          index-groups (partition-all 2 1 indices)]
> >      (map #(apply subsequence coll %) index-groups
>
> While (distinct foo) is technically lazy, it retains in a set in
> memory every distinct element seen so far, and with the indices here
> that's as bad as holding onto the head. And all to avoid a 0 being
> repeated at the start. Try:
>
> (defn add-zero [coll]
>   (if (= 0 (first coll)) coll (cons 0 coll)))
>
> (defn split-when [pred coll]
>   (if (empty? coll)
>     '()
>     (let [indices (add-zero (index-filter pred coll))
>           index-groups (partition-all 2 1 indices)]
>       (map #(apply subsequence coll %) index-groups

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

2010-11-27 Thread Ken Wesson
On Sat, Nov 27, 2010 at 11:15 PM, Andreas Kostler
 wrote:
> Is this a 'bug' with eval?

It seems to be intended, if undocumented* and sometimes awkward, behavior.

* In that (doc eval) doesn't say anything about this issue.

-- 
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 At True Values Of Predicate

2010-11-27 Thread Ken Wesson
On Sat, Nov 27, 2010 at 11:03 PM, Benny Tsai  wrote:
> That's what I get for coding without taking my afternoon nap :)
>
> Try 3.  Tweaked 'subsequence' and 'split-when' so that it is no longer
> necessary to calculate the index for the end of the collection.  Also
> added a check to 'split-when' to return an empty list when called on
> an empty collection; otherwise it would return (()), which seemed like
> a strange result.
>
> (use '[clojure.contrib.seq :only (indexed)])
>
> (defn index-filter [pred coll]
>  (when pred
>    (for [[idx elt] (indexed coll) :when (pred elt)] idx)))
>
> (defn subsequence
>  ([coll start]
>     (drop start coll))
>  ([coll start end]
>     (take (- end start) (drop start coll
>
> (defn split-when [pred coll]
>  (if (empty? coll)
>    '()
>    (let [indices (distinct (conj (index-filter pred coll) 0))
>          index-groups (partition-all 2 1 indices)]
>      (map #(apply subsequence coll %) index-groups

While (distinct foo) is technically lazy, it retains in a set in
memory every distinct element seen so far, and with the indices here
that's as bad as holding onto the head. And all to avoid a 0 being
repeated at the start. Try:

(defn add-zero [coll]
  (if (= 0 (first coll)) coll (cons 0 coll)))

(defn split-when [pred coll]
  (if (empty? coll)
    '()
    (let [indices (add-zero (index-filter pred coll))
          index-groups (partition-all 2 1 indices)]
      (map #(apply subsequence coll %) index-groups

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

2010-11-27 Thread Andreas Kostler
Is this a 'bug' with eval?

On 28 November 2010 14:09, Ken Wesson  wrote:

> On Sat, Nov 27, 2010 at 10:42 PM, Andreas Kostler
>  wrote:
> > Hi all,
> > Sorry for my noob question (again). I'm trying to understand clojures
> > binding model.
> > Typing:
> > (def state {:status "foo"})
> > (def rule '(if (= (:status sate) "foo") (println "foo") (println
> > ("bar")))
> >
> > (defn fn []
> >  (let [state {:status "bar"}]
> >(eval rule)))
> >
> > This prints "foo". However, I would have expected the binding of state
> > created by let would shadow the global binding of state.
> > Now
> >
> > (defn fn1 []
> >  (binding [state {:status "bar"}]
> >(eval rule)))
> > Does the right thing. Can someone explain what's going on here please?
>
> This is eval not seeing local bindings. There is a workaround:
>
> (defmacro eval-with-local-vars [vars sexp]
>  (let [quoted-vars (vec (map #(list 'quote %) vars))]
>   `(let [varvals# (vec (interleave ~quoted-vars ~vars))]
>  (eval (list 'clojure.core/let varvals# ~sexp)
>
> user=> (let [a 1 b 2] (eval-with-local-vars [a b] '(+ a b)))
> 3
> user=> (def state {:status "foo"})
> #'user/state
> user=> (def rule
> '(if (= (:status state) "foo")
>(println "foo")
>(println "bar")))
> #'user/rule
> user=> (let [state {:status "bar"}]
> (eval rule))
> foo
> nil
> user=> (let [state {:status "bar"}]
> (eval-with-local-vars [state] rule))
> bar
> nil
>
> --
> 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
>



-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

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

2010-11-27 Thread Ken Wesson
On Sat, Nov 27, 2010 at 10:42 PM, Andreas Kostler
 wrote:
> Hi all,
> Sorry for my noob question (again). I'm trying to understand clojures
> binding model.
> Typing:
> (def state {:status "foo"})
> (def rule '(if (= (:status sate) "foo") (println "foo") (println
> ("bar")))
>
> (defn fn []
>  (let [state {:status "bar"}]
>    (eval rule)))
>
> This prints "foo". However, I would have expected the binding of state
> created by let would shadow the global binding of state.
> Now
>
> (defn fn1 []
>  (binding [state {:status "bar"}]
>    (eval rule)))
> Does the right thing. Can someone explain what's going on here please?

This is eval not seeing local bindings. There is a workaround:

(defmacro eval-with-local-vars [vars sexp]
 (let [quoted-vars (vec (map #(list 'quote %) vars))]
   `(let [varvals# (vec (interleave ~quoted-vars ~vars))]
  (eval (list 'clojure.core/let varvals# ~sexp)

user=> (let [a 1 b 2] (eval-with-local-vars [a b] '(+ a b)))
3
user=> (def state {:status "foo"})
#'user/state
user=> (def rule
 '(if (= (:status state) "foo")
(println "foo")
(println "bar")))
#'user/rule
user=> (let [state {:status "bar"}]
 (eval rule))
foo
nil
user=> (let [state {:status "bar"}]
 (eval-with-local-vars [state] rule))
bar
nil

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

2010-11-27 Thread Eduardo Julian
You might wanna check out the post I recently made and the answer by
Ken Wesson: 
http://groups.google.com/group/clojure/browse_thread/thread/9b042a2ddb8017aa
It's basically the same thing.

-- 
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: Ring startup processing?

2010-11-27 Thread Alex Osborne
Mike Meyer  writes:

> My simple web app
> (http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has
> some stuff that needs to happen just once (in this case, opening the
> serial port). It's not clear how to get this to happen using ring. If
> I do it inside my ring handler, then it gets run on every request, and
> I have to check to make sure it's not run multiple times.

I would just open it lazily on the first request.  That gives you a nice
place to gracefully retry on error as well, instead of being dead until
the entire servlet container is restarted.  As a sysadmin I really hate
apps that can get stuck in a error state and need restarting. ;-)

For example you could be using a USB to Serial adapter, which somebody
might have temporarily removed and plugged in later.  Similarly if
you're opening a database connection on startup and there's a network
dropout, or perhaps your app got started before the database server
did...

> If I run it outside the handler, then it gets run when I do "lein
> uberwar", which is simply wrong.

If you really want to do it at load time you can avoid executing
something at compile time by wrapping it in this:

(when-not *compile-files*
  ...)

-- 
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 At True Values Of Predicate

2010-11-27 Thread Benny Tsai
That's what I get for coding without taking my afternoon nap :)

Try 3.  Tweaked 'subsequence' and 'split-when' so that it is no longer
necessary to calculate the index for the end of the collection.  Also
added a check to 'split-when' to return an empty list when called on
an empty collection; otherwise it would return (()), which seemed like
a strange result.

(use '[clojure.contrib.seq :only (indexed)])

(defn index-filter [pred coll]
  (when pred
(for [[idx elt] (indexed coll) :when (pred elt)] idx)))

(defn subsequence
  ([coll start]
 (drop start coll))
  ([coll start end]
 (take (- end start) (drop start coll

(defn split-when [pred coll]
  (if (empty? coll)
'()
(let [indices (distinct (conj (index-filter pred coll) 0))
  index-groups (partition-all 2 1 indices)]
  (map #(apply subsequence coll %) index-groups

On Nov 27, 7:26 pm, Ken Wesson  wrote:
> On Sat, Nov 27, 2010 at 8:35 PM, Benny Tsai  wrote:
> > Here's a fixed version that...
>
> > 1. Is lazy everywhere.
> > 2. No longer loses elements :)
>
> ...
>
> > (defn split-when [pred coll]
> >  (let [coll-end (count coll)
>
> Er, did you just say "is lazy everywhere"? :)

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

2010-11-27 Thread Andreas Kostler
Hi all,
Sorry for my noob question (again). I'm trying to understand clojures
binding model.
Typing:
(def state {:status "foo"})
(def rule '(if (= (:status sate) "foo") (println "foo") (println
("bar")))

(defn fn []
  (let [state {:status "bar"}]
(eval rule)))

This prints "foo". However, I would have expected the binding of state
created by let would shadow the global binding of state.
Now

(defn fn1 []
  (binding [state {:status "bar"}]
(eval rule)))
Does the right thing. Can someone explain what's going on here please?

Kind Regards
Andreas

-- 
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: Symbol evaluation error in let

2010-11-27 Thread Ken Wesson
Caveat: since eval-with-local-vars is a macro you won't be able to
directly use it in HOFs. Wrapping it in a closure works, however:

user=> (let [a 1 b 2] (map #(eval-with-local-vars [a b] %) ['(+ a b) '(* a b)]))
(3 2)

-- 
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 At True Values Of Predicate

2010-11-27 Thread Ken Wesson
On Sat, Nov 27, 2010 at 8:35 PM, Benny Tsai  wrote:
> Here's a fixed version that...
>
> 1. Is lazy everywhere.
> 2. No longer loses elements :)

...

> (defn split-when [pred coll]
>  (let [coll-end (count coll)

Er, did you just say "is lazy everywhere"? :)

-- 
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: Ring startup processing?

2010-11-27 Thread Ken Wesson
On Sat, Nov 27, 2010 at 9:19 PM, Ken Wesson  wrote:
> On Sat, Nov 27, 2010 at 7:50 PM, Mike Meyer
>  wrote:
>> My simple web app
>> (http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has
>> some stuff that needs to happen just once (in this case, opening the
>> serial port). It's not clear how to get this to happen using ring. If
>> I do it inside my ring handler, then it gets run on every request, and
>> I have to check to make sure it's not run multiple times. If I run it
>> outside the handler, then it gets run when I do "lein uberwar", which
>> is simply wrong.
>>
>> When the deployment platform activates the war would seem to be the
>> right time to run this ("war load time"?). So maybe this is a question
>> that depends on the deployment platform, or war? However, a quick
>> google search didn't turn up anything that looked interesting.
>>
>> Anyone got suggestions on how to set up code to be run when Jetty (or
>> tomcat, or ...)?
>
> If it were an ordinary application, -main would be the obvious place
> (or some module-init function eventually called from there). In this
> case, though, I think your best bet may actually be a Java
> lazily-initialized singleton that you access from Clojure, if
> performance is an issue, or else the Clojure equivalent:
>
> (defmacro defsingleton [name init-sexp]
>  `(def ~name
>     (let [singleton-uninitialized# (Object.)
>           a# (atom singleton-uninitialized#)]
>       (fn []
>         (let [x# @a#]
>           (if (= x# singleton-uninitialized#)
>             (do
>               (reset! a# ~init-sexp)
>               @a#)
>             x#))
>
> user=> (defsingleton foo (do (println "foo initialized") 7))
> #'user/foo
> user=> (foo)
> foo initialized
> 7
> user=> (foo)
> 7
>
> You can also abuse futures:
>
> user=> (def foo (future (do (println "foo initialized") 7)))
> #'user/foo
> user=> @foo
> foo initialized
> 7
> user=> @foo
> 7
>
> or delay/force, or even lazy-seq:
>
> user=> (def foo (drop 1 (take 2 (iterate (fn [_] (do (println "foo
> initialized") 7)) nil
> #'user/foo
> user=> (first foo)
> foo initialized
> 7
> user=> (first foo)
> 7

Or memoize:

user=> (defn foo [] (do (println "foo initialized") 7))
#'user/foo
user=> (def foo (memoize foo))
#'user/foo
user=> (foo)
foo initialized
7
user=> (foo)
7

which actually is fairly close to what the defsingleton macro does.

-- 
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: Ring startup processing?

2010-11-27 Thread lprefontaine
Hi,

Normally this is done use an initialization servlet.
You need a separate class inheriting javax.servlet.http.HttpServlet
and a entry in your web.xml file to get it executed once at application
startup.

Look at load-on-startup here:
http://www.caucho.com/resin-3.0/servlet/servlet.xtp#load-on-startup

I'm two inches from implementing this in our medical record viewer
which uses Compojure and Ring, I have the same issue.
I will no have it done before next Tuesday however, I have some higher priority
stuff to deliver first.

Hope it helps you

Mike Meyer  wrote ..
> My simple web app
> (http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has
> some stuff that needs to happen just once (in this case, opening the
> serial port). It's not clear how to get this to happen using ring. If
> I do it inside my ring handler, then it gets run on every request, and
> I have to check to make sure it's not run multiple times. If I run it
> outside the handler, then it gets run when I do "lein uberwar", which
> is simply wrong.
> 
> When the deployment platform activates the war would seem to be the
> right time to run this ("war load time"?). So maybe this is a question
> that depends on the deployment platform, or war? However, a quick
> google search didn't turn up anything that looked interesting.
> 
> Anyone got suggestions on how to set up code to be run when Jetty (or
> tomcat, or ...)?
> 
>   thanks,
>-- 
> Mike Meyerhttp://www.mired.org/consulting.html
> Independent Network/Unix/Perforce consultant, email for more information.
> 
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
> 
> -- 
> 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
Luc P.


The rabid Muppet

-- 
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: Ring startup processing?

2010-11-27 Thread Ken Wesson
On Sat, Nov 27, 2010 at 7:50 PM, Mike Meyer
 wrote:
> My simple web app
> (http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has
> some stuff that needs to happen just once (in this case, opening the
> serial port). It's not clear how to get this to happen using ring. If
> I do it inside my ring handler, then it gets run on every request, and
> I have to check to make sure it's not run multiple times. If I run it
> outside the handler, then it gets run when I do "lein uberwar", which
> is simply wrong.
>
> When the deployment platform activates the war would seem to be the
> right time to run this ("war load time"?). So maybe this is a question
> that depends on the deployment platform, or war? However, a quick
> google search didn't turn up anything that looked interesting.
>
> Anyone got suggestions on how to set up code to be run when Jetty (or
> tomcat, or ...)?

If it were an ordinary application, -main would be the obvious place
(or some module-init function eventually called from there). In this
case, though, I think your best bet may actually be a Java
lazily-initialized singleton that you access from Clojure, if
performance is an issue, or else the Clojure equivalent:

(defmacro defsingleton [name init-sexp]
  `(def ~name
 (let [singleton-uninitialized# (Object.)
   a# (atom singleton-uninitialized#)]
   (fn []
 (let [x# @a#]
   (if (= x# singleton-uninitialized#)
 (do
   (reset! a# ~init-sexp)
   @a#)
 x#))

user=> (defsingleton foo (do (println "foo initialized") 7))
#'user/foo
user=> (foo)
foo initialized
7
user=> (foo)
7

You can also abuse futures:

user=> (def foo (future (do (println "foo initialized") 7)))
#'user/foo
user=> @foo
foo initialized
7
user=> @foo
7

or delay/force, or even lazy-seq:

user=> (def foo (drop 1 (take 2 (iterate (fn [_] (do (println "foo
initialized") 7)) nil
#'user/foo
user=> (first foo)
foo initialized
7
user=> (first foo)
7

-- 
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 At True Values Of Predicate

2010-11-27 Thread Benny Tsai
If you don't mind, I would love to see your version with lazy-seq and
recursion.  Seems like that's the idiomatic way of solving problems
like this, judging by the source for the partition functions.

On Nov 27, 10:02 am, Asim Jalis  wrote:
> I want to partition a sequence based on the values of a predicate so
> that every true starts a new sequence in the partition. Here is an
> example of how partition-with could be used:
>
> (partition-when true? '(true false false true false true true))
>   -> '((true false false) (true false) (true) (true))
>
> I have written this lazy-seq and recursion. However, I was wondering
> if there is a way to do this with core Clojure sequence primitives.
> Any suggestions?
>
> Asim
> --
> San Francisco, 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: Partition At True Values Of Predicate

2010-11-27 Thread Benny Tsai
I really dig the succinctness of your folding solutions.

On Nov 27, 5:52 pm, rob levy  wrote:
> fwiw my folding solution above yields the expected result.
>
>
>
>
>
>
>
> On Sat, Nov 27, 2010 at 7:07 PM, Benny Tsai  wrote:
> > > Subvec, however, isn't lazy.
>
> > That's true.  I just realized there's another problem with my approach
> > as well: it does not preserve elements before the first true index.
>
> > user=> (partition-when true? [false true])
> > ([true])
>
> > When the result should probably be:
>
> > user=> (partition-when true? [false true])
> > ((false) (true))
>
> > On Nov 27, 2:05 pm, Ken Wesson  wrote:
> > > Subvec, however, isn't lazy. This is:
>
> > > (defn split-when [pred coll]
> > >   (let [ipred (complement pred)
> > >         bits (iterate
> > >                (fn [[out coll]]
> > >                  (let [[a b] (split-with ipred (rest coll))]
> > >                    [(cons (first coll) a) b]))
> > >                [nil coll])]
> > >     (map #(first (first %))
> > >       (take-while #(seq (second (second %))) (map vector (rest bits)
> > bits)
>
> > > user=> (take 10 (split-when #(= 0 (rem % 3)) (iterate inc 1)))
> > > ((1 2)
> > >  (3 4 5)
> > >  (6 7 8)
> > >  (9 10 11)
> > >  (12 13 14)
> > >  (15 16 17)
> > >  (18 19 20)
> > >  (21 22 23)
> > >  (24 25 26)
> > >  (27 28 29))
>
> > --
> > 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 At True Values Of Predicate

2010-11-27 Thread Benny Tsai
Here's a fixed version that...

1. Is lazy everywhere.
2. No longer loses elements :)

(use '[clojure.contrib.seq :only (indexed)])

(defn index-filter [pred coll]
  (when pred
(for [[idx elt] (indexed coll) :when (pred elt)] idx)))

(defn subsequence [coll start end]
  (take (- end start) (drop start coll)))

(defn split-when [pred coll]
  (let [coll-end (count coll)
indices (distinct (concat [0] (index-filter pred coll) [coll-end]))
index-pairs (partition 2 1 indices)]
(for [[start end] index-pairs] (subsequence coll start end

On Nov 27, 5:07 pm, Benny Tsai  wrote:
> > Subvec, however, isn't lazy.
>
> That's true.  I just realized there's another problem with my approach
> as well: it does not preserve elements before the first true index.
>
> user=> (partition-when true? [false true])
> ([true])
>
> When the result should probably be:
>
> user=> (partition-when true? [false true])
> ((false) (true))
>
> On Nov 27, 2:05 pm, Ken Wesson  wrote:
>
>
>
>
>
>
>
> > Subvec, however, isn't lazy. This is:
>
> > (defn split-when [pred coll]
> >   (let [ipred (complement pred)
> >         bits (iterate
> >                (fn [[out coll]]
> >                  (let [[a b] (split-with ipred (rest coll))]
> >                    [(cons (first coll) a) b]))
> >                [nil coll])]
> >     (map #(first (first %))
> >       (take-while #(seq (second (second %))) (map vector (rest bits) 
> > bits)
>
> > user=> (take 10 (split-when #(= 0 (rem % 3)) (iterate inc 1)))
> > ((1 2)
> >  (3 4 5)
> >  (6 7 8)
> >  (9 10 11)
> >  (12 13 14)
> >  (15 16 17)
> >  (18 19 20)
> >  (21 22 23)
> >  (24 25 26)
> >  (27 28 29))

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


Can clojure.contrib.fnmap.PersistentFnMap have metadata

2010-11-27 Thread Eduardo Julian
I was trying to use the fnmap API at clojure.contrib for some things
and I needed to add metadata to the function maps but I got this
exception:
java.lang.ClassCastException: clojure.contrib.fnmap.PersistentFnMap
cannot be cast to clojure.lang.IObj

Stuart, can you make PersistentFnMa extend IObject or is it not
possible for some reason?

-- 
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: Symbol evaluation error in let

2010-11-27 Thread Eduardo Julian
Woah. That's as weird as you can get.

Thanks, man.

-- 
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 At True Values Of Predicate

2010-11-27 Thread rob levy
fwiw my folding solution above yields the expected result.

On Sat, Nov 27, 2010 at 7:07 PM, Benny Tsai  wrote:

> > Subvec, however, isn't lazy.
>
> That's true.  I just realized there's another problem with my approach
> as well: it does not preserve elements before the first true index.
>
> user=> (partition-when true? [false true])
> ([true])
>
> When the result should probably be:
>
> user=> (partition-when true? [false true])
> ((false) (true))
>
> On Nov 27, 2:05 pm, Ken Wesson  wrote:
> > Subvec, however, isn't lazy. This is:
> >
> > (defn split-when [pred coll]
> >   (let [ipred (complement pred)
> > bits (iterate
> >(fn [[out coll]]
> >  (let [[a b] (split-with ipred (rest coll))]
> >[(cons (first coll) a) b]))
> >[nil coll])]
> > (map #(first (first %))
> >   (take-while #(seq (second (second %))) (map vector (rest bits)
> bits)
> >
> > user=> (take 10 (split-when #(= 0 (rem % 3)) (iterate inc 1)))
> > ((1 2)
> >  (3 4 5)
> >  (6 7 8)
> >  (9 10 11)
> >  (12 13 14)
> >  (15 16 17)
> >  (18 19 20)
> >  (21 22 23)
> >  (24 25 26)
> >  (27 28 29))
>
> --
> 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

Ring startup processing?

2010-11-27 Thread Mike Meyer
My simple web app
(http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has
some stuff that needs to happen just once (in this case, opening the
serial port). It's not clear how to get this to happen using ring. If
I do it inside my ring handler, then it gets run on every request, and
I have to check to make sure it's not run multiple times. If I run it
outside the handler, then it gets run when I do "lein uberwar", which
is simply wrong.

When the deployment platform activates the war would seem to be the
right time to run this ("war load time"?). So maybe this is a question
that depends on the deployment platform, or war? However, a quick
google search didn't turn up anything that looked interesting.

Anyone got suggestions on how to set up code to be run when Jetty (or
tomcat, or ...)?

thanks,
 http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
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: Durable Clojure - Functions and Closures

2010-11-27 Thread Ken Wesson
On Sat, Nov 27, 2010 at 1:10 PM, Mark  wrote:
> Hi -
>
> I'm surprised your work doesn't generate more interest from folks.  I
> wish I had more time, I would definitely jump in and help.

Persistence doesn't seem to generate much interest in general. I
posted my own stab at a way of persisting the ref world
near-transparently a few weeks ago and it sank without a ripple.

-- 
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: Exporting FatJar from Eclipse CCW does not work

2010-11-27 Thread Arie van Wingerden
Hi Gijs,

it wasn't a typo, but lack of knowledge :-)
Indeed this is the solution.

Thanks for your help!

Regards,
   Arie

2010/11/27 Gijs S. 

> Hi,
>
> Perhaps it is a typo but you should have
>
> (defn -main [] ...) rather than (defn- main [] ...)
>
> Note the place of the dash "-".
>
> defn- yields a non public var (a private declaration)
> (http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/
> defn-)
>
> -main uses the dash, which is the default :prefix "-" for method
> lookup in a class
> (http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/
> gen-class)
>
> Cheers,
> 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

-- 
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: Use of nested class to acces an enum

2010-11-27 Thread benjiiiiii
Thanks for you help.

I was missing sonthing, in fact the class day wasn't where i expected
it to be.


And in addintion i have to say:
Once the importe is done using :
(ns org.codingkata.unit.MyKata
  (:import org.codingkata.unit.api.BaseKataSolution
   org.codingkata.unit.api.BaseKataSolution$Day))
we can call Day class using it's "real" name :BaseKataSolution$Day)



On 26 nov, 23:50, Alex Osborne  wrote:
> Alex Osborne  writes:
> >benjii writes:
>
> >> (ns org.codingkata.unit.MyKata
> >>   (:import (org.codingkata.unit.api.BaseKataSolution)
> >>           (org.codingkata.unit.api.BaseKataSolution$Day))
> >>   (:gen-class
> >>    :extends org.codingkata.unit.api.BaseKataSolution))
>
> >> This compile, but then i can't acces to Day neither BasKataSolution
> >> $Day.
>
> > Strange. After (:import org.codingkata.unit.api.BaseKataSolution$Day)
> > you should be able to use BaseKataSolution$Day.
>
> Ah.  Actually I just noticed you've got an extra pair of parens around
> your imports.  Do it either this way:
>
> (ns org.codingkata.unit.MyKata
>   (:import org.codingkata.unit.api.BaseKataSolution
>            org.codingkata.unit.api.BaseKataSolution$Day))
>
> Or this way:
>
> (ns org.codingkata.unit.MyKata
>   (:import (org.codingkata.unit.api BaseKataSolution
>                                     BaseKataSolution$Day)))
>
> The extra parens mean a prefix, like in the second example.
>
> (:import (foo bar baz)) means import both foo.bar and foo.baz
>
> While (:import (foo)) is meaningless, it doesn't do anything.

-- 
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: Durable Clojure - Functions and Closures

2010-11-27 Thread Mark
Hi -

I'm surprised your work doesn't generate more interest from folks.  I
wish I had more time, I would definitely jump in and help.

On Nov 24, 3:37 pm, Alyssa Kwan  wrote:
> Extension 
> ofhttp://groups.google.com/group/clojure/browse_thread/thread/7c917e983...
>
> Hi everyone!
>
> I've extended the Clojure core to extend durability to functions and
> closures.
>
> 1. Functions with lexical and dynamic bindings are now supported. This
> includes functions that generate functions.
> 1.a. There is a slight overhead applied to all compiled functions; the
> bytecode is inaccessible at runtime except through a cache which
> maintains an entry for all classes regardless of whether they are
> eventually persisted or not. This doubles memory required per class,
> but should, in practice, be negligible.
> 2. Identities of identities are now supported. This means that
> persistent data structures of identities can be saved, i.e. you can
> have a ref of a hash-map of refs.
> 3. sorted-map and sorted-set are now supported.
>
> Get it here:  git://github.com/kwanalyssa/clojure.git
>
> More testing, especially performance testing, is very welcome.
> However, at this point, I've satisfied my own requirements. I'd love
> to get this in scope eventually for enhancing Clojure core, if pain-
> free persistence is part of the grand vision. Discussion of API and
> implementation is also welcome.
>
> Thanks!
> Alyssa Kwan

-- 
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: Why isn't there a fold-right?

2010-11-27 Thread tpeng
thanks Alex for this nice foldr. ;-)

however this lazy-foldr can only be used when the fn can stop by
itself (in this case, it's 'and' which is short-circuited)  otherwise
lazy-foldr will never get stop.
i think for a good foldr, the evaluation of #(lazy-foldr f val xs)
should be only forced when necessary?

On Nov 27, 6:44 pm, Alex Osborne  wrote:
> "nicolas.o...@gmail.com"  writes:
> > I doubt there is a foldr that handles the infinite list.
> > To do anything, it would have to read at least one element: the last.
>
> > Alex nice answer is a foldl.
>
> Actually I think you have them backwards.  Wikipedia has a pair of
> diagrams which I find very useful for visualising which is which:
>
> foldr:http://en.wikipedia.org/wiki/File:Right-fold-transformation.png
>
> foldl (reduce in 
> Clojure):http://en.wikipedia.org/wiki/File:Left-fold-transformation.png
>
> Look at the right side of the diagram.  That's the call structure.  (The
> left side of the diagram is the linked list (1 2 3 4 5).  The ":" just
> means cons in Haskell syntax.)
>
> With a foldr the outermost call is given the first element of the list,
> so mine is definitely a foldr.
>
> Let's use (and) as the combining function and use an infinite list that
> begins [true true false false ...].  So that looks like:
>
> (lazy-foldr #(and %1 (%2)) nil (cycle [true true false false]))
>
> We can draw an ASCII call structure diagram in the same form as the
> Wikipedia one and see this:
>
>       and
>       / \
>      T  and
>         / \
>        T  and
>           / \
>          F   (not evaluated)
>
> Since (and) short-circuits when given false, only the part of the list
> up to the first false is evaluated.
>
> There's probably not much practical use for lazy-foldr.  But it was fun
> to write. :-)

-- 
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 At True Values Of Predicate

2010-11-27 Thread Benny Tsai
> Subvec, however, isn't lazy.

That's true.  I just realized there's another problem with my approach
as well: it does not preserve elements before the first true index.

user=> (partition-when true? [false true])
([true])

When the result should probably be:

user=> (partition-when true? [false true])
((false) (true))

On Nov 27, 2:05 pm, Ken Wesson  wrote:
> Subvec, however, isn't lazy. This is:
>
> (defn split-when [pred coll]
>   (let [ipred (complement pred)
>         bits (iterate
>                (fn [[out coll]]
>                  (let [[a b] (split-with ipred (rest coll))]
>                    [(cons (first coll) a) b]))
>                [nil coll])]
>     (map #(first (first %))
>       (take-while #(seq (second (second %))) (map vector (rest bits) bits)
>
> user=> (take 10 (split-when #(= 0 (rem % 3)) (iterate inc 1)))
> ((1 2)
>  (3 4 5)
>  (6 7 8)
>  (9 10 11)
>  (12 13 14)
>  (15 16 17)
>  (18 19 20)
>  (21 22 23)
>  (24 25 26)
>  (27 28 29))

-- 
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: Autodoc dependencies broken?

2010-11-27 Thread Rayne
If it's helpful, I have a snapshot of autodoc 0.8.0 on clojars that
I'm using in cake-autodoc: http://clojars.org/org.clojars.rayne/autodoc

On Nov 26, 9:21 pm, James Reeves  wrote:
> I've investigated this a little further, and it looks like I was
> misinterpreting the dependency error messages.
>
> 0.8.0-SNAPSHOT doesn't work because it hasn't been uploaded to Clojars.
>
> 0.7.1 doesn't work because it references clojure-contrib
> 1.1.0-master-SNAPSHOT, and clojure 1.3.0-alpha3, the latter via
> Enlive, which seems to always reference the latest version, stable or
> not.
>
> But I'm not sure with 1.3.0-alpha3 would fail, because as far as I can
> tell it's in the Clojure repository. I'll investigate further
> tomorrow.
>
> - James
>
> On 27 November 2010 02:17, Tom Faulhaber  wrote:
>
>
>
> > James,
>
> > I don't know why this would be true, but something may have broken in
> > the underlying dependency chains. Autodoc hasn't been updated in
> > clojars for a very long time and does not directly depend on super-
> > pom.jar.
>
> > Are you using autodoc standalone or as a lein plugin?
>
> > Tom
>
> > On Nov 26, 1:09 pm, James Reeves  wrote:
> >> I've just tried installing autodoc 1.7.1 and 0.8.0-SNAPSHOT via
> >> Leiningen and Clojars, and it seems to be missing some dependencies
> >> (specifically org.apache.maven:super-pom:jar:2.0).
>
> >> Has anyone else had this problem recently?
>
> >> - James
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > 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


New installation for Emacs clojure-mode, etc.

2010-11-27 Thread Phil Hagelberg

One of the biggest frustrations in maintaining the Emacs libraries for
Clojure has been the fact that ELPA, the original package archive for
Emacs, is manually curated, so updates can take a very long time to
propagate. In Emacs 24 (currently under development), they have bundled
the package.el package manager with enhancements that allow it to read
from multiple archive sources. This allows Elisp maintainers to keep
their own package sources in a decentralized manner on their own terms
rather than submitting everything to the official GNU sources or the
original ELPA archive.

My personal package archive at http://repo.technomancy.us/emacs/ now has
a new clojure-mode, clojure-test-mode, and paredit. It also has durendal
and a version of slime that has the version mismatch fix in place.

If you want to stay on stable Emacs, you can get the latest package.el
straight out of Emacs trunk; (http://bit.ly/pkg-el) I've done some
testing that indicates it should work fine on 23. Note that it now comes
configured with only the FSF repo out of the box, and since it doesn't
host non-GNU projects it only has six or so packages. You have to add
other archives like ELPA or my own before it's useful.

tl;dr: you'll get more up-to-date versions of clojure-mode, slime,
etc. if you use Emacs 24 with my personal package archive:

(add-to-list 'package-archives
 '("technomancy" . "http://repo.technomancy.us/emacs/";) t)

Let me know if you run into problems.

-Phil

-- 
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: Symbol evaluation error in let

2010-11-27 Thread Ken Wesson
On Sat, Nov 27, 2010 at 4:31 PM, Ken Wesson  wrote:
> On Sat, Nov 27, 2010 at 10:45 AM, Eduardo Julian  wrote:
>> user=> (let [a 'b] (str a))
>> "b"
>> user=> (let [b 5 a 'b] (eval a))
>> java.lang.Exception: Unable to resolve symbol: b in this context
>> (repl-1:7)
>> user=> (let [a 'b b 5] (eval a))
>> java.lang.Exception: Unable to resolve symbol: b in this context
>> (repl-1:9)
>>
>> user=> (def b 5)
>> #'user/b
>> user=> (def a 'b)
>> #'user/a
>> user=> a
>> b
>> userr=> (eval a)
>> 5
>>
>> How come this problem happens inside the let but not with def?
>
> If you
>
> (do
>  (binding [*ns* (find-ns 'foo)]
>    (eval bar)))
>
> the evaluation of bar sees the global bindings in the namespace foo,
> and can get at other global bindings and Java classes with
> fully-qualified names, but cannot see the lexical environment around
> the eval call. Even when called inside a let or a function body,
> eval's contents only see what they would see if executed at the top
> level of the source file for the namespace that is *current when eval
> is called* (not necessarily the same file the eval itself is in).

Adding to this, you can work around it with

(defmacro eval-with-local-vars [vars sexp]
  (let [quoted-vars (vec (map #(list 'quote %) vars))]
`(let [varvals# (vec (interleave ~quoted-vars ~vars))]
   (eval (list 'clojure.core/let varvals# ~sexp)

user=> (let [a 1 b 2] (eval-with-local-vars [a b] '(+ a b)))
3

user=> (let [b 5 a 'b] (eval-with-local-vars [b a] a))
5

Note that the vars have to be in the correct order in the vector:

user=> (let [b 5 a 'b] (eval-with-local-vars [a b] a))
#

-- 
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 At True Values Of Predicate

2010-11-27 Thread rob levy
This is clearer to read though:

(defn partition-when [f l]
  (reduce #(if (f %2)
 (conj %1 (vector %2))
 (conj (vec (butlast %1))
   (conj (vec (last %1)) %2)))
  [] (vec l)))

On Sat, Nov 27, 2010 at 4:47 PM, rob levy  wrote:

> This is more correct, because conj does not preserve the order correctly.
>  I wonder if there is a more idiomatic way to cons things onto the end of
> the list.
>
>
> (defn partition-when [f l]
>   (reduce #(if (f %2)
>  (concat %1 (vector (vector %2)))
>  (concat (butlast %1)
>  (vector (concat (last %1) (vector %2)
>   [] l))
>
>
> On Sat, Nov 27, 2010 at 4:18 PM, rob levy  wrote:
>
>> Something like this?
>>
>> (defn partition-when [f l]
>>   (reduce #(if (f %2)
>>  (conj %1 (vector %2))
>>  (conj (butlast %1)
>>(conj (last %1) %2)))
>>   [] l))
>>
>> On Sat, Nov 27, 2010 at 4:15 PM, Ken Wesson  wrote:
>>
>>> On Sat, Nov 27, 2010 at 4:00 PM, rob levy  wrote:
>>> > partition-by does exactly what you need.
>>>
>>> Not quite.
>>>
>>> user=> (take 10 (partition-by #(= 0 (rem % 3)) (iterate inc 1)))
>>> ((1 2)
>>>  (3)
>>>  (4 5)
>>>  (6)
>>>  (7 8)
>>>  (9)
>>>  (10 11)
>>>  (12)
>>>  (13 14)
>>>  (15))
>>>
>>> At first it seems you can fix this as follows:
>>>
>>> user=> (defn questionable-split-when [pred coll]
>>> (let [p (partition-by pred coll)]
>>>   (cons (first p) (map #(apply concat %) (partition 2 2 []
>>> (rest p))
>>> #'user/questionable-split-when
>>> user=> (take 10 (questionable-split-when #(= 0 (rem % 3)) (iterate inc
>>> 1)))
>>> ((1 2)
>>>  (3 4 5)
>>>  (6 7 8)
>>>  (9 10 11)
>>>  (12 13 14)
>>>  (15 16 17)
>>>  (18 19 20)
>>>  (21 22 23)
>>>  (24 25 26)
>>>  (27 28 29))
>>>
>>> So far, so good. But:
>>>
>>> user=> (questionable-split-when #(= 0 (rem % 3)) [1 2 3 6 7 8 9])
>>> ((1 2)
>>>  (3 6 7 8)
>>>  (9))
>>>
>>> Whereas:
>>>
>>> user=> (split-when #(= 0 (rem % 3)) [1 2 3 6 7 8 9])
>>> ((1 2)
>>>  (3)
>>>  (6 7 8)
>>>  (9))
>>>
>>> The latter correctly starts a new partition each time the pred is
>>> true; the former fails if the pred is ever true twice in a row.
>>>
>>> --
>>> 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 At True Values Of Predicate

2010-11-27 Thread rob levy
This is more correct, because conj does not preserve the order correctly.  I
wonder if there is a more idiomatic way to cons things onto the end of the
list.


(defn partition-when [f l]
  (reduce #(if (f %2)
 (concat %1 (vector (vector %2)))
 (concat (butlast %1)
 (vector (concat (last %1) (vector %2)
  [] l))


On Sat, Nov 27, 2010 at 4:18 PM, rob levy  wrote:

> Something like this?
>
> (defn partition-when [f l]
>   (reduce #(if (f %2)
>  (conj %1 (vector %2))
>  (conj (butlast %1)
>(conj (last %1) %2)))
>   [] l))
>
> On Sat, Nov 27, 2010 at 4:15 PM, Ken Wesson  wrote:
>
>> On Sat, Nov 27, 2010 at 4:00 PM, rob levy  wrote:
>> > partition-by does exactly what you need.
>>
>> Not quite.
>>
>> user=> (take 10 (partition-by #(= 0 (rem % 3)) (iterate inc 1)))
>> ((1 2)
>>  (3)
>>  (4 5)
>>  (6)
>>  (7 8)
>>  (9)
>>  (10 11)
>>  (12)
>>  (13 14)
>>  (15))
>>
>> At first it seems you can fix this as follows:
>>
>> user=> (defn questionable-split-when [pred coll]
>> (let [p (partition-by pred coll)]
>>   (cons (first p) (map #(apply concat %) (partition 2 2 []
>> (rest p))
>> #'user/questionable-split-when
>> user=> (take 10 (questionable-split-when #(= 0 (rem % 3)) (iterate inc
>> 1)))
>> ((1 2)
>>  (3 4 5)
>>  (6 7 8)
>>  (9 10 11)
>>  (12 13 14)
>>  (15 16 17)
>>  (18 19 20)
>>  (21 22 23)
>>  (24 25 26)
>>  (27 28 29))
>>
>> So far, so good. But:
>>
>> user=> (questionable-split-when #(= 0 (rem % 3)) [1 2 3 6 7 8 9])
>> ((1 2)
>>  (3 6 7 8)
>>  (9))
>>
>> Whereas:
>>
>> user=> (split-when #(= 0 (rem % 3)) [1 2 3 6 7 8 9])
>> ((1 2)
>>  (3)
>>  (6 7 8)
>>  (9))
>>
>> The latter correctly starts a new partition each time the pred is
>> true; the former fails if the pred is ever true twice in a row.
>>
>> --
>> 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: Symbol evaluation error in let

2010-11-27 Thread Ken Wesson
On Sat, Nov 27, 2010 at 10:45 AM, Eduardo Julian  wrote:
> user=> (let [a 'b] (str a))
> "b"
> user=> (let [b 5 a 'b] (eval a))
> java.lang.Exception: Unable to resolve symbol: b in this context
> (repl-1:7)
> user=> (let [a 'b b 5] (eval a))
> java.lang.Exception: Unable to resolve symbol: b in this context
> (repl-1:9)
>
> user=> (def b 5)
> #'user/b
> user=> (def a 'b)
> #'user/a
> user=> a
> b
> userr=> (eval a)
> 5
>
> How come this problem happens inside the let but not with def?

If you

(do
  (binding [*ns* (find-ns 'foo)]
(eval bar)))

the evaluation of bar sees the global bindings in the namespace foo,
and can get at other global bindings and Java classes with
fully-qualified names, but cannot see the lexical environment around
the eval call. Even when called inside a let or a function body,
eval's contents only see what they would see if executed at the top
level of the source file for the namespace that is *current when eval
is called* (not necessarily the same file the eval itself is in).

-- 
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 At True Values Of Predicate

2010-11-27 Thread rob levy
Something like this?

(defn partition-when [f l]
  (reduce #(if (f %2)
 (conj %1 (vector %2))
 (conj (butlast %1)
   (conj (last %1) %2)))
  [] l))

On Sat, Nov 27, 2010 at 4:15 PM, Ken Wesson  wrote:

> On Sat, Nov 27, 2010 at 4:00 PM, rob levy  wrote:
> > partition-by does exactly what you need.
>
> Not quite.
>
> user=> (take 10 (partition-by #(= 0 (rem % 3)) (iterate inc 1)))
> ((1 2)
>  (3)
>  (4 5)
>  (6)
>  (7 8)
>  (9)
>  (10 11)
>  (12)
>  (13 14)
>  (15))
>
> At first it seems you can fix this as follows:
>
> user=> (defn questionable-split-when [pred coll]
> (let [p (partition-by pred coll)]
>   (cons (first p) (map #(apply concat %) (partition 2 2 []
> (rest p))
> #'user/questionable-split-when
> user=> (take 10 (questionable-split-when #(= 0 (rem % 3)) (iterate inc 1)))
> ((1 2)
>  (3 4 5)
>  (6 7 8)
>  (9 10 11)
>  (12 13 14)
>  (15 16 17)
>  (18 19 20)
>  (21 22 23)
>  (24 25 26)
>  (27 28 29))
>
> So far, so good. But:
>
> user=> (questionable-split-when #(= 0 (rem % 3)) [1 2 3 6 7 8 9])
> ((1 2)
>  (3 6 7 8)
>  (9))
>
> Whereas:
>
> user=> (split-when #(= 0 (rem % 3)) [1 2 3 6 7 8 9])
> ((1 2)
>  (3)
>  (6 7 8)
>  (9))
>
> The latter correctly starts a new partition each time the pred is
> true; the former fails if the pred is ever true twice in a row.
>
> --
> 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 At True Values Of Predicate

2010-11-27 Thread Ken Wesson
On Sat, Nov 27, 2010 at 4:00 PM, rob levy  wrote:
> partition-by does exactly what you need.

Not quite.

user=> (take 10 (partition-by #(= 0 (rem % 3)) (iterate inc 1)))
((1 2)
 (3)
 (4 5)
 (6)
 (7 8)
 (9)
 (10 11)
 (12)
 (13 14)
 (15))

At first it seems you can fix this as follows:

user=> (defn questionable-split-when [pred coll]
 (let [p (partition-by pred coll)]
   (cons (first p) (map #(apply concat %) (partition 2 2 []
(rest p))
#'user/questionable-split-when
user=> (take 10 (questionable-split-when #(= 0 (rem % 3)) (iterate inc 1)))
((1 2)
 (3 4 5)
 (6 7 8)
 (9 10 11)
 (12 13 14)
 (15 16 17)
 (18 19 20)
 (21 22 23)
 (24 25 26)
 (27 28 29))

So far, so good. But:

user=> (questionable-split-when #(= 0 (rem % 3)) [1 2 3 6 7 8 9])
((1 2)
 (3 6 7 8)
 (9))

Whereas:

user=> (split-when #(= 0 (rem % 3)) [1 2 3 6 7 8 9])
((1 2)
 (3)
 (6 7 8)
 (9))

The latter correctly starts a new partition each time the pred is
true; the former fails if the pred is ever true twice in a row.

-- 
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 At True Values Of Predicate

2010-11-27 Thread Laurent PETIT
2010/11/27 rob levy 

> partition-by does exactly what you need.


Nope.

partition-by will split each time the value changes. Not each time a
particular value is seen.


>
>
> On Sat, Nov 27, 2010 at 3:04 PM, Benny Tsai  wrote:
>
>> Could do it this way.  Use index-filter (borrowed from Programming
>> Clojure) to get the indices where the predicate is true in the
>> sequence.  partition-when-true then just calls subvec with pairs of
>> indices to get the subsequences.
>>
>> coll-end is the index just past the end of the collection.  This is
>> used as a pad element so that the last true index is included in the
>> pairs, and also accounts for the case where there is only a single
>> true index.
>>
>> (use '[clojure.contrib.seq :only (indexed)])
>>
>> (defn index-filter [pred coll]
>>  (when pred
>>(for [[idx elt] (indexed coll) :when (pred elt)] idx)))
>>
>> (defn partition-when [pred coll]
>>  (let [coll-end (count coll)
>>indices (index-filter pred coll)
>>index-pairs (partition 2 1 [coll-end] indices)
>>coll-vec (vec coll)]
>>(for [[start end] index-pairs] (subvec coll-vec start end
>>
>> user=> (partition-when true? '(true false false true false true true))
>> ([true false false] [true false] [true] [true])
>>
>> On Nov 27, 10:02 am, Asim Jalis  wrote:
>> > I want to partition a sequence based on the values of a predicate so
>> > that every true starts a new sequence in the partition. Here is an
>> > example of how partition-with could be used:
>> >
>> > (partition-when true? '(true false false true false true true))
>> >   -> '((true false false) (true false) (true) (true))
>> >
>> > I have written this lazy-seq and recursion. However, I was wondering
>> > if there is a way to do this with core Clojure sequence primitives.
>> > Any suggestions?
>> >
>> > Asim
>> > --
>> > San Francisco, 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
>>
>
>  --
> 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 At True Values Of Predicate

2010-11-27 Thread Ken Wesson
Subvec, however, isn't lazy. This is:

(defn split-when [pred coll]
  (let [ipred (complement pred)
bits (iterate
   (fn [[out coll]]
 (let [[a b] (split-with ipred (rest coll))]
   [(cons (first coll) a) b]))
   [nil coll])]
(map #(first (first %))
  (take-while #(seq (second (second %))) (map vector (rest bits) bits)

user=> (take 10 (split-when #(= 0 (rem % 3)) (iterate inc 1)))
((1 2)
 (3 4 5)
 (6 7 8)
 (9 10 11)
 (12 13 14)
 (15 16 17)
 (18 19 20)
 (21 22 23)
 (24 25 26)
 (27 28 29))

-- 
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 At True Values Of Predicate

2010-11-27 Thread rob levy
partition-by does exactly what you need.

On Sat, Nov 27, 2010 at 3:04 PM, Benny Tsai  wrote:

> Could do it this way.  Use index-filter (borrowed from Programming
> Clojure) to get the indices where the predicate is true in the
> sequence.  partition-when-true then just calls subvec with pairs of
> indices to get the subsequences.
>
> coll-end is the index just past the end of the collection.  This is
> used as a pad element so that the last true index is included in the
> pairs, and also accounts for the case where there is only a single
> true index.
>
> (use '[clojure.contrib.seq :only (indexed)])
>
> (defn index-filter [pred coll]
>  (when pred
>(for [[idx elt] (indexed coll) :when (pred elt)] idx)))
>
> (defn partition-when [pred coll]
>  (let [coll-end (count coll)
>indices (index-filter pred coll)
>index-pairs (partition 2 1 [coll-end] indices)
>coll-vec (vec coll)]
>(for [[start end] index-pairs] (subvec coll-vec start end
>
> user=> (partition-when true? '(true false false true false true true))
> ([true false false] [true false] [true] [true])
>
> On Nov 27, 10:02 am, Asim Jalis  wrote:
> > I want to partition a sequence based on the values of a predicate so
> > that every true starts a new sequence in the partition. Here is an
> > example of how partition-with could be used:
> >
> > (partition-when true? '(true false false true false true true))
> >   -> '((true false false) (true false) (true) (true))
> >
> > I have written this lazy-seq and recursion. However, I was wondering
> > if there is a way to do this with core Clojure sequence primitives.
> > Any suggestions?
> >
> > Asim
> > --
> > San Francisco, 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
>

-- 
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 At True Values Of Predicate

2010-11-27 Thread Benny Tsai
Could do it this way.  Use index-filter (borrowed from Programming
Clojure) to get the indices where the predicate is true in the
sequence.  partition-when-true then just calls subvec with pairs of
indices to get the subsequences.

coll-end is the index just past the end of the collection.  This is
used as a pad element so that the last true index is included in the
pairs, and also accounts for the case where there is only a single
true index.

(use '[clojure.contrib.seq :only (indexed)])

(defn index-filter [pred coll]
  (when pred
(for [[idx elt] (indexed coll) :when (pred elt)] idx)))

(defn partition-when [pred coll]
  (let [coll-end (count coll)
indices (index-filter pred coll)
index-pairs (partition 2 1 [coll-end] indices)
coll-vec (vec coll)]
(for [[start end] index-pairs] (subvec coll-vec start end

user=> (partition-when true? '(true false false true false true true))
([true false false] [true false] [true] [true])

On Nov 27, 10:02 am, Asim Jalis  wrote:
> I want to partition a sequence based on the values of a predicate so
> that every true starts a new sequence in the partition. Here is an
> example of how partition-with could be used:
>
> (partition-when true? '(true false false true false true true))
>   -> '((true false false) (true false) (true) (true))
>
> I have written this lazy-seq and recursion. However, I was wondering
> if there is a way to do this with core Clojure sequence primitives.
> Any suggestions?
>
> Asim
> --
> San Francisco, 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: ANN: ClojureQL 1.0.0 finally released as public beta

2010-11-27 Thread Janico Greifenberg
First of all, thank you for this awesome library.

I'm experimenting with ClojureQL for accessing Postgis, the spacial
extender for Postgres. To improve the ClojureQL for this use case, it
would be useful to have a way to add custom predicates. For example to
find all places whose location column intersect with a polygon, you
can use a query like this:

SELECT * FROM place WHERE ST_Intersects(location,
ST_GeographyFromText('SRID=4326;POLYGON((33 38,34 38,34 39,33 39,33
38))'))

It would be nice, if I could write that as

(-> places (select (where (st-intersects :location polygon

Is there a way to do this (or something similar) in ClojureQL or is it
planned for a future version?

Janico

On Thu, Nov 25, 2010 at 7:27 PM, LauJensen  wrote:
> There's some valuable food for thought in this thread.
>
> My major problem with support various backends is the amount of work
> thats involved. Every single backend needs to play nice with all the
> primitives defined in Relational Algebra and that are implemented in
> ClojureQL. I believe that the SQL92 standard takes us very far down
> the middle road, but I realize that it wont take us all the way.
>
> ClojureQL is actually two sets of primitives. Firstly its the RA stuf
> (select, project, join, etc) and then internally there is a number of
> primitives defined which help translate the RTable record into a query
> string. At the highest level only two functions need to be changed in
> order to effectively replace the entire compiler: to-sql and build-
> join. These call each other to build complex queries. If these were
> supplied as plugins, I think most backends could be fully supported
> simply by providing these two methods. They are not trivial however,
> so anybody interested in contributing should check out whats already
> there.
>
> Still thinking this through but the input is appreciated!
>
> Lau
>
> On Nov 25, 6:14 pm, rickmode  wrote:
>> Allowing implementation-specific and optimized SQL only via strings
>> and not via a mechanism within ClojureQL allows its use in specific
>> applications but effectively prevents use for libraries and
>> frameworks. Indirect use of ClojureQL could yield unacceptable
>> performance with no elegant fix.
>>
>> On Nov 24, 11:28 pm, LauJensen  wrote:
>>
>> > Hi Brenton,
>>
>> > Yes the OFFSET/LIMIT syntax differs from backend to backend. However
>> > in some instances (like MySQL/PostgreSQL) they have ensured
>> > compatability so that the same statement will run on several DBs
>> > although the syntax might not be considered 'native'. For something
>> > like Oracle there actually isnt a syntax for LIMIT so instead they do
>> > something like
>>
>> > SELECT * FROM (
>> >   SELECT
>> >     ROW_NUMBER() OVER (ORDER BY key ASC) AS rownumber,
>> >     columns
>> >   FROM tablename
>> > )
>> > WHERE rownumber <= n
>>
>> > But as you can see it would be trivial to express this in terms of
>> > ClojureQL:
>>
>> > (defn oracle-take
>> >   [tname limit]
>> >   (-> (table (str "(SELECT ROW_NUMBER() OVER (ORDER BY key ASC)"
>> >                   " AS rownumber,columns"
>> >                   " FROM " (to-tablename tname) ")"))
>> >       (select (where (<= :rownumber limit)))
>> >       (project ["*"])))
>>
>> > (to-sql (oracle-table :users 10))
>> > ["SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY key ASC) AS
>> > rownumber,columns FROM users) WHERE (rownumber <= ?)" 10]
>>
>> > From the outset it has been my ambition to make ClojureQL extremely
>> > composable and as far as possible allow users to directly insert
>> > strings into the query to allow for backend specific customization.
>> > The entire design-plan of this customization is not yet thought out so
>> > input is welcomed. To me, flexibility and leaving with the power to
>> > the user is the key to wide adoption across various backends.
>>
>> > Lau
>>
>> > On Nov 24, 11:42 pm, Brenton  wrote:
>>
>> > > > ClojureQL does not take the backend in to account. This is the one
>> > > > feature from the old CQL that I didn't want to carry over because it
>> > > > would be impossible for me to cater to all backends. If you hit
>> > > > specific problems, let me know and I'll see what we can do.
>>
>> > > > We adhere to SQL92 and test everything on MySQL and Postgres. If
>> > > > you're in a situation where thats not good enough, its always possible
>> > > > to supply part of your expression as a string.
>>
>> > > Lau
>>
>> > > Off the top of my head, I know that the LIMIT syntax for SQL Server is
>> > > totally different. A lot of the apps that I write end up getting
>> > > deployed using Oracle and SQL Server. If you plan for CQL to be widely
>> > > used I think you will need to take backends into account. You don't
>> > > need to implement them all yourself, but you should provide a way so
>> > > that others can implement them when they need to.
>>
>> > > Brenton
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post

Re: a macro to debug the let form

2010-11-27 Thread Robert McIntyre
cool!  Although I think with-seperator should be spelled "with-separator"

--Robert McIntyre

On Thu, Nov 25, 2010 at 9:13 AM, Sunil S Nandihalli
 wrote:
> I just tried to re-write with-seperator without using the symbol-macros from
> macro-utils and it seems to work fine ..
>
> On Thu, Nov 25, 2010 at 1:27 PM, Sunil S Nandihalli
>  wrote:
>>
>> Hello everybody,
>>  I was trying to learn to write clojure macros and the code is posted here
>> in the following link
>> https://gist.github.com/715047
>> There are basically three macros
>> 1. with-seperator - a zero argument macro and is supposed to just draw a
>> line to indicate beginning and ending of the execution of the body.
>> 2. display-local-bindings - a function to print the local bindings in the
>> lexical scope where the macro is called
>> 3. letd - a helper macro to print the values of all the bindings  followed
>> by printing of the local bindings using display-local-bindings
>> The letd macro as posted works as expected but without the seperation line
>> .  It is supposed to print the seperation line when I uncomment line 14 and
>> comment line 15 but some how this is causing the &env variable automatically
>> passed with every macro to be nil display-local-binding .. but the I feel it
>> is not the case .. can somebody help me understand this. This was an
>> exercise to learn macro writing than to writing a letd debugging helper
>> function..
>> Thanks,
>> Sunil.
>
> --
> 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


Partition At True Values Of Predicate

2010-11-27 Thread Asim Jalis
I want to partition a sequence based on the values of a predicate so
that every true starts a new sequence in the partition. Here is an
example of how partition-with could be used:

(partition-when true? '(true false false true false true true))
  -> '((true false false) (true false) (true) (true))

I have written this lazy-seq and recursion. However, I was wondering
if there is a way to do this with core Clojure sequence primitives.
Any suggestions?

Asim
--
San Francisco, 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


Symbol evaluation error in let

2010-11-27 Thread Eduardo Julian
user=> (let [a 'b] (str a))
"b"
user=> (let [b 5 a 'b] (eval a))
java.lang.Exception: Unable to resolve symbol: b in this context
(repl-1:7)
user=> (let [a 'b b 5] (eval a))
java.lang.Exception: Unable to resolve symbol: b in this context
(repl-1:9)

user=> (def b 5)
#'user/b
user=> (def a 'b)
#'user/a
user=> a
b
userr=> (eval a)
5

How come this problem happens inside the let but not with def?

-- 
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: Wolfram: 100 years since Principia Mathematica

2010-11-27 Thread Alec Battles
> Thought some Clojure folk might enjoy this:
>
> http://blog.stephenwolfram.com/2010/11/100-years-since-principia-mathematica/

Though I don't use Clojure (I follow this list out of curiosity), I
have a hard time imagining why anything Wolfram writes is interesting,
and furthermore why any a user of any not-so-mainstream language would
find it interesting, and even furthermore why a mathematician would.

"And in mathematics, the difference between open-source and
closed-source is more important, for the reason that any part of a
mathematical solution that cannot be fully examined is fatal to the
result."

--http://www.arachnoid.com/sage/

Sorry if members of this group consider this off-topic, but I honestly
couldn't restrain myself...

-- 
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: struct type info

2010-11-27 Thread Shantanu Kumar
I think you can either use either defrecord or factory-function +
metadata:
http://bitumenframework.blogspot.com/2010/10/typed-abstractions-in-clojure.html

Regards,
Shantanu

On Nov 27, 4:24 pm, Sunil S Nandihalli 
wrote:
> Hello,
>  I would like to know if it is possible to find out the name of the
> structure from its instance. my attempt to use the function class is not
> giving me any useful info. It kept saying that it is  a structmap and
> nothing more...
> Regards,
> Sunil

-- 
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: Exporting FatJar from Eclipse CCW does not work

2010-11-27 Thread Gijs S.
Hi,

Perhaps it is a typo but you should have

(defn -main [] ...) rather than (defn- main [] ...)

Note the place of the dash "-".

defn- yields a non public var (a private declaration)
(http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/
defn-)

-main uses the dash, which is the default :prefix "-" for method
lookup in a class
(http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/
gen-class)

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


Exporting FatJar from Eclipse CCW does not work

2010-11-27 Thread Arie van Wingerden
Hi,

when trying to use FatJar from Eclipse / CCW I manage to get the fatjar to
be generated;
however, when I run the jar I get:

D:\src\Clojure\First>java -jar First_fat.jar
Exception in thread "main" java.lang.UnsupportedOperationException:
First.core/-
main not defined
at First.core.main(Unknown Source)

My source code:
   (ns First.core
 (:gen-class))
   (defn- main []
 (println "Hello World!"))

I *did* compile the source and checked that the appropriate classes were
present.

During FatJar generation I specified "First.core" as the Main class.

Any ideas?

Regards
   Arie

-- 
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: struct type info

2010-11-27 Thread David Powell
Hello Sunil,

Saturday, November 27, 2010, 11:24:58 AM, you wrote:

> Hello,
>  I would like to know if it is possible to find out the name of the
> structure from its instance. my attempt to use the function class is
> not giving me any useful info. It kept saying that it is  a structmap and 
> nothing more...
> Regards,
> Sunil

It isn't really possible - structmaps are more intended as an optimisation for 
normal maps than a type system

However in Clojure 1.2 or above, defrecord is available.  This is similar to 
structmaps, but it gives you types, interop with java, and polymorphic method 
dispatch via protocols:

see: http://clojure.org/datatypes

-- 
Dave

-- 
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: struct type info

2010-11-27 Thread Chris Perkins
On Nov 27, 6:24 am, Sunil S Nandihalli 
wrote:
> Hello,
>  I would like to know if it is possible to find out the name of the
> structure from its instance. my attempt to use the function class is not
> giving me any useful info. It kept saying that it is  a structmap and
> nothing more...
> Regards,
> Sunil

Structures created with defstruct or create-struct do not store a
name. They only store the keys.

If you look at the source of defstruct:

user=> (source defstruct)
(defmacro defstruct
  "Same as (def name (create-struct keys...))"
  {:added "1.0"}
  [name & keys]
  `(def ~name (create-struct ~...@keys)))

you can see that the name is not even passed to create-struct. Only
the keys are. So the struct type cannot tell you its name.

- 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


struct type info

2010-11-27 Thread Sunil S Nandihalli
Hello,
 I would like to know if it is possible to find out the name of the
structure from its instance. my attempt to use the function class is not
giving me any useful info. It kept saying that it is  a structmap and
nothing more...
Regards,
Sunil

-- 
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: Why isn't there a fold-right?

2010-11-27 Thread Alex Osborne
"nicolas.o...@gmail.com"  writes:

> I doubt there is a foldr that handles the infinite list.
> To do anything, it would have to read at least one element: the last.
>
> Alex nice answer is a foldl.

Actually I think you have them backwards.  Wikipedia has a pair of
diagrams which I find very useful for visualising which is which:

foldr:
http://en.wikipedia.org/wiki/File:Right-fold-transformation.png

foldl (reduce in Clojure):
http://en.wikipedia.org/wiki/File:Left-fold-transformation.png

Look at the right side of the diagram.  That's the call structure.  (The
left side of the diagram is the linked list (1 2 3 4 5).  The ":" just
means cons in Haskell syntax.)

With a foldr the outermost call is given the first element of the list,
so mine is definitely a foldr.

Let's use (and) as the combining function and use an infinite list that
begins [true true false false ...].  So that looks like:

(lazy-foldr #(and %1 (%2)) nil (cycle [true true false false]))

We can draw an ASCII call structure diagram in the same form as the
Wikipedia one and see this:

  and
  / \
 T  and
/ \
   T  and
  / \
 F   (not evaluated)
 
Since (and) short-circuits when given false, only the part of the list
up to the first false is evaluated.

There's probably not much practical use for lazy-foldr.  But it was fun
to write. :-)

-- 
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: Why isn't there a fold-right?

2010-11-27 Thread nicolas.o...@gmail.com
On Fri, Nov 26, 2010 at 5:28 PM, tpeng  wrote:
> but this foldr can't handle the infinite list, am i right?
>


I doubt there is a foldr that handles the infinite list.
To do anything, it would have to read at least one element: the last.

Alex nice answer is a foldl.

-- 
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: Gloss, a byte-format DSL

2010-11-27 Thread zoka
The most general case would be a codec that can have mixture of big
and little endian fields,
so legacy comms protocols or file formats can be supported.

For example:

(defcodec mixed (ordered-map :b :int16, :a :float32-le))
; total 6 bytes, first 2 bytes short in big endian format (JVM
default),
; followed by 4 byte float in little endian (Intel) format.

Zoka

On Nov 25, 3:00 am, Zach Tellman  wrote:
> ByteBuffers have an order() method which allows you to toggle the
> endianness.  I haven't tested this, but since everything is built on
> top of Java's ByteBuffer functionality it should be fine as long as
> the ByteBuffers are correctly set and correctly ordered with respect
> to each other.
>
> Zach
>

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