Name suggestions

2010-03-17 Thread mac
After just a little more test and polish I plan on calling clj-native
1.0. But clj-native is a *really* boring name so I want to change it
before 1.0 and I don't have very good imagination when it comes to
these things.
So I need your help.
It doesn't have to have anything to do with anything, could just be
something that sounds funny, like sasquatch, that's a funny word.

Please help!

/Markus

On 13 mar, 19:14, mac  wrote:
> Hello all.
> I have had some time lately to work on my C FFI for Clojure and I
> think it's pretty much feature complete now.
> It has support for functions, callbacks, structures, unions and
> globals.
> For structures there is support for different alignments.
>
> The library has two main namespaces: clj-native.direct and clj-
> native.dynamic.
> The direct namespace uses the "direct mapping" feature of JNA in order
> to be as efficient and arity and type safe as possible. However, it
> does not support varargs functions since they require reflection and
> dynamic translation of the parameters. That's what the dynamic
> namespace is for: It can map any C function into clojure, even vararg
> functions like printf but at a higher cost in call time and less
> safety (it's easy to crash the jvm by sending the wrong type or number
> of parameters). Access to global variables through the JNA Pointer
> class is also available in the dynamic namespace.
>
> The library is available from github:http://github.com/bagucode/clj-native
> and clojars:http://clojars.org/clj-native
>
> Example usage of the direct namespace can be found 
> here:http://github.com/bagucode/clj-native/blob/master/src/examples/c_lib.clj
>
> Please report issues or make requests to my github account or by mail.
>
> Enjoy!
>
> /Markus

-- 
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: Name suggestions

2010-03-17 Thread Ramakrishnan Muthukrishnan
On Wed, Mar 17, 2010 at 12:38 PM, mac  wrote:
> After just a little more test and polish I plan on calling clj-native
> 1.0. But clj-native is a *really* boring name so I want to change it
> before 1.0 and I don't have very good imagination when it comes to
> these things.
> So I need your help.
> It doesn't have to have anything to do with anything, could just be
> something that sounds funny, like sasquatch, that's a funny word.

clj-baremetal ?

-- 
  Ramakrishnan

-- 
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: Name suggestions

2010-03-17 Thread Garth Sheldon-Coulson
I suggest prawn.
Garth

On Wed, Mar 17, 2010 at 3:08 AM, mac  wrote:

> After just a little more test and polish I plan on calling clj-native
> 1.0. But clj-native is a *really* boring name so I want to change it
> before 1.0 and I don't have very good imagination when it comes to
> these things.
> So I need your help.
> It doesn't have to have anything to do with anything, could just be
> something that sounds funny, like sasquatch, that's a funny word.
>
> Please help!
>
> /Markus
>
> On 13 mar, 19:14, mac  wrote:
> > Hello all.
> > I have had some time lately to work on my C FFI for Clojure and I
> > think it's pretty much feature complete now.
> > It has support for functions, callbacks, structures, unions and
> > globals.
> > For structures there is support for different alignments.
> >
> > The library has two main namespaces: clj-native.direct and clj-
> > native.dynamic.
> > The direct namespace uses the "direct mapping" feature of JNA in order
> > to be as efficient and arity and type safe as possible. However, it
> > does not support varargs functions since they require reflection and
> > dynamic translation of the parameters. That's what the dynamic
> > namespace is for: It can map any C function into clojure, even vararg
> > functions like printf but at a higher cost in call time and less
> > safety (it's easy to crash the jvm by sending the wrong type or number
> > of parameters). Access to global variables through the JNA Pointer
> > class is also available in the dynamic namespace.
> >
> > The library is available from github:
> http://github.com/bagucode/clj-native
> > and clojars:http://clojars.org/clj-native
> >
> > Example usage of the direct namespace can be found here:
> http://github.com/bagucode/clj-native/blob/master/src/examples/c_lib.clj
> >
> > Please report issues or make requests to my github account or by mail.
> >
> > Enjoy!
> >
> > /Markus
>
> --
> 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: bounded memoize

2010-03-17 Thread Meikel Brandmeyer
Hi,

On Mar 16, 8:13 am, Meikel Brandmeyer  wrote:

> as threatened previously I wrote a summery blog post of this
> discussion: http://kotka.de/blog/2010/03/memoize_done_right.html.
> Please let me know in case I missed something crucial.

And updated with a protocol/type version for bleeding edge:
http://kotka.de/blog/2010/03/memoize_done_right.html#protocols

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Name suggestions

2010-03-17 Thread Adrian Cuthbertson
You asked for it! What's the bet there are at least 50 responses to
your post. How about;
natty, nattle, clonat, or just nat.

-Rgds, Adrian.

On Wed, Mar 17, 2010 at 9:08 AM, mac  wrote:
> After just a little more test and polish I plan on calling clj-native
> 1.0. But clj-native is a *really* boring name so I want to change it
> before 1.0 and I don't have very good imagination when it comes to
> these things.
> So I need your help.
> It doesn't have to have anything to do with anything, could just be
> something that sounds funny, like sasquatch, that's a funny word.
>
> Please help!
>
> /Markus
>
> On 13 mar, 19:14, mac  wrote:
>> Hello all.
>> I have had some time lately to work on my C FFI for Clojure and I
>> think it's pretty much feature complete now.
>> It has support for functions, callbacks, structures, unions and
>> globals.
>> For structures there is support for different alignments.
>>
>> The library has two main namespaces: clj-native.direct and clj-
>> native.dynamic.
>> The direct namespace uses the "direct mapping" feature of JNA in order
>> to be as efficient and arity and type safe as possible. However, it
>> does not support varargs functions since they require reflection and
>> dynamic translation of the parameters. That's what the dynamic
>> namespace is for: It can map any C function into clojure, even vararg
>> functions like printf but at a higher cost in call time and less
>> safety (it's easy to crash the jvm by sending the wrong type or number
>> of parameters). Access to global variables through the JNA Pointer
>> class is also available in the dynamic namespace.
>>
>> The library is available from github:http://github.com/bagucode/clj-native
>> and clojars:http://clojars.org/clj-native
>>
>> Example usage of the direct namespace can be found 
>> here:http://github.com/bagucode/clj-native/blob/master/src/examples/c_lib.clj
>>
>> Please report issues or make requests to my github account or by mail.
>>
>> Enjoy!
>>
>> /Markus
>
> --
> 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: Name suggestions

2010-03-17 Thread Meikel Brandmeyer
aborigine

-- 
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: Name suggestions

2010-03-17 Thread Laurent PETIT
pistil

2010/3/17 Meikel Brandmeyer :
> aborigine
>
> --
> 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: Why do functions in the state monad only accept one value?

2010-03-17 Thread Jarkko Oranen


On Mar 17, 1:17 am, "Steven E. Harris"  wrote:
> Michał Marczyk  writes:
> > a State-using programme builds up a stateful computation first, then
> > uses runState (or perhaps execState / evalState) to run it as a whole;
> > only at this final step does the initial state actually get poured
> > into the opening of the monadic pipe, as it were.
>
> That's a good metaphor.
>
> [...]
>
> > You can use it multiple times, each time injecting a different initial
> > value of state.
>
> Ah, but here's where part of my confusion arises. With this treatment of
> such a built-up computation, it's a kind of a zero-argument function, in
> that there's no way to pass in a "basic value" to kick it off. Where
> does the first "basic value" to be fed into the first monadic function
> come from? Presumably it comes from the first monadic value in the
> "pipe". In your description above, it sounds like this first monadic
> value must be committed to when "buld[ing] up a stateful computation
> first".

Hmm... In Clojure, *values* representing the entire composed
"stateful" computation are functions of the state. therefore, you can
treat it as a regular function and just call (stateful-computation
init-state) as many times as you like. so the first basic value is
simply the one you pass to the composite operation. In haskell, State
monad values have their own type, so you can't use them as functions
directly and need the runState operation. An *operation* on state
monad values is one that returns such a function of state, and the
whole point of the monadic structure is to allow composing these
operations. After all, it's clear that you can't just use function
composition to compose them, because the arguments they expect and the
values they return are not compatible.

Further, any function that creates state monad values can of course be
created dynamically. eg:

(defn make-adder-to-state [x] ; a function
   (fn [v]  ; that returns a monadic function
(fn [s] ; that returns a state monad value.
  [v (+ x s)])))

which can be used like:

(let [computation (m-bind (m-result 4) (make-adder-to-state 5))]
  (computation 10))
 -> [4 15]

Hope this helps

-- 
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: bounded memoize

2010-03-17 Thread Meikel Brandmeyer
Pfff... ttl strategy still broken...

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


Quines

2010-03-17 Thread Kei Suzuki
((fn[](let[s "](print\"((fn[](let[s\"(pr-str s)s" ](print"((fn[]
(let[s"(pr-str s)s

(let[s "](print\"(let[s\"(pr-str s)s))" ](print"(let[s"(pr-str s)s))

(def s"(def s%s)(printf s(pr-str s))")(printf s(pr-str s))

Any others?

-- 
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: take-to-first & partition-when

2010-03-17 Thread Sean Devlin
Hey Greg, welcome to Clojure :)

You might want to take a look at c.c.seq-utils and the clojure cheat
sheet.  Both of these already exist.  See take-while & partition-by

The cheat sheet can be found here:
http://clojure.org/cheatsheet


On Mar 16, 11:12 pm, Greg  Fodor  wrote:
> Just saw that I need to sign the contributor agreement. Will do
> promptly. I additionally have implemented two new functions that I
> believe could fit in clojure-contrib.seq and clojure-
> contrib.combinatorics. The seq function partition-at-fenceposts allows
> you to partition a seq based upon bits flipped in an integer value
> passed in, where 1-bits correspond to partition boundaries, the least
> significant bit being earlier fenceposts in the seq. As such, this
> makes it possible to easily implement a function named partitions for
> clojure-contrib.combinatorics, which yields a lazy seq of all possible
> partitions of a seq.
>
> user=> (partition-at-fenceposts 1 '(1 2 3 4 5))
> ((0) (1 2 3 4))
>
> user=> (partition-at-fenceposts 2 '(1 2 3 4 5))
> ((0 1) (2 3 4))
>
> user=> (partition-at-fenceposts 3 '(1 2 3 4 5))
> ((0) (1) (2 3 4))
>
> user=> (partitions '(1 2 3))
> (((0 1 2)) ((0) (1 2)) ((0 1) (2)) ((0) (1) (2)))
>
> user=> (partitions '(1 2 3 4 5))
> (((0 1 2 3 4)) ((0) (1 2 3 4)) ((0 1) (2 3 4)) ((0) (1) (2 3 4)) ((0 1
> 2) (3 4)) ((0) (1 2) (3 4)) ((0 1) (2) (3 4)) ((0) (1) (2) (3 4)) ((0
> 1 2 3) (4)) ((0) (1 2 3) (4)) ((0 1) (2 3) (4)) ((0) (1) (2 3) (4))
> ((0 1 2) (3) (4)) ((0) (1 2) (3) (4)) ((0 1) (2) (3) (4)) ((0) (1) (2)
> (3) (4)))
>
> implementation:
>
> (defn take-to-first
>   "Returns a lazy sequence of successive items from coll up to
>   and including the point at which it (pred item) returns true.
>   pred must be free of side-effects."
>   [pred coll]
>   (lazy-seq
>    (when-let [s (seq coll)]
>        (if-not (pred (first s))
>          (cons (first s) (take-to-first pred (rest s)))
>          (list (first s))
>
> (defn partition-when
>   "Applies f to each value in coll, splitting it each time f returns
>    true. Returns a lazy seq of lazy seqs."
>   [f coll]
>   (when-let [s (seq coll)]
>   (lazy-seq
>     (let [run (take-to-first f s)
>           res (drop (count run) s)]
>         (cons run (partition-when f res))
>
> (defn partition-at-fenceposts [b coll]
>   "Partitions coll at fenceposts corresponding to bits in b that are
>   set to 1. Returns a lazy seq of lazy seqs."
>   (let [bits b]
>     (map #(map first %)
>         (partition-when
>           (fn [[i v]] (not (zero? (bit-and (bit-shift-left 1 i)
> bits
>           (indexed coll)
>
> (defn partitions [coll]
>   "Returns a lazy seq of possible partitions of coll."
>   (map #(partition-at-fenceposts % coll) (range (expt 2 (- (count
> coll) 1)
>
> On Mar 15, 1:24 pm, Greg  Fodor  wrote:
>
> > Hi there, I am just learning Clojure and am processing some BER
> > encoded integer values. Basically, the most significant bit of the
> > integer in the stream indicates the split point between integers, and
> > so I was looking into partition-by to see if that would help. Turns
> > out, what I really need are two complementary functions: take-to-first
> > and partition-when. Take-to-first is similar to take-while, but is
> > *inclusive* and also inverts the boolean. For example:
>
> > Clojure=> (take-to-first even? [1 1 1 1])
> > (1 1 1 1)
> > Clojure=> (take-to-first even? [1 1 1 1 2 3 3 3])
> > (1 1 1 1 2)
> > Clojure=> (take-to-first even? [2 2 2 ])
> > (2)
>
> > Additionally, partition-when runs through the seq and partitions it on
> > demand when a predicate is true. (Leaving the entry where it is seen
> > to be true in the current partition:
>
> > Clojure=> (partition-when even? [1 1 1 2 3 3 3 4 3 3 3 4 3 3 3])
> > ((1 1 1 2) (3 3 3 4) (3 3 3 4) (3 3 3))
> > Clojure=> (partition-when even? [1 1 1])
> > ((1 1 1))
> > Clojure=> (partition-when even? [1 1 1 2 3 3 3])
> > ((1 1 1 2) (3 3 3))
> > Clojure=> (partition-when even? [2 2 2 2])
> > ((2) (2) (2) (2))
>
> > These seem to sit aside the current take and partitioning functions
> > since they are basically looking at an truth value that indicates a
> > partition or stopping event that we want to capture and cease moving
> > forward. Here is the source:
>
> > (defn take-to-first
> >   "Returns a lazy sequence of successive items from coll up to
> >   and including the point at which it (pred item) returns true.
> >   pred must be free of side-effects."
> >   [pred coll]
> >   (lazy-seq
> >    (when-let [s (seq coll)]
> >        (if-not (pred (first s))
> >          (cons (first s) (take-to pred (rest s)))
> >          (list (first s))
>
> > (defn partition-when
> >   "Applies f to each value in coll, splitting it each time f returns
> >    true. Returns a lazy seq of lazy seqs."
> >   [f coll]
> >   (when-let [s (seq coll)]
> >     (let [run (take-to-first #(f %) s)
> >           res (drop (count run) s)]
> >       (lazy-seq
> >         (cons run (partition-when f res))

position/index-of function

2010-03-17 Thread John R. Williams
I'm looking for a function along the lines of java.util.List.indexOf,
and I'm having a hard time believing it's not there in the core or at
least contrib.  I was expecting to find something like this:

(defn index-of [coll item]
  (let [index (.indexOf (sequence coll) item)]
(if (neg? index) nil index)))

Am I missing something?

-- 
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: position/index-of function

2010-03-17 Thread Sean Devlin
You want the positions fn in c.c.seq

Sean

On Mar 17, 10:43 am, "John R. Williams"  wrote:
> I'm looking for a function along the lines of java.util.List.indexOf,
> and I'm having a hard time believing it's not there in the core or at
> least contrib.  I was expecting to find something like this:
>
> (defn index-of [coll item]
>   (let [index (.indexOf (sequence coll) item)]
>     (if (neg? index) nil index)))
>
> Am I missing something?

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


web starting clojure apps without Java code

2010-03-17 Thread Eugen Dück
All,

Developing in clojure is a lot of fun, at least it was for me and a
project of mine - except for one thing: Deploying the app as Java Web
Start app, that took me a bit of time to figure out, and not only
because Java Web Start is broken in debian squeeze (for a workaround,
see bugs.debian.org/560056 ).

Java Web Start has been discussed in this group some time ago (
http://groups.google.com/group/clojure/browse_thread/thread/f0c69735c5a9bd03/
), and the proposed solution at that time contained one Java class
that did some static initialization (to propagate the necessary
permissions to clojure's own classloader) and then went on to call RT
to load a clj file, after fiddling around with PushBackReaders and so
forth.

I would like to stay away from RT, as it can change, and I don't want
to depend on RT staying the way it is. Now it turns out that Web Start
is actually pretty easy if you just AOT your whole app and gen-class
your main entry point. That way you don't need any Java code.

My clj file that contains the entry point starts like this:

(ns kanshiki.swing
  (:gen-class))

Then I compile the app and create the jar file:
mkdir classes
java -cp clojure.jar:clojure-contrib-slim.jar:classes:. clojure.main -
e "(compile 'kanshiki.swing)"
(cd classes; jar cf ../kanshiki-boom.jar *)
jarsigner kanshiki-boom.jar

And the jnlp contains these tags to make it work:
...
  



  
  
...

The complete jnlp can be found at http://dueck.org/kanshiki-boom/ .

I plan to introduce and document this beta-grade app soon, but if
there's any Japanese learner out there interested in or in need of
Kanji handwriting recognition, check it out, but please hold back with
any bug reports etc. until I have introduced it.

Only one quick note: Kanjis you click will automatically be copied to
the clipboard, so if you use it together with a kanji dictionary that
can search the clipboard like kiten (yes, that's the KDE kanji
dictionary with the hge memory leak, the other day it grew to 6GB
before I killed it), it is actually useful to look up kanjis or words.

Oh, and did I mention lately that clojure is pure fun? Thanks again
Rich! You've done (and are still doing) a terrific job!

Eugen

-- 
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: Name suggestions

2010-03-17 Thread David Nolen
yodel

On Wed, Mar 17, 2010 at 3:08 AM, mac  wrote:

> After just a little more test and polish I plan on calling clj-native
> 1.0. But clj-native is a *really* boring name so I want to change it
> before 1.0 and I don't have very good imagination when it comes to
> these things.
> So I need your help.
> It doesn't have to have anything to do with anything, could just be
> something that sounds funny, like sasquatch, that's a funny word.
>
> Please help!
>
> /Markus
>
> On 13 mar, 19:14, mac  wrote:
> > Hello all.
> > I have had some time lately to work on my C FFI for Clojure and I
> > think it's pretty much feature complete now.
> > It has support for functions, callbacks, structures, unions and
> > globals.
> > For structures there is support for different alignments.
> >
> > The library has two main namespaces: clj-native.direct and clj-
> > native.dynamic.
> > The direct namespace uses the "direct mapping" feature of JNA in order
> > to be as efficient and arity and type safe as possible. However, it
> > does not support varargs functions since they require reflection and
> > dynamic translation of the parameters. That's what the dynamic
> > namespace is for: It can map any C function into clojure, even vararg
> > functions like printf but at a higher cost in call time and less
> > safety (it's easy to crash the jvm by sending the wrong type or number
> > of parameters). Access to global variables through the JNA Pointer
> > class is also available in the dynamic namespace.
> >
> > The library is available from github:
> http://github.com/bagucode/clj-native
> > and clojars:http://clojars.org/clj-native
> >
> > Example usage of the direct namespace can be found here:
> http://github.com/bagucode/clj-native/blob/master/src/examples/c_lib.clj
> >
> > Please report issues or make requests to my github account or by mail.
> >
> > Enjoy!
> >
> > /Markus
>
> --
> 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

help with infinite loop: break and examine stack? dynamic tracing? circular lists?

2010-03-17 Thread Lee Spector

I apologize for the length of this message, but I've run into a problem that I 
think I might approach in any of several ways, each of which leads to questions 
about things that I'd like to know more about in any event. Some are dev 
environment questions and some (re: circular lists near the end) are core 
Clojure language questions.

The root problem is that I think I have an infinite loop somewhere in my code 
and I'm having a hard time tracking it down. My system has a lot of randomness 
in it and I've been unable to produce a repeatable or minimal example, but in 
many full-scale runs I eventually get a hang that smells like an infinite loop. 
I found one that I tracked down to some recursive zipper code, and I fixed 
that, but there's at least one more and I can't find it. One of the reasons 
this is particularly tricky is that I'm dynamically generating and executing 
lots of calls in random/evolved orders with random/evolved arguments, so 
unexpected sequences of events can arise. (And they do arise, which is the 
point! :-)

In Common Lisp I would wait until I think I'm in trouble, break execution with 
a keyboard interrupt, look at the function call stack (and local vars, if I'm 
in a nice CL environment), and probably figure it out pretty quickly.

What would experienced Clojurians suggest in a situation like this?

Is there is a way to break and look around under slime? I just finally got 
slime working with Clojure (THANKS to Lau Jens, 
http://www.bestinclass.dk/index.php/2009/12/clojure-101-getting-clojure-slime-installed/),
 but I don't yet know my way around it. Can anyone recommend a good concise 
description of all of the relevant key commands? I've never used slime much for 
Common Lisp either -- I've used mostly IDEs like MCL and various lisp machines 
way back in the last century -- so I need to start near the beginning on slime. 
Knowing that I could break and examine state would certainly motivate that.

In general I've been running a REPL in a separate terminal window using the clj 
script that comes with ClojureX (on macs running OS X 10.6.2). I don't know how 
to force a break or get a break loop in this environment but when I hit an 
error I can do (.printStackTrace *e) and this does show me some of my own 
function calls amid the other stuff. Even though this is pretty minimal it has 
been very helpful at times. Two problems with this, however: 1) I can only get 
this from an error; I don't know how to force a break so I can look at this 
when I seem to be stuck in a loop, and 2) The stack trace info is always 
elided, with lines saying something like "... 31 more". I want all the trace 
information that it can give me, but I've been unable to figure out how to keep 
it from eliding. I've tried to force clj-initiated runs to break by sending 
signals to the java process from the Mac OS X Activity Monitor app, but 
everything that I have tried (e.g. SIGINT) either does nothing or kills the 
whole process. Is there a signal that I could sent to abort execution but not 
quit java, as happens with errors,  so that I could look at a backtrace? Is 
there a handler that I could add to my code to allow this to happen? It'd only 
help if it allowed me to see what else was going on when the signal was 
received; if it only told me that the error was from a signal arriving then 
that would defeat the purpose.

I've also been doing some runs under MCLIDE, with help from Terje Norderhaug, 
and there I can indeed issue a break from a menu and get a backtrace of 
sorts... but so far I have not been able to get a backtrace that shows me what 
I need -- that is, I don't see any of my own functions, presumably because the 
break changed the context... I'm not sure what's going on there. I've also 
briefly experimented with Eclipse/Counterclockwise, but found Eclipse fairly 
confusing in general... but does it provide a better approach to 
breaking/exploring running code? If so then perhaps I should give that another 
shot.

An alternative: Is there a way to watch my running Clojure program without 
breaking it, that is to observe the recent call history (of my own definitions, 
either all of them or specifically marked ones) from outside the process? I can 
think of some clumsy ways to roll my own version of this, e.g. using trace and 
sending the trace output to a file, but I don't think this will be practical 
because I generally only get these errors after long stretches of intensive 
computation that will involve many many calls to the potentially problematic 
functions. So I think there'll be too much trace output to save on disk, and 
the slowdown from tracing all of the calls may prevent me from ever reaching a 
problematic state (although I haven't tried this to be sure of the timing). I 
guess I could keep a bounded trace on disk but maintaining the bound would slow 
things even more... So this doesn't feel like the best approach. Might there be 
-- wishful thinking, I know -- some alr

Re: take-to-first & partition-when

2010-03-17 Thread Greg Fodor
Hey thanks :) These are different than partition-by and take-while.

partition-by triggers a new partition when the predicate value
*changes*, whereas partition-when triggers a new partition at any
point in the sequence where the predicate is true. take-while takes
all the items up to the point in the sequence where the predicate is
true, where take-to-first does the same but *inclusively*, retaining
the item at which the predicate first becomes true. I'm not sure but I
believe it is not trivial to use partition-by and take-while to
implement either of these.

On Mar 17, 10:33 am, Sean Devlin  wrote:
> Hey Greg, welcome to Clojure :)
>
> You might want to take a look at c.c.seq-utils and the clojure cheat
> sheet.  Both of these already exist.  See take-while & partition-by
>
> The cheat sheet can be found here:http://clojure.org/cheatsheet
>
> On Mar 16, 11:12 pm, Greg  Fodor  wrote:
>
> > Just saw that I need to sign the contributor agreement. Will do
> > promptly. I additionally have implemented two new functions that I
> > believe could fit in clojure-contrib.seq and clojure-
> > contrib.combinatorics. The seq function partition-at-fenceposts allows
> > you to partition a seq based upon bits flipped in an integer value
> > passed in, where 1-bits correspond to partition boundaries, the least
> > significant bit being earlier fenceposts in the seq. As such, this
> > makes it possible to easily implement a function named partitions for
> > clojure-contrib.combinatorics, which yields a lazy seq of all possible
> > partitions of a seq.
>
> > user=> (partition-at-fenceposts 1 '(1 2 3 4 5))
> > ((0) (1 2 3 4))
>
> > user=> (partition-at-fenceposts 2 '(1 2 3 4 5))
> > ((0 1) (2 3 4))
>
> > user=> (partition-at-fenceposts 3 '(1 2 3 4 5))
> > ((0) (1) (2 3 4))
>
> > user=> (partitions '(1 2 3))
> > (((0 1 2)) ((0) (1 2)) ((0 1) (2)) ((0) (1) (2)))
>
> > user=> (partitions '(1 2 3 4 5))
> > (((0 1 2 3 4)) ((0) (1 2 3 4)) ((0 1) (2 3 4)) ((0) (1) (2 3 4)) ((0 1
> > 2) (3 4)) ((0) (1 2) (3 4)) ((0 1) (2) (3 4)) ((0) (1) (2) (3 4)) ((0
> > 1 2 3) (4)) ((0) (1 2 3) (4)) ((0 1) (2 3) (4)) ((0) (1) (2 3) (4))
> > ((0 1 2) (3) (4)) ((0) (1 2) (3) (4)) ((0 1) (2) (3) (4)) ((0) (1) (2)
> > (3) (4)))
>
> > implementation:
>
> > (defn take-to-first
> >   "Returns a lazy sequence of successive items from coll up to
> >   and including the point at which it (pred item) returns true.
> >   pred must be free of side-effects."
> >   [pred coll]
> >   (lazy-seq
> >    (when-let [s (seq coll)]
> >        (if-not (pred (first s))
> >          (cons (first s) (take-to-first pred (rest s)))
> >          (list (first s))
>
> > (defn partition-when
> >   "Applies f to each value in coll, splitting it each time f returns
> >    true. Returns a lazy seq of lazy seqs."
> >   [f coll]
> >   (when-let [s (seq coll)]
> >   (lazy-seq
> >     (let [run (take-to-first f s)
> >           res (drop (count run) s)]
> >         (cons run (partition-when f res))
>
> > (defn partition-at-fenceposts [b coll]
> >   "Partitions coll at fenceposts corresponding to bits in b that are
> >   set to 1. Returns a lazy seq of lazy seqs."
> >   (let [bits b]
> >     (map #(map first %)
> >         (partition-when
> >           (fn [[i v]] (not (zero? (bit-and (bit-shift-left 1 i)
> > bits
> >           (indexed coll)
>
> > (defn partitions [coll]
> >   "Returns a lazy seq of possible partitions of coll."
> >   (map #(partition-at-fenceposts % coll) (range (expt 2 (- (count
> > coll) 1)
>
> > On Mar 15, 1:24 pm, Greg  Fodor  wrote:
>
> > > Hi there, I am just learning Clojure and am processing some BER
> > > encoded integer values. Basically, the most significant bit of the
> > > integer in the stream indicates the split point between integers, and
> > > so I was looking into partition-by to see if that would help. Turns
> > > out, what I really need are two complementary functions: take-to-first
> > > and partition-when. Take-to-first is similar to take-while, but is
> > > *inclusive* and also inverts the boolean. For example:
>
> > > Clojure=> (take-to-first even? [1 1 1 1])
> > > (1 1 1 1)
> > > Clojure=> (take-to-first even? [1 1 1 1 2 3 3 3])
> > > (1 1 1 1 2)
> > > Clojure=> (take-to-first even? [2 2 2 ])
> > > (2)
>
> > > Additionally, partition-when runs through the seq and partitions it on
> > > demand when a predicate is true. (Leaving the entry where it is seen
> > > to be true in the current partition:
>
> > > Clojure=> (partition-when even? [1 1 1 2 3 3 3 4 3 3 3 4 3 3 3])
> > > ((1 1 1 2) (3 3 3 4) (3 3 3 4) (3 3 3))
> > > Clojure=> (partition-when even? [1 1 1])
> > > ((1 1 1))
> > > Clojure=> (partition-when even? [1 1 1 2 3 3 3])
> > > ((1 1 1 2) (3 3 3))
> > > Clojure=> (partition-when even? [2 2 2 2])
> > > ((2) (2) (2) (2))
>
> > > These seem to sit aside the current take and partitioning functions
> > > since they are basically looking at an truth value that indicates a
> > > partition or stopping event that we want to c

Re: help with infinite loop: break and examine stack? dynamic tracing? circular lists?

2010-03-17 Thread Richard Newman
An alternative: Is there a way to watch my running Clojure program  
without breaking it, that is to observe the recent call history (of  
my own definitions, either all of them or specifically marked ones)  
from outside the process?


If you send a SIGQUIT to the java process, it will print the thread  
info (including call stack) for each thread to stdout.


You can also try attaching a Java debugger. They should all work for  
this purpose, if not showing locals etc.


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: Web Programming with clojure

2010-03-17 Thread invis
http://vimeo.com/8356990

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


Broken JSON API in clojure-contrib?

2010-03-17 Thread frye
I'm getting an error, trying to use the JSON API in the clojure-
contrib library:

user=> (ns foo
  (:require clojure.contrib.json))
java.lang.Exception: Unable to resolve symbol: defprotocol in this
context (json.clj:167)


I tried clojure-contrib 1.1.0 with clojure 1.0.0 and 1.1.0. As of
today (March 16th, 2010), I tried getting the latest clojure code and
clojure-contrib code from 1) SVN and 2) GIT respectively.

1) svn checkout http://clojure.googlecode.com/svn/trunk/ clojure-read-
only
2) git://github.com/richhickey/clojure-contrib.git

I'm still getting the error. What library setup do I need to run this
library contrib successfully? Thanks in advance.

-- 
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: take-to-first & partition-when

2010-03-17 Thread Per Vognsen
That implementation of partitions feels really low level. If you
implement the monadic version of partition-when (which I call
partition-where in my own code), it looks as simple as this:

(defn partitions [xs]
  (run-seq (m-partition-where (const [false true]) xs)))

-Per

On Wed, Mar 17, 2010 at 10:12 AM, Greg  Fodor  wrote:
> Just saw that I need to sign the contributor agreement. Will do
> promptly. I additionally have implemented two new functions that I
> believe could fit in clojure-contrib.seq and clojure-
> contrib.combinatorics. The seq function partition-at-fenceposts allows
> you to partition a seq based upon bits flipped in an integer value
> passed in, where 1-bits correspond to partition boundaries, the least
> significant bit being earlier fenceposts in the seq. As such, this
> makes it possible to easily implement a function named partitions for
> clojure-contrib.combinatorics, which yields a lazy seq of all possible
> partitions of a seq.
>
> user=> (partition-at-fenceposts 1 '(1 2 3 4 5))
> ((0) (1 2 3 4))
>
> user=> (partition-at-fenceposts 2 '(1 2 3 4 5))
> ((0 1) (2 3 4))
>
> user=> (partition-at-fenceposts 3 '(1 2 3 4 5))
> ((0) (1) (2 3 4))
>
> user=> (partitions '(1 2 3))
> (((0 1 2)) ((0) (1 2)) ((0 1) (2)) ((0) (1) (2)))
>
> user=> (partitions '(1 2 3 4 5))
> (((0 1 2 3 4)) ((0) (1 2 3 4)) ((0 1) (2 3 4)) ((0) (1) (2 3 4)) ((0 1
> 2) (3 4)) ((0) (1 2) (3 4)) ((0 1) (2) (3 4)) ((0) (1) (2) (3 4)) ((0
> 1 2 3) (4)) ((0) (1 2 3) (4)) ((0 1) (2 3) (4)) ((0) (1) (2 3) (4))
> ((0 1 2) (3) (4)) ((0) (1 2) (3) (4)) ((0 1) (2) (3) (4)) ((0) (1) (2)
> (3) (4)))
>
> implementation:
>
> (defn take-to-first
>  "Returns a lazy sequence of successive items from coll up to
>  and including the point at which it (pred item) returns true.
>  pred must be free of side-effects."
>  [pred coll]
>  (lazy-seq
>   (when-let [s (seq coll)]
>       (if-not (pred (first s))
>         (cons (first s) (take-to-first pred (rest s)))
>         (list (first s))
>
> (defn partition-when
>  "Applies f to each value in coll, splitting it each time f returns
>   true. Returns a lazy seq of lazy seqs."
>  [f coll]
>  (when-let [s (seq coll)]
>  (lazy-seq
>    (let [run (take-to-first f s)
>          res (drop (count run) s)]
>        (cons run (partition-when f res))
>
> (defn partition-at-fenceposts [b coll]
>  "Partitions coll at fenceposts corresponding to bits in b that are
>  set to 1. Returns a lazy seq of lazy seqs."
>  (let [bits b]
>    (map #(map first %)
>        (partition-when
>          (fn [[i v]] (not (zero? (bit-and (bit-shift-left 1 i)
> bits
>          (indexed coll)
>
> (defn partitions [coll]
>  "Returns a lazy seq of possible partitions of coll."
>  (map #(partition-at-fenceposts % coll) (range (expt 2 (- (count
> coll) 1)
>
>
> On Mar 15, 1:24 pm, Greg  Fodor  wrote:
>> Hi there, I am just learning Clojure and am processing some BER
>> encoded integer values. Basically, the most significant bit of the
>> integer in the stream indicates the split point between integers, and
>> so I was looking into partition-by to see if that would help. Turns
>> out, what I really need are two complementary functions: take-to-first
>> and partition-when. Take-to-first is similar to take-while, but is
>> *inclusive* and also inverts the boolean. For example:
>>
>> Clojure=> (take-to-first even? [1 1 1 1])
>> (1 1 1 1)
>> Clojure=> (take-to-first even? [1 1 1 1 2 3 3 3])
>> (1 1 1 1 2)
>> Clojure=> (take-to-first even? [2 2 2 ])
>> (2)
>>
>> Additionally, partition-when runs through the seq and partitions it on
>> demand when a predicate is true. (Leaving the entry where it is seen
>> to be true in the current partition:
>>
>> Clojure=> (partition-when even? [1 1 1 2 3 3 3 4 3 3 3 4 3 3 3])
>> ((1 1 1 2) (3 3 3 4) (3 3 3 4) (3 3 3))
>> Clojure=> (partition-when even? [1 1 1])
>> ((1 1 1))
>> Clojure=> (partition-when even? [1 1 1 2 3 3 3])
>> ((1 1 1 2) (3 3 3))
>> Clojure=> (partition-when even? [2 2 2 2])
>> ((2) (2) (2) (2))
>>
>> These seem to sit aside the current take and partitioning functions
>> since they are basically looking at an truth value that indicates a
>> partition or stopping event that we want to capture and cease moving
>> forward. Here is the source:
>>
>> (defn take-to-first
>>   "Returns a lazy sequence of successive items from coll up to
>>   and including the point at which it (pred item) returns true.
>>   pred must be free of side-effects."
>>   [pred coll]
>>   (lazy-seq
>>    (when-let [s (seq coll)]
>>        (if-not (pred (first s))
>>          (cons (first s) (take-to pred (rest s)))
>>          (list (first s))
>>
>> (defn partition-when
>>   "Applies f to each value in coll, splitting it each time f returns
>>    true. Returns a lazy seq of lazy seqs."
>>   [f coll]
>>   (when-let [s (seq coll)]
>>     (let [run (take-to-first #(f %) s)
>>           res (drop (count run) s)]
>>       (lazy-seq
>>         (cons run (partition-when f res))
>>
>> I thin

Re: leiningen and random jars

2010-03-17 Thread johnprince
You don't need a pom file - just append -DgeneratePom=true to mvn
install:install-file and maven will generate one for you.

John

On Mar 16, 9:34 pm, Phil Hagelberg  wrote:
> On Tue, Mar 16, 2010 at 9:22 AM, stevel  wrote:
> > I'd really like to use leiningen to assemble my classpath for me, but
> > need to reference a jdbc jar.
> > What is the approved method of doing this?
>
> The best way to do it would be to push it to a public repository so
> everyone on your team can have access to it in an automated fashion.
> If the project is only going to be developed on one machine you could
> put it in lib/ as David suggests (just be careful not to run clean) or
> use mvn install:install-file if you have a pom file for it.
>
> -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: help with infinite loop: break and examine stack? dynamic tracing? circular lists?

2010-03-17 Thread Terje Norderhaug

On Mar 17, 2010, at 8:14 AM, Lee Spector wrote:
The root problem is that I think I have an infinite loop somewhere  
in my code and I'm having a hard time tracking it down. [...] In  
Common Lisp I would wait until I think I'm in trouble, break  
execution with a keyboard interrupt, look at the function call  
stack (and local vars, if I'm in a nice CL environment), and  
probably figure it out pretty quickly.[...] Is there is a way to  
break and look around under slime? [...]


I've also been doing some runs under MCLIDE, with help from Terje  
Norderhaug, and there I can indeed issue a break from a menu and  
get a backtrace of sorts... but so far I have not been able to get  
a backtrace that shows me what I need -- that is, I don't see any  
of my own functions, presumably because the break changed the  
context... I'm not sure what's going on there.


MCLIDE gets the same backtrace items from swank-clojure as does emacs  
SLIME. I believe the issue is that the JVM only provides limited  
stacktrace information (at least compared to what Common Lisp  
developers are used to).


A good backtrace is essential for efficient debugging. Are there any  
ways to improve the backtrace provided by swank-clojure?


An alternative: Is there a way to watch my running Clojure program  
without breaking it, that is to observe the recent call history (of  
my own definitions, either all of them or specifically marked ones)  
from outside the process?


You could use a profiler to see which of your Clojure functions  
monopolize the execution.


I can think of some clumsy ways to roll my own version of this,  
e.g. using trace and sending the trace output to a file, but I  
don't think this will be practical because I generally only get  
these errors after long stretches of intensive computation that  
will involve many many calls to the potentially problematic  
functions. So I think there'll be too much trace output to save on  
disk, and the slowdown from tracing all of the calls may prevent me  
from ever reaching a problematic state (although I haven't tried  
this to be sure of the timing).


Consider waiting until you are in the situation then use trace on  
candidate culprits.


And in spite of the problems listed above I'm having a great time  
in the Clojureverse!



-- Terje Norderhaug
  te...@in-progress.com




--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Simple functional programming lexicon?

2010-03-17 Thread Ben Armstrong
I am new to clojure and functional programming, but not to programming 
in general, having been in the profession for a quarter of a century.  
I'm trying to stretch myself a bit by learning clojure, but some of the 
threads here go beyond mere stretching to verge on head-exploding.  In 
my offline reading of this list this morning, I tried using the tools 
available to me at the time (dict client and a few dictionaries like 
foldoc) to make sense of words like:  http://foldoc.org/monad .  I 
survived to write this post, but only barely.


What I would like to have is some sort of lexicon to at least help 
explain the terminology in a way that doesn't require three years of 
academic exposure to functional programming to read.  Is there such a 
reference?  Or should I just ignore threads like "Why do functions in 
the state monad only accept one value?" and be happy that at least 
somebody cares about this stuff, so that I don't have to?


Ben

--
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: help with infinite loop: break and examine stack? dynamic tracing? circular lists?

2010-03-17 Thread Lee Spector

Thanks Richard.

The SIGQUIT thing sounds potentially useful, but when I send a SIGQUIT to the 
stuck (looping) java process it has no effect. I've tried sending SIGQUIT via 
the Max OS X Activity Monitor and also kill -3, kill -s SIGQUIT, and kill 
-SIGQUIT with the process ID from a terminal window. I know that kill -9 will 
kill it but I get no thread info. The other signals I've tried are all either 
ignored or uninformative.

On Java debuggers: Is there a particular one that I ought to try? I see a big 
universe of these, but with most assuming a particular development environment 
or other setup stuff that I wouldn't know how to do from Clojure... Aside from 
minor dabbling I'm new to the Java universe.

 -Lee


On Mar 17, 2010, at 1:58 PM, Richard Newman wrote:

>> An alternative: Is there a way to watch my running Clojure program without 
>> breaking it, that is to observe the recent call history (of my own 
>> definitions, either all of them or specifically marked ones) from outside 
>> the process?
> 
> If you send a SIGQUIT to the java process, it will print the thread info 
> (including call stack) for each thread to stdout.
> 
> You can also try attaching a Java debugger. They should all work for this 
> purpose, if not showing locals etc.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> 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

--
Lee Spector, Professor of Computer Science
School of Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspec...@hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438

Check out Genetic Programming and Evolvable Machines:
http://www.springer.com/10710 - http://gpemjournal.blogspot.com/

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: help with infinite loop: break and examine stack? dynamic tracing? circular lists?

2010-03-17 Thread Lee Spector

Thanks Terje. I think I must be missing something because both your profiling 
and "waiting until you are in the situation then use trace on candidate 
culprits" ideas sound great IF I could do ANYTHING when I'm in the problematic 
situation. But I can't. My REPL is frozen and unresponsive to anything except 
cntrl-z (not even cntrol-c works) but I can tell from top that it's cranking 
CPU, maxing out all cores.

UPDATE to Richard: One of those SIGQUIT instructions DID eventually get through 
the process and spill stacktrace info to the terminal. And I see some of my own 
function names there, so this is excellent and I have a starting point for 
further investigation. It took several minutes to have an effect, so I just 
thought it was a lost cause. It'd still be even nicer to be able to get some 
info without quitting, but this is definitely an improvement!

 -Lee


On Mar 17, 2010, at 2:04 PM, Terje Norderhaug wrote:

> On Mar 17, 2010, at 8:14 AM, Lee Spector wrote:
>> The root problem is that I think I have an infinite loop somewhere in my 
>> code and I'm having a hard time tracking it down. [...] In Common Lisp I 
>> would wait until I think I'm in trouble, break execution with a keyboard 
>> interrupt, look at the function call stack (and local vars, if I'm in a nice 
>> CL environment), and probably figure it out pretty quickly.[...] Is there is 
>> a way to break and look around under slime? [...]
>> 
>> I've also been doing some runs under MCLIDE, with help from Terje 
>> Norderhaug, and there I can indeed issue a break from a menu and get a 
>> backtrace of sorts... but so far I have not been able to get a backtrace 
>> that shows me what I need -- that is, I don't see any of my own functions, 
>> presumably because the break changed the context... I'm not sure what's 
>> going on there.
> 
> MCLIDE gets the same backtrace items from swank-clojure as does emacs SLIME. 
> I believe the issue is that the JVM only provides limited stacktrace 
> information (at least compared to what Common Lisp developers are used to).
> 
> A good backtrace is essential for efficient debugging. Are there any ways to 
> improve the backtrace provided by swank-clojure?
> 
>> An alternative: Is there a way to watch my running Clojure program without 
>> breaking it, that is to observe the recent call history (of my own 
>> definitions, either all of them or specifically marked ones) from outside 
>> the process?
> 
> You could use a profiler to see which of your Clojure functions monopolize 
> the execution.
> 
>> I can think of some clumsy ways to roll my own version of this, e.g. using 
>> trace and sending the trace output to a file, but I don't think this will be 
>> practical because I generally only get these errors after long stretches of 
>> intensive computation that will involve many many calls to the potentially 
>> problematic functions. So I think there'll be too much trace output to save 
>> on disk, and the slowdown from tracing all of the calls may prevent me from 
>> ever reaching a problematic state (although I haven't tried this to be sure 
>> of the timing).
> 
> Consider waiting until you are in the situation then use trace on candidate 
> culprits.
> 
>> And in spite of the problems listed above I'm having a great time in the 
>> Clojureverse!
> 
> 
> -- Terje Norderhaug
>  te...@in-progress.com
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
Lee Spector, Professor of Computer Science
School of Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspec...@hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438

Check out Genetic Programming and Evolvable Machines:
http://www.springer.com/10710 - http://gpemjournal.blogspot.com/

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: help with infinite loop: break and examine stack? dynamic tracing? circular lists?

2010-03-17 Thread Richard Newman
It'd still be even nicer to be able to get some info without  
quitting, but this is definitely an improvement!


The JVM shouldn't quit when it gets a SIGQUIT. That's just the signal  
name.


You might find this useful:

http://www.unixville.com/~moazam/stories/2004/05/18/debuggingHangsInTheJvm.html

--
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: Simple functional programming lexicon?

2010-03-17 Thread Sean Devlin
Here's a collection of reading material:

http://news.ycombinator.com/item?id=1033503

Personally, I'd recommend Programming Clojure as a good place to
start.

Sean

On Mar 17, 8:28 am, Ben Armstrong  wrote:
> I am new to clojure and functional programming, but not to programming
> in general, having been in the profession for a quarter of a century.  
> I'm trying to stretch myself a bit by learning clojure, but some of the
> threads here go beyond mere stretching to verge on head-exploding.  In
> my offline reading of this list this morning, I tried using the tools
> available to me at the time (dict client and a few dictionaries like
> foldoc) to make sense of words like:  http://foldoc.org/monad.  I
> survived to write this post, but only barely.
>
> What I would like to have is some sort of lexicon to at least help
> explain the terminology in a way that doesn't require three years of
> academic exposure to functional programming to read.  Is there such a
> reference?  Or should I just ignore threads like "Why do functions in
> the state monad only accept one value?" and be happy that at least
> somebody cares about this stuff, so that I don't have to?
>
> Ben

-- 
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: position/index-of function

2010-03-17 Thread Christophe Grand
On Wed, Mar 17, 2010 at 3:43 PM, John R. Williams  wrote:

> I'm looking for a function along the lines of java.util.List.indexOf,
> and I'm having a hard time believing it's not there in the core or at
> least contrib.  I was expecting to find something like this:
>
> (defn index-of [coll item]
>  (let [index (.indexOf (sequence coll) item)]
>(if (neg? index) nil index)))
>
> Am I missing something?
>

It's not in core to promote better suited data types (sets, maps) because
95% of the time .indexOf is used to check if an element is in a collection
(if it's a one-off you can use (some #(= item %) coll)).

Vectors and lists both implement j.u.List so if you really need to you can
resort to interop (and you don't need to call sequence before).

Christophe

-- 
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: Broken JSON API in clojure-contrib?

2010-03-17 Thread Michael Wood
On 16 March 2010 22:26, frye  wrote:
> I'm getting an error, trying to use the JSON API in the clojure-
> contrib library:
>
> user=> (ns foo
>  (:require clojure.contrib.json))
> java.lang.Exception: Unable to resolve symbol: defprotocol in this
> context (json.clj:167)

defprotocol is a Clojure version 1.2 thing.  i.e. it does not exist in
any released version of Clojure yet.  It looks like you're trying to
use a version of clojure.contrib that is too new for your version of
clojure.  I've not used clojure.contrib.json, but the version in
clojure-contrib 1.1.0 should work with clojure 1.1.0.

> I tried clojure-contrib 1.1.0 with clojure 1.0.0 and 1.1.0. As of
> today (March 16th, 2010), I tried getting the latest clojure code and
> clojure-contrib code from 1) SVN and 2) GIT respectively.
>
> 1) svn checkout http://clojure.googlecode.com/svn/trunk/ clojure-read-
> only

The Subversion repositories (on Sourceforge and Google code) were
abandoned long ago.  Don't use them.

> 2) git://github.com/richhickey/clojure-contrib.git
>
> I'm still getting the error. What library setup do I need to run this
> library contrib successfully? Thanks in advance.

$ git clone ...clojure.git
$ cd clojure
$ git checkout -b v1.1.0 1.1.0
Switched to a new branch 'v1.1.0'
$ ant
[...]
BUILD SUCCESSFUL
Total time: 15 seconds
$ cp clojure-1.1.0.jar /tmp
$ cd ..
$ git clone ...clojure-contrib.git
$ cd clojure-contrib
$ git checkout -b v1.1.0 1.1.0
Switched to a new branch 'v1.1.0'
$ ant
[...]
BUILD SUCCESSFUL
Total time: 18 seconds
$ cp clojure-contrib.jar /tmp
$ cd /tmp
$ java -cp clojure-1.1.0.jar:clojure-contrib.jar clojure.main
Clojure 1.1.0
user=> (ns foo
 (:require clojure.contrib.json))
java.io.FileNotFoundException: Could not locate
clojure/contrib/json__init.class or clojure/contrib/json.clj on
classpath:  (NO_SOURCE_FILE:1)

So it seems the API has changed.  If you look here you will find the 1.1.x API:

http://richhickey.github.com/clojure-contrib/branch-1.1.x/json.read-api.html

$ java -cp clojure-1.1.0.jar:clojure-contrib.jar clojure.mainClojure 1.1.0
user=> (ns foo (:require clojure.contrib.json.read))
nil
foo=>

-- 
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: help with infinite loop: break and examine stack? dynamic tracing? circular lists?

2010-03-17 Thread Lee Spector

Thanks again -- that is definitely a useful page at unixville.

BTW from the dump I got from your previous suggestion I think that my original 
bug wasn't a loop after all, but was instead caused by exponentially growing 
BigIntegers. We'll see, but at least I have a better way to investigate things 
now.

 -Lee

On Mar 17, 2010, at 2:58 PM, Richard Newman wrote:

>> It'd still be even nicer to be able to get some info without quitting, but 
>> this is definitely an improvement!
> 
> The JVM shouldn't quit when it gets a SIGQUIT. That's just the signal name.
> 
> You might find this useful:
> 
> http://www.unixville.com/~moazam/stories/2004/05/18/debuggingHangsInTheJvm.html
> 
> -- 
> 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

--
Lee Spector, Professor of Computer Science
School of Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspec...@hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438

Check out Genetic Programming and Evolvable Machines:
http://www.springer.com/10710 - http://gpemjournal.blogspot.com/

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Broken JSON API in clojure-contrib?

2010-03-17 Thread Michael Wood
On 17 March 2010 21:18, Michael Wood  wrote:
[...]
> $ java -cp clojure-1.1.0.jar:clojure-contrib.jar clojure.mainClojure 1.1.0
[...]

Whoops!  Not sure what happened there.  That's of course supposed to be:

$ java -cp clojure-1.1.0.jar:clojure-contrib.jar clojure.main
Clojure 1.1.0

but I'm sure nobody was confused :)

-- 
Michael Wood 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Simple functional programming lexicon?

2010-03-17 Thread David Nolen
On Wed, Mar 17, 2010 at 8:28 AM, Ben Armstrong  wrote:

> What I would like to have is some sort of lexicon to at least help explain
> the terminology in a way that doesn't require three years of academic
> exposure to functional programming to read.  Is there such a reference?  Or
> should I just ignore threads like "Why do functions in the state monad only
> accept one value?" and be happy that at least somebody cares about this
> stuff, so that I don't have to?
>
> Ben
>

To me the beauty of Clojure isn't that you _don't_ need a strong academic
background or even much exposure to FP to approach the language. Clojure is
relatively free of FP jargon, instead we have "Rich Hickey Jargon". I jest
:)

But seriously, in my personal opinion Monads are relatively useless in the
context of Clojure. They are necessary in pure FP languages like Haskell
because otherwise it's impossible get any real applications written. This is
not to say they are not useful, you just don't need to know a damn thing
about them to have fun in Clojure.

Having hacked on Clojure for a a year and half now I think the best approach
is to learn those aspects of Clojure that are most useful to you. You
certainly don't need to pick up everything at once. I still don't completely
grok deftype/protocols or the more involved concurrency constructs. This
hasn't stopped me from writing many useful programs.

If you _do_ want to get deeper in Clojure's philosophy you can't beat Rich
Hickey's Amazon Bookshelf.

David

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Simple functional programming lexicon?

2010-03-17 Thread James Reeves
On 17 March 2010 19:54, David Nolen  wrote:
> But seriously, in my personal opinion Monads are relatively useless in the
> context of Clojure.

I'm considering using the continuation monad to implement a parser
that can pick up where it left off. However, I agree that they're very
rarely used in Clojure.

- 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


Re: Simple functional programming lexicon?

2010-03-17 Thread Konrad Hinsen

On 17 Mar 2010, at 20:54, David Nolen wrote:

But seriously, in my personal opinion Monads are relatively useless  
in the context of Clojure.


I'd say that in any impure functional language, monads are useful in  
the context of specific applications or algorithmic approaches. When  
working with continuations, or when writing complex parsers, monads  
are useful. It's just Haskell that has a language-specific relation to  
monads, because it needs them for fundamental tasks such as I/O.


Konrad.


--
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: Simple functional programming lexicon?

2010-03-17 Thread David Nolen
On Wed, Mar 17, 2010 at 4:09 PM, Konrad Hinsen
wrote:

> On 17 Mar 2010, at 20:54, David Nolen wrote:
>
>  But seriously, in my personal opinion Monads are relatively useless in the
>> context of Clojure.
>>
>
> I'd say that in any impure functional language, monads are useful in the
> context of specific applications or algorithmic approaches. When working
> with continuations, or when writing complex parsers, monads are useful. It's
> just Haskell that has a language-specific relation to monads, because it
> needs them for fundamental tasks such as I/O.


James, and Konrad sorry if I sounded overly dismissive of Monads ;) Yes for
parsers, continuations, other tricky problems they provide a very elegant
solution.

David

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Simple functional programming lexicon?

2010-03-17 Thread eyeris
On Mar 17, 7:28 am, Ben Armstrong  wrote:
> Or should I just ignore threads like "Why do functions in the state monad 
> only accept one value?"

Yes, ignore those for now. Write an entire program in Clojure before
you read anything about monads. They aren't required. When I first
dipped my toes in the functional waters I learned a lot from "Casting
SPELs in LISP"[1]. It's based around Common Lisp, but it should be
easily translatable to Clojure.

[1] http://www.lisperati.com/casting.html

-- 
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: help with infinite loop: break and examine stack? dynamic tracing? circular lists?

2010-03-17 Thread Michael Wood
On 17 March 2010 20:40, Lee Spector  wrote:
>
> Thanks Richard.
>
> The SIGQUIT thing sounds potentially useful, but when I send a SIGQUIT to the 
> stuck (looping) java process it has no effect. I've tried sending SIGQUIT via 
> the Max OS X Activity Monitor and also kill -3, kill -s SIGQUIT, and kill 
> -SIGQUIT with the process ID from a terminal window. I know that kill -9 will 
> kill it but I get no thread info. The other signals I've tried are all either 
> ignored or uninformative.

I didn't know about it before Richard mentioned it, but it does seem
to work.  I tried both on Linux and OS X.

e.g. in one terminal:

$ java -cp clojure.jar clojure.main

Then in another:

$ ps ax | grep java

Find the PID and then:

$ kill -QUIT 

and I get something like this:

Full thread dump Java HotSpot(TM) Server VM (1.5.0_13-119 mixed mode):

"Low Memory Detector" daemon prio=5 tid=0x0020a700 nid=0x81ca00
runnable [0x..0x]

"CompilerThread1" daemon prio=9 tid=0x00209c30 nid=0x81bc00 waiting on
condition [0x..0xb0c093b8]

"CompilerThread0" daemon prio=9 tid=0x00209670 nid=0x81ae00 waiting on
condition [0x..0xb0b87f48]

"AdapterThread" daemon prio=9 tid=0x00209080 nid=0x815e00 waiting on
condition [0x..0x]

"Signal Dispatcher" daemon prio=9 tid=0x00208c30 nid=0x808600 waiting
on condition [0x..0x]

"Finalizer" daemon prio=8 tid=0x00208350 nid=0x819c00 in Object.wait()
[0xb0a05000..0xb0a05d90]
at java.lang.Object.wait(Native Method)
- waiting on <0x07851580> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:116)
- locked <0x07851580> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:132)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)

"Reference Handler" daemon prio=10 tid=0x00207f50 nid=0x818e00 in
Object.wait() [0xb0984000..0xb0984d90]
at java.lang.Object.wait(Native Method)
- waiting on <0x07851600> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:474)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
- locked <0x07851600> (a java.lang.ref.Reference$Lock)

"main" prio=5 tid=0x00201370 nid=0xb0801000 runnable [0xb07ff000..0xb0800148]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:90)
at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:265)
at clojure.main$skip_whitespace__5866.invoke(main.clj:70)
at clojure.main$repl_read__5869.invoke(main.clj:91)
at clojure.main$repl__5879$read_eval_print__5887.invoke(main.clj:181)
at clojure.main$repl__5879.doInvoke(main.clj:200)
at clojure.lang.RestFn.invoke(RestFn.java:422)
at clojure.main$repl_opt__5914.invoke(main.clj:254)
at clojure.main$main__5940.doInvoke(main.clj:347)
at clojure.lang.RestFn.invoke(RestFn.java:398)
at clojure.lang.Var.invoke(Var.java:361)
at clojure.lang.AFn.applyToHelper(AFn.java:161)
at clojure.lang.Var.applyTo(Var.java:482)
at clojure.main.main(main.java:37)

"VM Thread" prio=9 tid=0x002076a0 nid=0x809800 runnable

"VM Periodic Task Thread" prio=9 tid=0x0020b300 nid=0x81d800 waiting
on condition

"Exception Catcher Thread" prio=10 tid=0x002015f0 nid=0x80a800 runnable
java.io.IOException: Interrupted system call
user=>

I suppose if you've redirected stdout somewhere else it might not show
up where you expect it to.  e.g. maybe SLIME interferes somehow (just
guessing).

> On Java debuggers: Is there a particular one that I ought to try? I see a big 
> universe of these, but with most assuming a particular development 
> environment or other setup stuff that I wouldn't know how to do from 
> Clojure... Aside from minor dabbling I'm new to the Java universe.

I've never used a Java debugger, but VisualVM has been mentioned on
this list before.

http://java.sun.com/javase/6/docs/technotes/guides/visualvm/

I'm pretty sure others have been mentioned too, but I can't remember off hand.

-- 
Michael Wood 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: take-to-first & partition-when

2010-03-17 Thread Garth Sheldon-Coulson
Hi Greg,

Welcome to Clojure!

I haven't scrutinized your code, but at a glance it looks like your
implementations are very idiomatic.

It also seems right to me that these functions can't be implemented directly
in terms of take-while and partition-by. Without more thought I can't say if
there are more direct implementations than yours, but I wanted to compliment
you anyway on getting your hands dirty. These look like useful functions.
Perhaps someone
who knows c.c.seq well can say more.

Here's another implementation of take-to-first, just for comparison's sake.
I tried to use the standard sequence functions. Yours is twice as fast and
more readable.

(defn take-to-first [pred coll]
  (if (seq coll)
(map last
 (take-while (comp (complement pred) first)
 (cons (list (first coll)) (partition 2 1 coll
(lazy-seq)))

Garth

On Mon, Mar 15, 2010 at 1:24 PM, Greg Fodor  wrote:

> Hi there, I am just learning Clojure and am processing some BER
> encoded integer values. Basically, the most significant bit of the
> integer in the stream indicates the split point between integers, and
> so I was looking into partition-by to see if that would help. Turns
> out, what I really need are two complementary functions: take-to-first
> and partition-when. Take-to-first is similar to take-while, but is
> *inclusive* and also inverts the boolean. For example:
>
> Clojure=> (take-to-first even? [1 1 1 1])
> (1 1 1 1)
> Clojure=> (take-to-first even? [1 1 1 1 2 3 3 3])
> (1 1 1 1 2)
> Clojure=> (take-to-first even? [2 2 2 ])
> (2)
>
> Additionally, partition-when runs through the seq and partitions it on
> demand when a predicate is true. (Leaving the entry where it is seen
> to be true in the current partition:
>
> Clojure=> (partition-when even? [1 1 1 2 3 3 3 4 3 3 3 4 3 3 3])
> ((1 1 1 2) (3 3 3 4) (3 3 3 4) (3 3 3))
> Clojure=> (partition-when even? [1 1 1])
> ((1 1 1))
> Clojure=> (partition-when even? [1 1 1 2 3 3 3])
> ((1 1 1 2) (3 3 3))
> Clojure=> (partition-when even? [2 2 2 2])
> ((2) (2) (2) (2))
>
> These seem to sit aside the current take and partitioning functions
> since they are basically looking at an truth value that indicates a
> partition or stopping event that we want to capture and cease moving
> forward. Here is the source:
>
> (defn take-to-first
>  "Returns a lazy sequence of successive items from coll up to
>  and including the point at which it (pred item) returns true.
>  pred must be free of side-effects."
>  [pred coll]
>  (lazy-seq
>   (when-let [s (seq coll)]
>   (if-not (pred (first s))
> (cons (first s) (take-to pred (rest s)))
> (list (first s))
>
> (defn partition-when
>  "Applies f to each value in coll, splitting it each time f returns
>   true. Returns a lazy seq of lazy seqs."
>  [f coll]
>  (when-let [s (seq coll)]
>(let [run (take-to-first #(f %) s)
>  res (drop (count run) s)]
>  (lazy-seq
>(cons run (partition-when f res))
>
> I think these could make a good addition to clojure.contrib.seq.
> Please let me know if there is an easier way to get this in if you
> agree. Also, please let me know if these are the best ways to write
> these functions, since I am still a newbie!
>
> --
> 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: Simple functional programming lexicon?

2010-03-17 Thread Ben Armstrong

On 17/03/10 03:58 PM, Sean Devlin wrote:

Here's a collection of reading material:

http://news.ycombinator.com/item?id=1033503

Personally, I'd recommend Programming Clojure as a good place to
start.
   


Thanks.  Yes, I have already started with "Programming Clojure".  It is 
because it doesn't go deeply into FP ('monad' is mentioned once, in an 
aside, and is unexplained in that reference) that I was looking for 
other references.  I'll have a look at some of the others on this page.


Ben

--
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: Simple functional programming lexicon?

2010-03-17 Thread jonathan.watmo...@gmail.com
On Mar 17, 7:28 am, Ben Armstrong  wrote:
> I am new to clojure and functional programming, but not to programming
> in general, having been in the profession for a quarter of a century.  
> I'm trying to stretch myself a bit by learning clojure, but some of the
> threads here go beyond mere stretching to verge on head-exploding.  In
> my offline reading of this list this morning, I tried using the tools
> available to me at the time (dict client and a few dictionaries like
> foldoc) to make sense of words like:  http://foldoc.org/monad.  I
> survived to write this post, but only barely.
>
> What I would like to have is some sort of lexicon to at least help
> explain the terminology in a way that doesn't require three years of
> academic exposure to functional programming to read.  Is there such a
> reference?  Or should I just ignore threads like "Why do functions in
> the state monad only accept one value?" and be happy that at least
> somebody cares about this stuff, so that I don't have to?
>
> Ben


Ben,
You can do a LOT with just a basic level of Clojure. I'm writing a
database
loader to help support an iPhone app I'm writing, and got done in just
a few
hours whilst only scratching the surface of what's available. No
paralleism,
no monads, no macros, no refs.
My opinion, and it may only be valid for me, is learning a language
works
best when you have a definite task, and you can build code, then
better
code, then even better code in the language you're trying to learn.
I have a couple of the books, but as yet, the best method for
learning
seems to be google and example code.
Tim Bray has a Clojure Wide Finder series that makes interesting
reading.
The best thing about Clojure is the immediacy and ability to syntax
check
as you go. I'm using TextMate with the Clojure bundle and it's working
great,
just hit clover-R on hightlighted text and the result comes right
back...
In short don't worry about monads... The terminology is awful, and
they make
my head explode too.
Here's a nice little piece of code that sucks in a file and inserts it
into a SQL
table. This is the sort of conciseness I love about Clojure.

(defn load-records [table-name file-name]
(doseq [line (-> file-name java.io.FileReader.
java.io.BufferedReader. line-seq)]
(let [fields (map #(.replace %1 "~" "") (seq (.split #"\^" (str 
line
"~"]
(sql/insert-rows table-name fields

If this sucks as code, someone jump in and tell!

Best Wishes,
Jonathan

-- 
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: Simple functional programming lexicon?

2010-03-17 Thread Ben Armstrong

On 17/03/10 04:54 PM, David Nolen wrote:
To me the beauty of Clojure isn't that you _don't_ need a strong 
academic background or even much exposure to FP to approach the 
language. Clojure is relatively free of FP jargon, instead we have 
"Rich Hickey Jargon". I jest :)


Very good.  And so far, my experience has borne this out.  It is 
approachable, elegant, immediately usable.  It's just that I am curious, 
so I would like to be able to have at least a basic idea of what these 
other conversations are about, even if I can't entirely follow every 
argument.


But seriously, in my personal opinion Monads are relatively useless in 
the context of Clojure. They are necessary in pure FP languages like 
Haskell because otherwise it's impossible get any real applications 
written. This is not to say they are not useful, you just don't need 
to know a damn thing about them to have fun in Clojure.


OK.  That puts it a bit more in perspective.  Also, once I was online 
again, I reached for Wikipedia to see if I could find an article written 
to be understood by those outside the field.  Actually, the first two 
paragraphs here were helpful to get at least a basic grasp of what 
Monads are about:


http://en.wikipedia.org/wiki/Monad_(functional_programming)

The overview here is certainly more readable than the foldoc entry I 
read, and it, in turn links to a page on monad as used in category 
theory which is, I am sure, readable by mathematicians, but which again 
left me scratching my head just as the foldoc entry had.  So I guess 
it's not so much FP that I find hard to grok as it is the math from 
which it has borrowed some terminology.


Having hacked on Clojure for a a year and half now I think the best 
approach is to learn those aspects of Clojure that are most useful to 
you. You certainly don't need to pick up everything at once. I still 
don't completely grok deftype/protocols or the more involved 
concurrency constructs. This hasn't stopped me from writing many 
useful programs.


Most useful to me, or at least most interesting ...  I can't say that at 
this point I can see where I'm going to use this.  But it certainly *is* 
intriguing ... including the bits that right now are a hard to follow at 
least in part due to the unfamiliar terms.


If you _do_ want to get deeper in Clojure's philosophy you can't beat 
Rich Hickey's Amazon Bookshelf.


I'm not sure at this point how deep I want to go.  Nice resource, though.

Ben


--
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: Simple functional programming lexicon?

2010-03-17 Thread Ben Armstrong

On 17/03/10 05:57 PM, eyeris wrote:

On Mar 17, 7:28 am, Ben Armstrong  wrote:
   

Or should I just ignore threads like "Why do functions in the state monad only 
accept one value?"
 

Yes, ignore those for now. Write an entire program in Clojure before
you read anything about monads. They aren't required.When I first
dipped my toes in the functional waters I learned a lot from "Casting
SPELs in LISP"[1]. It's based around Common Lisp, but it should be
easily translatable to Clojure.

[1] http://www.lisperati.com/casting.html
   


Nice!  I see there's a Ruby adaptation too, and *that*, at least, is 
familiar ground.


Cheers,
Ben

--
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: Name suggestions

2010-03-17 Thread pthatcher
I can't believe no one has suggested:

Najure.


On Mar 17, 8:00 am, David Nolen  wrote:
> yodel
>
>
>
> On Wed, Mar 17, 2010 at 3:08 AM, mac  wrote:
> > After just a little more test and polish I plan on calling clj-native
> > 1.0. But clj-native is a *really* boring name so I want to change it
> > before 1.0 and I don't have very good imagination when it comes to
> > these things.
> > So I need your help.
> > It doesn't have to have anything to do with anything, could just be
> > something that sounds funny, like sasquatch, that's a funny word.
>
> > Please help!
>
> > /Markus
>
> > On 13 mar, 19:14, mac  wrote:
> > > Hello all.
> > > I have had some time lately to work on my C FFI for Clojure and I
> > > think it's pretty much feature complete now.
> > > It has support for functions, callbacks, structures, unions and
> > > globals.
> > > For structures there is support for different alignments.
>
> > > The library has two main namespaces: clj-native.direct and clj-
> > > native.dynamic.
> > > The direct namespace uses the "direct mapping" feature of JNA in order
> > > to be as efficient and arity and type safe as possible. However, it
> > > does not support varargs functions since they require reflection and
> > > dynamic translation of the parameters. That's what the dynamic
> > > namespace is for: It can map any C function into clojure, even vararg
> > > functions like printf but at a higher cost in call time and less
> > > safety (it's easy to crash the jvm by sending the wrong type or number
> > > of parameters). Access to global variables through the JNA Pointer
> > > class is also available in the dynamic namespace.
>
> > > The library is available from github:
> >http://github.com/bagucode/clj-native
> > > and clojars:http://clojars.org/clj-native
>
> > > Example usage of the direct namespace can be found here:
> >http://github.com/bagucode/clj-native/blob/master/src/examples/c_lib.clj
>
> > > Please report issues or make requests to my github account or by mail.
>
> > > Enjoy!
>
> > > /Markus
>
> > --
> > 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: clj-native 0.8.1

2010-03-17 Thread pthatcher
I can't believe no one has suggested:

Najure.

On Mar 13, 11:14 am, mac  wrote:
> Hello all.
> I have had some time lately to work on my C FFI for Clojure and I
> think it's pretty much feature complete now.
> It has support for functions, callbacks, structures, unions and
> globals.
> For structures there is support for different alignments.
>
> The library has two main namespaces: clj-native.direct and clj-
> native.dynamic.
> The direct namespace uses the "direct mapping" feature of JNA in order
> to be as efficient and arity and type safe as possible. However, it
> does not support varargs functions since they require reflection and
> dynamic translation of the parameters. That's what the dynamic
> namespace is for: It can map any C function into clojure, even vararg
> functions like printf but at a higher cost in call time and less
> safety (it's easy to crash the jvm by sending the wrong type or number
> of parameters). Access to global variables through the JNA Pointer
> class is also available in the dynamic namespace.
>
> The library is available from github:http://github.com/bagucode/clj-native
> and clojars:http://clojars.org/clj-native
>
> Example usage of the direct namespace can be found 
> here:http://github.com/bagucode/clj-native/blob/master/src/examples/c_lib.clj
>
> Please report issues or make requests to my github account or by mail.
>
> Enjoy!
>
> /Markus

-- 
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: Name suggestions

2010-03-17 Thread Wilson MacGyver
hashi, means bridge in japanese

On Wed, Mar 17, 2010 at 3:08 AM, mac  wrote:
> After just a little more test and polish I plan on calling clj-native
> 1.0. But clj-native is a *really* boring name so I want to change it
> before 1.0 and I don't have very good imagination when it comes to
> these things.
> So I need your help.
> It doesn't have to have anything to do with anything, could just be
> something that sounds funny, like sasquatch, that's a funny word.
>
> Please help!
>
> /Markus
>
> On 13 mar, 19:14, mac  wrote:
>> Hello all.
>> I have had some time lately to work on my C FFI for Clojure and I
>> think it's pretty much feature complete now.
>> It has support for functions, callbacks, structures, unions and
>> globals.
>> For structures there is support for different alignments.
>>
>> The library has two main namespaces: clj-native.direct and clj-
>> native.dynamic.
>> The direct namespace uses the "direct mapping" feature of JNA in order
>> to be as efficient and arity and type safe as possible. However, it
>> does not support varargs functions since they require reflection and
>> dynamic translation of the parameters. That's what the dynamic
>> namespace is for: It can map any C function into clojure, even vararg
>> functions like printf but at a higher cost in call time and less
>> safety (it's easy to crash the jvm by sending the wrong type or number
>> of parameters). Access to global variables through the JNA Pointer
>> class is also available in the dynamic namespace.
>>
>> The library is available from github:http://github.com/bagucode/clj-native
>> and clojars:http://clojars.org/clj-native
>>
>> Example usage of the direct namespace can be found 
>> here:http://github.com/bagucode/clj-native/blob/master/src/examples/c_lib.clj
>>
>> Please report issues or make requests to my github account or by mail.
>>
>> Enjoy!
>>
>> /Markus
>
> --
> 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



-- 
Omnem crede diem tibi diluxisse supremum.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Simple functional programming lexicon?

2010-03-17 Thread Praki Prakash
I spent a lot of time trying to understand monads in Haskell, which led to
reading Category Theory. It's an alluring subject and one can spend a lot
time following the concepts and terminology. But, the good news is that, one
doesn't need an advanced degree in math to appreciate monads in FP. A really
helpful paper that explains the motivation for Monads is this:
http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf

As others have mentioned, Haskell is heavy in its use of monads and  many
other  algebraic structures. I don't know why the two languages feel so
different with respect to the level of formalism you need to use them. But,
Haskell is one of the most mind bending programming language there and well
worth the study.

Praki
On Wed, Mar 17, 2010 at 5:16 PM, Ben Armstrong  wrote:

> On 17/03/10 04:54 PM, David Nolen wrote:
>
>> To me the beauty of Clojure isn't that you _don't_ need a strong academic
>> background or even much exposure to FP to approach the language. Clojure is
>> relatively free of FP jargon, instead we have "Rich Hickey Jargon". I jest
>> :)
>>
>
> Very good.  And so far, my experience has borne this out.  It is
> approachable, elegant, immediately usable.  It's just that I am curious, so
> I would like to be able to have at least a basic idea of what these other
> conversations are about, even if I can't entirely follow every argument.
>
>  But seriously, in my personal opinion Monads are relatively useless in the
>> context of Clojure. They are necessary in pure FP languages like Haskell
>> because otherwise it's impossible get any real applications written. This is
>> not to say they are not useful, you just don't need to know a damn thing
>> about them to have fun in Clojure.
>>
>
> OK.  That puts it a bit more in perspective.  Also, once I was online
> again, I reached for Wikipedia to see if I could find an article written to
> be understood by those outside the field.  Actually, the first two
> paragraphs here were helpful to get at least a basic grasp of what Monads
> are about:
>
> http://en.wikipedia.org/wiki/Monad_(functional_programming)
>
> The overview here is certainly more readable than the foldoc entry I read,
> and it, in turn links to a page on monad as used in category theory which
> is, I am sure, readable by mathematicians, but which again left me
> scratching my head just as the foldoc entry had.  So I guess it's not so
> much FP that I find hard to grok as it is the math from which it has
> borrowed some terminology.
>
>  Having hacked on Clojure for a a year and half now I think the best
>> approach is to learn those aspects of Clojure that are most useful to you.
>> You certainly don't need to pick up everything at once. I still don't
>> completely grok deftype/protocols or the more involved concurrency
>> constructs. This hasn't stopped me from writing many useful programs.
>>
>
> Most useful to me, or at least most interesting ...  I can't say that at
> this point I can see where I'm going to use this.  But it certainly *is*
> intriguing ... including the bits that right now are a hard to follow at
> least in part due to the unfamiliar terms.
>
>  If you _do_ want to get deeper in Clojure's philosophy you can't beat Rich
>> Hickey's Amazon Bookshelf.
>>
>
> I'm not sure at this point how deep I want to go.  Nice resource, though.
>
> Ben
>
>
>
> --
> 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
>



-- 
http://www.google.com/profiles/praki.prakash

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