Reading clojure code of larger domain specific projects

2011-05-09 Thread Christian Schuhegger
Hello list,

I have a question that perhaps may be relevant for more people. I
strongly believe that reading code of other people is an undervalued
discipline of all developers. Typically it just happens as a side
effect of working in a project with other people. Like that a style of
development evolves in a programming language community.

You may think of projects written by other people what you like (well
done, poorly done), but I believe that it is always beneficial to read
code written by other people. I've done that in C++ and Java quite a
bit (ACE framework, TAO orb, STLport, Java Swing libraries, Java
Spring libraries, Apache Commons libraries, JBoss SEAM, ...).

I am writing programs in Common Lisp since 1995, but up to now I never
worked in Lisp projects with more than me being involved. There are
definitely many well written Lisp projects out there and books like
PAIP may definitely help, too, but I was wondering if there are any
larger domain specific open-source projects written in Clojure out
there that you would recommend for reading as some sort of best
practice guide? I was thinking about leiningen or cake, but I would
prefer projects that are closer to fulfilling a business purpose than
a technical purpose like a build system. If the project then also
would have a good documentation then that would be perfect :)

Any suggestions from your side?

Thanks,
Christian

-- 
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: Equivalent of Cyclic barrier

2011-05-09 Thread MohanR
Actually I think it is possible.

This is actually based on the Java documentation.

public class MyCyclicBarrier {

   private CyclicBarrier barrier;

   private boolean done = false;

   class Task implements Runnable {

 public void run() {

   while (!done) {

 try {
   long l = barrier.await();
   System.out.println( Thread indexed [ + l + ] has
run);
 } catch (InterruptedException ex) {
   return;
 } catch (BrokenBarrierException ex) {
   return;
 }
   }
 }
   }

   public void compute() {
 barrier = new CyclicBarrier( 10,
  new Runnable() {
   public void run() {
 done = true;
 System.out.println( Barrier
action - + Boolean.toString( done ));
   }
 });
 for (int i = 0; i  10; ++i){

 new Thread(new Task()).start();

 }

  while (!done) {

  System.out.println( Waiting till done);

  }

   }

 public static void main( String[] argv ){

 new  MyCyclicBarrier().compute();
 }


I think there is an base example found here. 
http://www.michaelharrison.ws/weblog/?p=239

Shouldn't I be directly translating java.util.concurrent to Clojure's
concurrency model because they are fundamentally different ?


-- 
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: Reading clojure code of larger domain specific projects

2011-05-09 Thread Chris Perkins
On May 9, 2:21 am, Christian Schuhegger
christian.schuheg...@gmail.com wrote:
 Hello list,

 I have a question that perhaps may be relevant for more people. I
 strongly believe that reading code of other people is an undervalued
 discipline of all developers. Typically it just happens as a side
 effect of working in a project with other people. Like that a style of
 development evolves in a programming language community.

 You may think of projects written by other people what you like (well
 done, poorly done), but I believe that it is always beneficial to read
 code written by other people. I've done that in C++ and Java quite a
 bit (ACE framework, TAO orb, STLport, Java Swing libraries, Java
 Spring libraries, Apache Commons libraries, JBoss SEAM, ...).

 I am writing programs in Common Lisp since 1995, but up to now I never
 worked in Lisp projects with more than me being involved. There are
 definitely many well written Lisp projects out there and books like
 PAIP may definitely help, too, but I was wondering if there are any
 larger domain specific open-source projects written in Clojure out
 there that you would recommend for reading as some sort of best
 practice guide? I was thinking about leiningen or cake, but I would
 prefer projects that are closer to fulfilling a business purpose than
 a technical purpose like a build system. If the project then also
 would have a good documentation then that would be perfect :)

 Any suggestions from your side?


I have been thinking for while that it would be great to have
something equivalent to book clubs for reading code. A group could
meet weekly, all having read the same moderate-sized project, and
discuss. I wonder if this could be made to work as a web-app, where
you can sign up, state your areas of interest, and have a weekly
reading assignment emailed. Then you could meet on IRC or something.
Just a thought.

Having said that, I don't have any specific suggestions for you, but
I'm also interested in seeing what answers you get.

- Chris Perkins

-- 
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: Order a sequence of maps with {:type :before [types]}

2011-05-09 Thread msappler
Hello Thanks for your answer.

Yes it should throw an exception - there should be no cyclic orders.

I want to use this for the initialisation functions of the game I am
developing (http://resatori.com/cyber-dungeon-quest-alpha-1)

There is a number of those functions and some need to come after some
others; most of them dont care about order.

I thougt about the best way to do is, is introducing an :after key and
a type.

So after the gui is initialized, i can add frames for example.

On 9 Mai, 07:07, Ken Wesson kwess...@gmail.com wrote:
 On Sun, May 8, 2011 at 10:56 PM, msappler damnedmar...@web.de wrote:
  I want to order a sequence of maps with keys:
  obligatory :type
  optional :before [types]; which means the types should occur before
  this element in the sequence.

 That's a quite complex and somewhat difficult problem.

 First of all, what if you have

 A: {:type :foo :before [:bar]}
 B: {:type :bar :before [:foo]}
 ?

 Which comes first then?

 Probably you should throw an Exception or an Error then because the
 constraints are unsatisfiable.

 More generally, the :before values create directed outbound edges of a
 directed graph and this needs to be acyclic. If it's cyclic you have a
 problem. Otherwise, you can order the nodes such that any node is
 left of any node it has an outbound edge to -- nodes with no
 outbound edges are at far right, nodes with outbound edges to them
 are one step to the left, nodes with outbound edges to those are two
 steps to the left, and so forth. This determines a partial order on
 the nodes by how-far-left, and you want to sort by this, and sort on
 :type as the tiebreaker within the nodes that are a particular
 distance left.

 Something like this:

 (defn subset? [a-seq a-set]
   (if a-seq
     (if (contains? a-set (first a-seq))
       (recur (next a-seq) a-set))
     true))

 (defn presort [node-seq]
   (loop [out nil nodes node-seq]
     (if (empty? nodes)
       out
       (let [toright (set (map :type (apply concat out)))
             nextnode? #(subset? (seq (:before %)) toright)
             nextnodes (filter nextnode? nodes)]
         (if (empty? nextnodes) (throw (Error. circularity)))
         (recur (cons nextnodes out) (remove nextnode? nodes))

 (defn sort [node-seq]
   (mapcat #(sort-by :type %) (presort node-seq)))

 user= (sort [{:type 1 :before [2 5]} {:type 2} {:type 3 :before [4]}
 {:type 4 :before []} {:type 5 :before [4]}])
 ({:type 1,
   :before [2 5]}
  {:type 3,
   :before [4]}
  {:type 5,
   :before [4]}
  {:type 2}
  {:type 4,
   :before []})
 user=

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


Re: ANN: Jark 0.3 (using the nrepl protocol)

2011-05-09 Thread Chas Emerick

On May 7, 2011, at 1:31 PM, David Nolen wrote:

 On Sat, May 7, 2011 at 12:50 PM, isaac praveen icylis...@gmail.com wrote:
 Sure. We need very powerful clojure development and deployment tools.
 My request for subscription to clojure-dev got declined :(
 
 Send in a CA! :)

Yes, that would explain that.  In any case, all contributors to jark will need 
to have CA's lodged before it (or parts of it) can be brought into Clojure 
contrib.

http://clojure.org/contributing

- Chas

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

Creating instances of types not known at compile time

2011-05-09 Thread Simon Katz
I'm trying to implement a function similar to new, but where
the type is not known at compile time -- so I want to evaluate
the first argument.

With the help of Google, I found the approach used in new*
below:

(ns dynamic-new)

(defn new* [type-name-as-symbol  args]
  (clojure.lang.Reflector/invokeConstructor
   (resolve type-name-as-symbol)
   (to-array args)))

In simple situations it works ok:

(ns my-namespace
  (:refer dynamic-new))

(defrecord MyRecord [a b c])

(= (new MyRecord 1 2 3)
   (new* 'MyRecord 1 2 3)
   (new* 'my-namespace.MyRecord 1 2 3))
= true

(= (new java.util.Date 0 0 1)
   (new* 'java.util.Date 0 0 1))
= true

But there's a problem with unqualified symbols.
Continuing with definitions in my-namespace...

(defn instantiate-qualified []
  (new* 'my-namespace.MyRecord 1 2 3))

(defn instantiate-unqualified []
  (new* 'MyRecord 1 2 3))

(defn both-funs-same? []
  (= (instantiate-qualified)
 (instantiate-unqualified)))

(both-funs-same?)
= true

OK -- no surprises above.

But...

(ns another-namespace)
(try (do (my-namespace/instantiate-unqualified)
 succeeded)
 (catch Exception e failed))
= failed

In another-namespace, the call of my-namespace/instantiate-unqualified
fails because there is no data type or class named MyRecord in that
namespace.

And...

(ns a-namespace-with-a-different-MyRecord)
(defrecord MyRecord [a b c]) ; two MyRecords in different
namespaces
(my-namespace/instantiate-unqualified)
= #:a-namespace-with-a-different-MyRecord.MyRecord{:a 1, :b 2, :c
3}

So, the function my-namespace/instantiate-unqualified has created
an instance of a-namespace-with-a-different-MyRecord.MyRecord.
This could be a source of confusing bugs.

Now my questions:

Q1. Is this basically the right approach, or is there some other
way to implement new*?

Q2. I can use syntax-quote to qualify a symbol at read time:
(defn instantiate-unqualified []
  (new* `MyRecord 1 2 3))
Is that the right way to go?

Q3. It might be a good idea to check in new* that the symbol passed
to it is qualified.  In combination with the use of syntax-quote,
this might be a good solution.  Is there a way to check for this?
(Perhaps checking whether the symbol's name contains a .?  But
(a) that's slow and (b) I'm not sure it's good enough.)

I had thought that I might be able to use the namespace function
to check this, because
(namespace 'my-namespace/foo) = my-namespace
but unfortunately
(namespace 'my-namespace.MyRecord) = nil

Q4. Given that symbols containing . are qualified, is
(namespace 'my-namespace.MyRecord) = nil
correct behaviour?
(I think I don't fully understand symbols containing . but
not /.)

Q5. I've seen the phrase fully-qualified symbol used in a few
places.  Does this simply mean qualified symbol?  If there
is such a thing as a partially-qualified symbol, checking
that a symbol is qualified may not help.

Simon

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


Efficient moving average

2011-05-09 Thread Andreas Kostler
Hi all,
I'm trying to calculate the moving average of a certain window size.
One straight forward approach is:
(defn lazy-avg [coll]
  (let [[sum cnt] (reduce
   (fn [[v c] val] [(+ val v) (inc c)])
   [0 0]
   coll)]
(if (zero? cnt) 0 (/ sum cnt

(let [window-size 5
  n 100]
  (map lazy-avg (partition window-size 1 (range 0 n)))

This takes about 2 seconds for 10^6 elements on my box. How can I
improve the runtime?
A slightly more performant (not much) approach keeping a rolling sum
would be:

(defn partialsums [start lst]
  (lazy-seq
(if-let [lst (seq lst)]
  (cons start (partialsums (+ start (first lst)) (rest lst)))
  (list start

(defn sliding-window-moving-average [window lst]
  (map #(/ % window)
   (let [start   (apply + (take window lst))
 diffseq (map - (drop window lst) lst)]
 (partialsums start diffseq

However, this causes the jvm to run out of heap space for n  10^6

Is ~ 2 seconds the best I can do?

Cheers
Andreas

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


Re: Hi, simple problem from a newbie

2011-05-09 Thread Jonathan Fischer Friberg
I recommend reading a book about lisp.
I liked land of lisp:
http://landoflisp.com/

Practical common lisp should be good as well:
http://www.gigamonkeys.com/book/

Some more:
http://www.cliki.net/Lisp%20books

When you have an understanding of lisp, you can move on to clojure.
Practical clojure works well for introducing clojure, and it also works well
as a reference.
http://www.amazon.com/Practical-Clojure-Experts-Voice-Source/dp/1430272317

Of course, reading these books are very overkill if you only want to try
clojure out, but I found it hard to successfully be able to program anything
(I as you, felt lost) before I read land of lisp + practical clojure.

Have fun
Jonathan

On Mon, May 9, 2011 at 3:46 AM, Sean Corfield seancorfi...@gmail.comwrote:

 On Sun, May 8, 2011 at 4:59 PM, iamcreasy quazir...@gmail.com wrote:
  Hi everybody :)

 Welcome!

  I am an experienced C++ programmer. Recently I decided to try out
  clojure(I have some java experience).

 My background was C++ for most of the 90's then Java for quite a bit
 of the 00's so I expect you're finding the hardest part of learning
 Clojure is adjusting to a functional approach with immutable data?

  I read some tutorials of the basics clojure. Now I want to implement
  some simple algorithms. Starting with Insertion sort.

 There are two parts to the problem:
 * given an item and a sorted list, return a new list with the item
 inserted in the correct place
 * given a list of unsorted items, repeatedly perform the first part

 For the sorted insert:
 * if the sorted list is empty, return a new list with just the new item
 * else if the new item is less than the first item in the sorted list,
 return a new list: (cons new-item sorted-list)
 * else return a new list: (cons (first sorted-list) (sorted-insert
 new-item (rest list)))

 To repeatedly perform the insertion, try a loop with three variables:
 next item to insert, remaining items to insert, sorted list so far...

 Hope that helps you get started?
 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/
 World Singles, LLC. -- http://worldsingles.com/
 Railo Technologies, Inc. -- http://www.getrailo.com/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)

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


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

Re: ANN: Jark 0.3 (using the nrepl protocol)

2011-05-09 Thread isaac praveen
 Yes, that would explain that.  In any case, all contributors to jark will
 need to have CA's lodged before it (or parts of it) can be brought into
 Clojure contrib.
 http://clojure.org/contributing
 - Chas

Thanks Chas.

Ambrose and myself will send the CA across.

-- 
isaac

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


CfP: IEEE Software Special Issue: Algorithms and Today’s Practitioner

2011-05-09 Thread Cesare
~~
IEEE Software
Special Issue
Algorithms and Today’s Practitioner
Call for Papers
~~

IEEE Software seeks submissions for a special issue on the topic of
Algorithms and Today’s Practitioner, with
the aim of bringing the message to today’s practitioners that the
everyday relevance of algorithms to software
engineers is clear and present. This issue will focus on the central
role of algorithms in the software engineering
community, bringing both a historical perspective on breakthrough
algorithms that have enabled entire industrial
sectors to advance and a contemporary perspective on algorithms in
everyday industrial practice.
We encourage contributions that stress the relevance of algorithms to
modern topics in software engineering
that survey modern algorithmic accomplishment, and that highlight the
central role of algorithms in today’s
software engineering practice. Also, we seek articles that give a
general overview of the main algorithmic
approaches and libraries adopted in real-world applications of
interest for the software engineering community,
thus providing a useful tool that would help in the selection of the
appropriate solutions in today’s practitioner
work. Areas of particular interest include:

- Overview articles of key areas in which algorithmic advances have
made possible the emergence and
growth of significant business sectors (e.g. computer graphics,
search, massively parallel computing,
etc.)
- Articles on the practical selection and utilization of algorithms in
everyday industrial projects in order to
elevate and guarantee the quality of products and services produced.
- Articles on new paradigms and techniques for communicating
algorithms to practitioners, much as the
design pattern paradigm opened the way for the communication of
software design principles.
- Articles on important packages and delivery mechanisms for
algorithms to today’s development
environments, including best practices and approaches for their
design.
- Articles on modern teaching approaches that expose students and
practitioners to compelling real-world
applications of algorithmic techniques.

Potential authors are reminded of the practitioner-related mission of
IEEE Software and that theoretical, formula-
laden presentations of specific algorithmic topics are considered to
be out of scope and may be rejected without
refereeing.

Manuscripts must not exceed 5,400 words including figures and tables,
which count for 200 words each.
Submissions in excess of these limits may be rejected without
refereeing. The articles we deem within the
theme's scope will be peer-reviewed and are subject to editing for
magazine style, clarity, organization, and
space. We reserve the right to edit the title of all submissions. Be
sure to include the name of the theme you are
submitting for. Articles must be submitted on the IEEE Software author
submission site.

Papers must be submitted no later than 1 June 2011; publication is
scheduled for January/February 2012.

Guest Editors:
Giuseppe Prencipe, Dipartimento di Informatica, Università di Pisa —
prenc...@di.unipi.it
John Favaro, INTECS SpA — john.fav...@intecs.it
Alessandro Tommasi, Comprendo Srl — a.tomm...@comprendo.it
Cesare Zavattari, Comprendo Srl — c.zavatt...@comprendo.it

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


Re: Creating instances of types not known at compile time

2011-05-09 Thread Jonathan Fischer Friberg
Q1 This macro captures the correct namespace:

(defmacro new* [type-name-as-symbol  args]
  `(clojure.lang.Reflector/invokeConstructor
 (ns-resolve ~*ns* ~type-name-as-symbol)
 (to-array '~args)))

Q2 Backquote ` is unnecessary for symbols, use standard quote '

Q3 Answer to 1 fixes this

Q4 I'm not entirely sure, but roughly:
. means namespace (or class!)
/ means field in namespace (or class!)
That is why you have to use . for records, since records generate classes.

Q5 I guess?

Jonathan

On Mon, May 9, 2011 at 2:00 PM, Simon Katz nomisk...@gmail.com wrote:

 I'm trying to implement a function similar to new, but where
 the type is not known at compile time -- so I want to evaluate
 the first argument.

 With the help of Google, I found the approach used in new*
 below:

(ns dynamic-new)

(defn new* [type-name-as-symbol  args]
  (clojure.lang.Reflector/invokeConstructor
   (resolve type-name-as-symbol)
   (to-array args)))

 In simple situations it works ok:

(ns my-namespace
  (:refer dynamic-new))

(defrecord MyRecord [a b c])

(= (new MyRecord 1 2 3)
   (new* 'MyRecord 1 2 3)
   (new* 'my-namespace.MyRecord 1 2 3))
= true

(= (new java.util.Date 0 0 1)
   (new* 'java.util.Date 0 0 1))
= true

 But there's a problem with unqualified symbols.
 Continuing with definitions in my-namespace...

(defn instantiate-qualified []
  (new* 'my-namespace.MyRecord 1 2 3))

(defn instantiate-unqualified []
  (new* 'MyRecord 1 2 3))

(defn both-funs-same? []
  (= (instantiate-qualified)
 (instantiate-unqualified)))

(both-funs-same?)
= true

 OK -- no surprises above.

 But...

(ns another-namespace)
(try (do (my-namespace/instantiate-unqualified)
 succeeded)
 (catch Exception e failed))
= failed

 In another-namespace, the call of my-namespace/instantiate-unqualified
 fails because there is no data type or class named MyRecord in that
 namespace.

 And...

(ns a-namespace-with-a-different-MyRecord)
(defrecord MyRecord [a b c]) ; two MyRecords in different
 namespaces
(my-namespace/instantiate-unqualified)
= #:a-namespace-with-a-different-MyRecord.MyRecord{:a 1, :b 2, :c
 3}

 So, the function my-namespace/instantiate-unqualified has created
 an instance of a-namespace-with-a-different-MyRecord.MyRecord.
 This could be a source of confusing bugs.

 Now my questions:

 Q1. Is this basically the right approach, or is there some other
way to implement new*?

 Q2. I can use syntax-quote to qualify a symbol at read time:
(defn instantiate-unqualified []
  (new* `MyRecord 1 2 3))
Is that the right way to go?

 Q3. It might be a good idea to check in new* that the symbol passed
to it is qualified.  In combination with the use of syntax-quote,
this might be a good solution.  Is there a way to check for this?
(Perhaps checking whether the symbol's name contains a .?  But
(a) that's slow and (b) I'm not sure it's good enough.)

I had thought that I might be able to use the namespace function
to check this, because
(namespace 'my-namespace/foo) = my-namespace
but unfortunately
(namespace 'my-namespace.MyRecord) = nil

 Q4. Given that symbols containing . are qualified, is
(namespace 'my-namespace.MyRecord) = nil
correct behaviour?
(I think I don't fully understand symbols containing . but
not /.)

 Q5. I've seen the phrase fully-qualified symbol used in a few
places.  Does this simply mean qualified symbol?  If there
is such a thing as a partially-qualified symbol, checking
that a symbol is qualified may not help.

 Simon

 --
 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: clojure.java.jdbc 0.0.1 released

2011-05-09 Thread Armando Blancas
Yeap. Release numbers have become meaningless; your point is well
taken.

On May 8, 7:11 pm, Sean Corfield seancorfi...@gmail.com wrote:
 The library formerly known as clojure.contrib.sql has had it's first
 non-snapshot release.

 Features added:
 * returns generated keys for single record inserts
 * supports naming strategies to allow to override the conversion of
 keywords to/from SQL entity names
   * exposes resultset-seq that respects naming strategies
 * exposes print-* functions to print SQL exceptions (and no longer
 prints to *err* on an exception)

 More on naming strategies:

 https://github.com/clojure/java.jdbc/blob/master/doc/clojure/java/jdb...

 If you start using this with Clojure 1.3.0 and find bugs or think of
 enhancements, please enter them here:

 http://dev.clojure.org/jira/browse/JDBC
 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View --http://corfield.org/
 World Singles, LLC. --http://worldsingles.com/
 Railo Technologies, Inc. --http://www.getrailo.com/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)

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


Re: Creating instances of types not known at compile time

2011-05-09 Thread Jonathan Fischer Friberg
Never mind Q2, I didn't understand the question correctly.

Jonathan

On Mon, May 9, 2011 at 5:21 PM, Jonathan Fischer Friberg 
odysso...@gmail.com wrote:

 Q1 This macro captures the correct namespace:

 (defmacro new* [type-name-as-symbol  args]
   `(clojure.lang.Reflector/invokeConstructor
  (ns-resolve ~*ns* ~type-name-as-symbol)
  (to-array '~args)))

 Q2 Backquote ` is unnecessary for symbols, use standard quote '

 Q3 Answer to 1 fixes this

 Q4 I'm not entirely sure, but roughly:
 . means namespace (or class!)
 / means field in namespace (or class!)
 That is why you have to use . for records, since records generate classes.

 Q5 I guess?

 Jonathan


 On Mon, May 9, 2011 at 2:00 PM, Simon Katz nomisk...@gmail.com wrote:

 I'm trying to implement a function similar to new, but where
 the type is not known at compile time -- so I want to evaluate
 the first argument.

 With the help of Google, I found the approach used in new*
 below:

(ns dynamic-new)

(defn new* [type-name-as-symbol  args]
  (clojure.lang.Reflector/invokeConstructor
   (resolve type-name-as-symbol)
   (to-array args)))

 In simple situations it works ok:

(ns my-namespace
  (:refer dynamic-new))

(defrecord MyRecord [a b c])

(= (new MyRecord 1 2 3)
   (new* 'MyRecord 1 2 3)
   (new* 'my-namespace.MyRecord 1 2 3))
= true

(= (new java.util.Date 0 0 1)
   (new* 'java.util.Date 0 0 1))
= true

 But there's a problem with unqualified symbols.
 Continuing with definitions in my-namespace...

(defn instantiate-qualified []
  (new* 'my-namespace.MyRecord 1 2 3))

(defn instantiate-unqualified []
  (new* 'MyRecord 1 2 3))

(defn both-funs-same? []
  (= (instantiate-qualified)
 (instantiate-unqualified)))

(both-funs-same?)
= true

 OK -- no surprises above.

 But...

(ns another-namespace)
(try (do (my-namespace/instantiate-unqualified)
 succeeded)
 (catch Exception e failed))
= failed

 In another-namespace, the call of my-namespace/instantiate-unqualified
 fails because there is no data type or class named MyRecord in that
 namespace.

 And...

(ns a-namespace-with-a-different-MyRecord)
(defrecord MyRecord [a b c]) ; two MyRecords in different
 namespaces
(my-namespace/instantiate-unqualified)
= #:a-namespace-with-a-different-MyRecord.MyRecord{:a 1, :b 2, :c
 3}

 So, the function my-namespace/instantiate-unqualified has created
 an instance of a-namespace-with-a-different-MyRecord.MyRecord.
 This could be a source of confusing bugs.

 Now my questions:

 Q1. Is this basically the right approach, or is there some other
way to implement new*?

 Q2. I can use syntax-quote to qualify a symbol at read time:
(defn instantiate-unqualified []
  (new* `MyRecord 1 2 3))
Is that the right way to go?

 Q3. It might be a good idea to check in new* that the symbol passed
to it is qualified.  In combination with the use of syntax-quote,
this might be a good solution.  Is there a way to check for this?
(Perhaps checking whether the symbol's name contains a .?  But
(a) that's slow and (b) I'm not sure it's good enough.)

I had thought that I might be able to use the namespace function
to check this, because
(namespace 'my-namespace/foo) = my-namespace
but unfortunately
(namespace 'my-namespace.MyRecord) = nil

 Q4. Given that symbols containing . are qualified, is
(namespace 'my-namespace.MyRecord) = nil
correct behaviour?
(I think I don't fully understand symbols containing . but
not /.)

 Q5. I've seen the phrase fully-qualified symbol used in a few
places.  Does this simply mean qualified symbol?  If there
is such a thing as a partially-qualified symbol, checking
that a symbol is qualified may not help.

 Simon

 --
 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: Reading clojure code of larger domain specific projects

2011-05-09 Thread Jonathan Fischer Friberg
I'm interested!

The clojure source code is a pretty good read, hehe

Jonathan

https://github.com/clojure/clojure/tree/master/src/clj/clojure

On Mon, May 9, 2011 at 12:24 PM, Chris Perkins chrisperkin...@gmail.comwrote:

 On May 9, 2:21 am, Christian Schuhegger
 christian.schuheg...@gmail.com wrote:
  Hello list,
 
  I have a question that perhaps may be relevant for more people. I
  strongly believe that reading code of other people is an undervalued
  discipline of all developers. Typically it just happens as a side
  effect of working in a project with other people. Like that a style of
  development evolves in a programming language community.
 
  You may think of projects written by other people what you like (well
  done, poorly done), but I believe that it is always beneficial to read
  code written by other people. I've done that in C++ and Java quite a
  bit (ACE framework, TAO orb, STLport, Java Swing libraries, Java
  Spring libraries, Apache Commons libraries, JBoss SEAM, ...).
 
  I am writing programs in Common Lisp since 1995, but up to now I never
  worked in Lisp projects with more than me being involved. There are
  definitely many well written Lisp projects out there and books like
  PAIP may definitely help, too, but I was wondering if there are any
  larger domain specific open-source projects written in Clojure out
  there that you would recommend for reading as some sort of best
  practice guide? I was thinking about leiningen or cake, but I would
  prefer projects that are closer to fulfilling a business purpose than
  a technical purpose like a build system. If the project then also
  would have a good documentation then that would be perfect :)
 
  Any suggestions from your side?
 

 I have been thinking for while that it would be great to have
 something equivalent to book clubs for reading code. A group could
 meet weekly, all having read the same moderate-sized project, and
 discuss. I wonder if this could be made to work as a web-app, where
 you can sign up, state your areas of interest, and have a weekly
 reading assignment emailed. Then you could meet on IRC or something.
 Just a thought.

 Having said that, I don't have any specific suggestions for you, but
 I'm also interested in seeing what answers you get.

 - Chris Perkins

 --
 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: CfP: IEEE Software Special Issue: Algorithms and Today’s Practitioner

2011-05-09 Thread Cesare
Please disregard the previous version as this is the one containing
full submission information:

Call for Submissions

IEEE Software - Special Issue on Algorithms for Today's Practitioner

Submissions due: 1st June 2011

Publication date: January/February 2012

IEEE Software seeks submissions for a special issue on the topic of
Algorithms and Today's Practitioner, with the aim of bringing the
message to today's practitioners that the everyday relevance of
algorithms to software engineers is clear and present. This issue will
focus on the central role of algorithms in the software engineering
community, bringing both a historical perspective on breakthrough
algorithms that have enabled entire industrial sectors to advance and
a
contemporary perspective on algorithms in everyday industrial
practice.

We encourage contributions that stress the relevance of algorithms to
modern topics in software engineering that survey modern algorithmic
accomplishment, and that highlight the central role of algorithms in
today's software engineering practice. Also, we seek articles that
give
a general overview of the main algorithmic approaches and libraries
adopted in real-world applications of interest for the software
engineering community, thus providing a useful tool that would help in
the selection of the appropriate solutions in today's practitioner
work.
Areas of particular interest include:

- Overview articles of key areas in which algorithmic advances have
made
possible the emergence and growth of significant business sectors
(e.g.
computer graphics, search, massively parallel computing, etc.)
- Articles on the practical selection and utilization of algorithms in
everyday industrial projects in order to elevate and guarantee the
quality of products and services produced.
- Articles on new paradigms and techniques for communicating
algorithms
to practitioners, much as the design pattern paradigm opened the way
for
the communication of software design principles.
- Articles on important packages and delivery mechanisms for
algorithms
to today's development environments, including best practices and
approaches for their design.
- Articles on modern teaching approaches that expose students and
practitioners to compelling real-world applications of algorithmic
techniques.

Potential authors are reminded of the practitioner-related mission of
IEEE Software and that theoretical, formula-laden presentations of
specific algorithmic topics are considered to be out of scope and may
be
rejected without refereeing.

Special Issue Guest Editors

Giuseppe Prencipe, Dipartimento di Informatica, Università di Pisa -
prenc...@di.unipi.it
John Favaro, INTECS SpA - john.fav...@intecs.it
Alessandro Tommasi, Comprendo Srl - a.tomm...@comprendo.it
Cesare Zavattari, Comprendo Srl - c.zavatt...@comprendo.it

Submission Information

Manuscripts must not exceed 4,700 words including figures and tables,
which count for 200 words each. Submissions in excess of these limits
may be rejected without refereeing. The articles we deem within the
theme's scope will be peer reviewed and are subject to editing for
magazine style, clarity, organization, and space. We reserve the right
to edit the title of all submissions. Be sure to include the name of
the
theme or special issue you are submitting for.

Articles should have a practical orientation and be written in a style
accessible to practitioners. Articles should be novel. IEEE Software
does not republish material published previously in other venues,
including other periodicals and formal conference/workshop
proceedings,
whether previous publication was in print or in electronic form.

- For full author guidelines: www.computer.org/software/author.htm
- For more information about the focus: Giuseppe Prencipe, Università
di Pisa, prenc...@di.unipi.it
- For submission details: softw...@computer.org
- To submit an article: https://mc.manuscriptcentral.com/sw-cs

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


Re: Creating instances of types not known at compile time

2011-05-09 Thread Simon Katz
On Mon, May 9, 2011 at 16:21, Jonathan Fischer Friberg
odysso...@gmail.comwrote:

 Q1 This macro captures the correct namespace:

 (defmacro new* [type-name-as-symbol  args]
   `(clojure.lang.Reflector/invokeConstructor
  (ns-resolve ~*ns* ~type-name-as-symbol)
  (to-array '~args)))


Unfortunately that doesn't work -- it captures the namespace in which new*
is called, but that may not be where the symbol is actually written.
 Consider this:

(ns my-namespace
  (:refer dynamic-new))

(defrecord MyRecord [a b c])

(defn instantiate-using-parameter [type-name-as-symbol]
  (new* type-name-as-symbol 1 2 3))

(in-ns 'another-namespace)
(my-namespace/instantiate-using-parameter 'MyRecord)
= #:my-namespace.MyRecord{:a 1, :b 2, :c 3}

Again, the use of syntax-quote would qualify the symbol in the right
namespace -- the one containing the source of the symbol.

Simon

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

Re: Creating instances of types not known at compile time

2011-05-09 Thread Shantanu Kumar
Have you considered factory functions and macros? Macros might suit
better if you are dealing with various records.

(defmacro instance
  ([^Class c]
`(new ~c))
  ([^Class c  more]
`(new ~c ~@more)))

Since macros are expanded, qualified vs unqualified issue will be
taken care of automatically - i.e. the place where you use the macro
should have import'ed the class. Couple this with factory functions
and you may not even need to import the classes. Maybe if you can
share the use case you are trying to address, that would help
understand it better.

Regards,
Shantanu

On May 9, 5:00 pm, Simon Katz nomisk...@gmail.com wrote:
 I'm trying to implement a function similar to new, but where
 the type is not known at compile time -- so I want to evaluate
 the first argument.

 With the help of Google, I found the approach used in new*
 below:

     (ns dynamic-new)

     (defn new* [type-name-as-symbol  args]
       (clojure.lang.Reflector/invokeConstructor
        (resolve type-name-as-symbol)
        (to-array args)))

 In simple situations it works ok:

     (ns my-namespace
       (:refer dynamic-new))

     (defrecord MyRecord [a b c])

     (= (new MyRecord 1 2 3)
        (new* 'MyRecord 1 2 3)
        (new* 'my-namespace.MyRecord 1 2 3))
     = true

     (= (new java.util.Date 0 0 1)
        (new* 'java.util.Date 0 0 1))
     = true

 But there's a problem with unqualified symbols.
 Continuing with definitions in my-namespace...

     (defn instantiate-qualified []
       (new* 'my-namespace.MyRecord 1 2 3))

     (defn instantiate-unqualified []
       (new* 'MyRecord 1 2 3))

     (defn both-funs-same? []
       (= (instantiate-qualified)
          (instantiate-unqualified)))

     (both-funs-same?)
     = true

 OK -- no surprises above.

 But...

     (ns another-namespace)
     (try (do (my-namespace/instantiate-unqualified)
              succeeded)
          (catch Exception e failed))
     = failed

 In another-namespace, the call of my-namespace/instantiate-unqualified
 fails because there is no data type or class named MyRecord in that
 namespace.

 And...

     (ns a-namespace-with-a-different-MyRecord)
     (defrecord MyRecord [a b c]) ; two MyRecords in different
 namespaces
     (my-namespace/instantiate-unqualified)
     = #:a-namespace-with-a-different-MyRecord.MyRecord{:a 1, :b 2, :c
 3}

 So, the function my-namespace/instantiate-unqualified has created
 an instance of a-namespace-with-a-different-MyRecord.MyRecord.
 This could be a source of confusing bugs.

 Now my questions:

 Q1. Is this basically the right approach, or is there some other
     way to implement new*?

 Q2. I can use syntax-quote to qualify a symbol at read time:
         (defn instantiate-unqualified []
           (new* `MyRecord 1 2 3))
     Is that the right way to go?

 Q3. It might be a good idea to check in new* that the symbol passed
     to it is qualified.  In combination with the use of syntax-quote,
     this might be a good solution.  Is there a way to check for this?
     (Perhaps checking whether the symbol's name contains a .?  But
     (a) that's slow and (b) I'm not sure it's good enough.)

     I had thought that I might be able to use the namespace function
     to check this, because
         (namespace 'my-namespace/foo) = my-namespace
     but unfortunately
         (namespace 'my-namespace.MyRecord) = nil

 Q4. Given that symbols containing . are qualified, is
         (namespace 'my-namespace.MyRecord) = nil
     correct behaviour?
     (I think I don't fully understand symbols containing . but
     not /.)

 Q5. I've seen the phrase fully-qualified symbol used in a few
     places.  Does this simply mean qualified symbol?  If there
     is such a thing as a partially-qualified symbol, checking
     that a symbol is qualified may not help.

 Simon

-- 
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: Reading clojure code of larger domain specific projects

2011-05-09 Thread Meikel Brandmeyer
Hi,

Am 09.05.2011 um 17:36 schrieb Jonathan Fischer Friberg:

 I'm interested!
 
 The clojure source code is a pretty good read, hehe
 
 Jonathan
 
 https://github.com/clojure/clojure/tree/master/src/clj/clojure

Although the code in the preamble of core there is explicitly *not* recommended 
to be taken as example for “good” code. 
http://dev.clojure.org/display/design/Library+Coding+Standards

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: Creating instances of types not known at compile time

2011-05-09 Thread Jonathan Fischer Friberg
Well, that's sort of wanting to eat the cake and have it.
It's impossible to resolve a symbol where it isn't known where it came from,
if any resolving is to take place, it must assume to be in the current
namespace.

So yes, you're right; syntax-quote would work best here.

Jonathan


On Mon, May 9, 2011 at 5:41 PM, Simon Katz nomisk...@gmail.com wrote:

 On Mon, May 9, 2011 at 16:21, Jonathan Fischer Friberg 
 odysso...@gmail.com wrote:

 Q1 This macro captures the correct namespace:

 (defmacro new* [type-name-as-symbol  args]
   `(clojure.lang.Reflector/invokeConstructor
  (ns-resolve ~*ns* ~type-name-as-symbol)
  (to-array '~args)))


 Unfortunately that doesn't work -- it captures the namespace in which new*
 is called, but that may not be where the symbol is actually written.
  Consider this:

 (ns my-namespace
   (:refer dynamic-new))

 (defrecord MyRecord [a b c])

 (defn instantiate-using-parameter [type-name-as-symbol]
   (new* type-name-as-symbol 1 2 3))

 (in-ns 'another-namespace)
 (my-namespace/instantiate-using-parameter 'MyRecord)
 = #:my-namespace.MyRecord{:a 1, :b 2, :c 3}

 Again, the use of syntax-quote would qualify the symbol in the right
 namespace -- the one containing the source of the symbol.

 Simon

 --
 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: Creating instances of types not known at compile time

2011-05-09 Thread Chris Perkins
On May 9, 8:00 am, Simon Katz nomisk...@gmail.com wrote:
 I'm trying to implement a function similar to new, but where
 the type is not known at compile time -- so I want to evaluate
 the first argument.

 With the help of Google, I found the approach used in new*
 below:

     (ns dynamic-new)

     (defn new* [type-name-as-symbol  args]
       (clojure.lang.Reflector/invokeConstructor
        (resolve type-name-as-symbol)
        (to-array args)))

 Now my questions:

 Q1. Is this basically the right approach, or is there some other
     way to implement new*?


Is there a reason that you need to pass a symbol, rather than the
Class object itself?  eg:

(defrecord Foo [a b])

(defn new* [klass  args]
  (clojure.lang.Reflector/invokeConstructor klass (to-array args)))

(new* Foo 23 hello)
#:user.Foo{:a 23, :b hello}


- Chris Perkins

-- 
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: Reading clojure code of larger domain specific projects

2011-05-09 Thread gaz jones
compojure is often put forward as an example of good idiomatic clojure code:

https://github.com/weavejester/compojure

On Mon, May 9, 2011 at 10:55 AM, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 Am 09.05.2011 um 17:36 schrieb Jonathan Fischer Friberg:

 I'm interested!

 The clojure source code is a pretty good read, hehe

 Jonathan

 https://github.com/clojure/clojure/tree/master/src/clj/clojure

 Although the code in the preamble of core there is explicitly *not* 
 recommended to be taken as example for “good” code. 
 http://dev.clojure.org/display/design/Library+Coding+Standards

 Sincerely
 Meikel

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

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


Re: Reading clojure code of larger domain specific projects

2011-05-09 Thread Stuart Sierra
The code is somewhat out-of-date by now (pre-1.0 Clojure) but I wrote much 
of AltLaw.org in Clojure:

https://github.com/stuartsierra/altlaw-template
https://github.com/stuartsierra/altlaw-clojure-restlet
https://github.com/stuartsierra/altlaw-crawler
https://github.com/stuartsierra/altlaw-backend

-Stuart Sierra
clojure.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: Creating instances of types not known at compile time

2011-05-09 Thread Alan
On May 9, 9:50 am, Chris Perkins chrisperkin...@gmail.com wrote:
 On May 9, 8:00 am, Simon Katz nomisk...@gmail.com wrote:
  I'm trying to implement a function similar to new, but where
  the type is not known at compile time -- so I want to evaluate
  the first argument.

  With the help of Google, I found the approach used in new*
  below:

      (ns dynamic-new)

      (defn new* [type-name-as-symbol  args]
        (clojure.lang.Reflector/invokeConstructor
         (resolve type-name-as-symbol)
         (to-array args)))
  Now my questions:

  Q1. Is this basically the right approach, or is there some other
      way to implement new*?

 Is there a reason that you need to pass a symbol, rather than the
 Class object itself?  eg:

 (defrecord Foo [a b])

 (defn new* [klass  args]
   (clojure.lang.Reflector/invokeConstructor klass (to-array args)))

 (new* Foo 23 hello)
 #:user.Foo{:a 23, :b hello}

 - Chris Perkins

A mild gripe: we're in a language that doesn't make us use ugly names
like klass and clazz. Some will disagree with me for sure, but I think
it's more readable to simply use the symbol class when you're
talking about a class. If you disagree, by all means continue to use
klass; I'm just trying to prevent someone sticking with old java
habits because they don't realize they have a choice.

As to the content: yes, passing a class (which will get resolved in
the right namespace) is much much easier than passing a symbol and
then trying to resolve it by magic.

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


Re: ANN: A Clojure library for the Facebook Graph API - clj-facebook-graph

2011-05-09 Thread Bojan Jovičić
Hi Max,
I have started investigating this, and it works very nice. 

I am a noob in Clojure/Java and I have a question about posting to FB using 
your library. I tried something like this:

*(def auth-token (facebook-auth-by-name))
(def auth-name (first (keys auth-token)))
(with-facebook-auth-by-name auth-name (fb-get [:me :feed (str message= 
test)]))
*
But it seems not to work for processing parameters. The documentation for 
posting to FB is 
herehttp://developers.facebook.com/docs/reference/api/post/(bottom of the 
page).

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

Re: Creating instances of types not known at compile time

2011-05-09 Thread Chris Perkins
On May 9, 1:49 pm, Alan a...@malloys.org wrote:
 On May 9, 9:50 am, Chris Perkins chrisperkin...@gmail.com wrote:

 A mild gripe: we're in a language that doesn't make us use ugly names
 like klass and clazz. Some will disagree with me for sure, but I think
 it's more readable to simply use the symbol class when you're
 talking about a class. If you disagree, by all means continue to use
 klass; I'm just trying to prevent someone sticking with old java
 habits because they don't realize they have a choice.

Good point. Old java habits is exactly the problem. I'll give myself a
smack on the hand with a ruler :)

- Chris

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


Re: clojure.java.jdbc 0.0.1 released

2011-05-09 Thread Sean Corfield
On Mon, May 9, 2011 at 8:22 AM, Armando Blancas
armando_blan...@yahoo.com wrote:
 Yeap. Release numbers have become meaningless; your point is well
 taken.

Not sure what you mean by that?

The new contrib libraries can be seen here, with their current,
evolving version numbers:

https://oss.sonatype.org/index.html#nexus-search;quick~org.clojure
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

Perfection is the enemy of the good.
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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: CfP: IEEE Software Special Issue: Algorithms and Today’s Practitioner

2011-05-09 Thread Ken Wesson
On Mon, May 9, 2011 at 11:38 AM, Cesare cesare.zavatt...@gmail.com wrote:
 Manuscripts must not exceed 4,700 words including figures and tables,
 which count for 200 words each.

Damn, it's not just the real estate market that's crashed. I remember
when a picture was worth five times that many words!

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


Re: clojure.java.jdbc 0.0.1 released

2011-05-09 Thread Armando Blancas
Having no clue what to make of 0.0.1 precisely w.r.t. its previous
versions numbers, I gathered it's because you can't make out anybody's
modules anyway, in which I agree.

On May 9, 11:34 am, Sean Corfield seancorfi...@gmail.com wrote:
 On Mon, May 9, 2011 at 8:22 AM, Armando Blancas

 armando_blan...@yahoo.com wrote:
  Yeap. Release numbers have become meaningless; your point is well
  taken.

 Not sure what you mean by that?

 The new contrib libraries can be seen here, with their current,
 evolving version numbers:

 https://oss.sonatype.org/index.html#nexus-search;quick~org.clojure
 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View --http://corfield.org/
 World Singles, LLC. --http://worldsingles.com/
 Railo Technologies, Inc. --http://www.getrailo.com/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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: Reading clojure code of larger domain specific projects

2011-05-09 Thread Paul deGrandis
I really like the code in Stuart Sierra's lazytest:
https://github.com/stuartsierra/lazytest/tree/master/modules/lazytest/src/main/clojure/lazytest

The code in Enlive is also a really great read:
https://github.com/cgrand/enlive

I also would recommend going through compojure.

Pau

On May 9, 10:44 am, Stuart Sierra the.stuart.sie...@gmail.com wrote:
 The code is somewhat out-of-date by now (pre-1.0 Clojure) but I wrote much
 of AltLaw.org in Clojure:

 https://github.com/stuartsierra/altlaw-templatehttps://github.com/stuartsierra/altlaw-clojure-restlethttps://github.com/stuartsierra/altlaw-crawlerhttps://github.com/stuartsierra/altlaw-backend

 -Stuart Sierra
 clojure.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: Reading clojure code of larger domain specific projects

2011-05-09 Thread Ken Wesson
On Mon, May 9, 2011 at 6:06 PM, Paul deGrandis paul.degran...@gmail.com wrote:
 I really like the code in Stuart Sierra's lazytest:
 https://github.com/stuartsierra/lazytest/tree/master/modules/lazytest/src/main/clojure/lazytest

 The code in Enlive is also a really great read:
 https://github.com/cgrand/enlive

 I also would recommend going through compojure.

It can be instructive to read code posted to this list, too -- as long
as you also read any criticisms of that code. Though a lot of it isn't
domain-specific, but general example and algorithm code. Much of it
helps get a grasp on how to do certain kinds of data processing in
Clojure's functional paradigm, though, and using its collection types.

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


Re: clojure.java.jdbc 0.0.1 released

2011-05-09 Thread Sean Corfield
On Mon, May 9, 2011 at 2:38 PM, Armando Blancas
armando_blan...@yahoo.com wrote:
 Having no clue what to make of 0.0.1 precisely w.r.t. its previous
 versions numbers, I gathered it's because you can't make out anybody's
 modules anyway, in which I agree.

Well, the previous modules didn't really have version numbers
independently (which was part of the problem that Clojure/core have
addressed with this new approach). Each new contrib library has
started with a pre-1.0.0 version to indicate they are works in
progress which is in line with semantic versioning.

Read the various subsections here for more detail on versioning:
http://dev.clojure.org/display/design/How+to+Make+Releases - in
particular: Clojure/core team must approve first 1.0.0 release.
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

Perfection is the enemy of the good.
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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: Reading clojure code of larger domain specific projects

2011-05-09 Thread Mike Meyer
On Mon, 9 May 2011 03:24:44 -0700 (PDT)
Chris Perkins chrisperkin...@gmail.com wrote:
 I have been thinking for while that it would be great to have
 something equivalent to book clubs for reading code. A group could
 meet weekly, all having read the same moderate-sized project, and
 discuss. I wonder if this could be made to work as a web-app, where
 you can sign up, state your areas of interest, and have a weekly
 reading assignment emailed. Then you could meet on IRC or something.
 Just a thought.

I've been thinking about a similar thing. Lists for beginners at a
language include frequent requests to evaluate my code.  I've been
wondering if there would be any interest in a forum where you could
post a bit of code and let others comment on it. It'd need some way of
picking a language (specific forums? A tag on the post?).

One thing that happens to such posts is they turn into threads of
best way to solve this problem - where best varies by author.
Similarly, programming problem set sites are popular. So maybe an
option for How would I do this might be useful.

   mike
-- 
Mike Meyer m...@mired.org http://www.mired.org/
Independent Software developer/SCM consultant, email for more information.

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

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


Re: clojure.java.jdbc 0.0.1 released

2011-05-09 Thread Armando Blancas
Cool. I look forward to having approved 1.0.0 releases of contrib
libraries.

On May 9, 3:28 pm, Sean Corfield seancorfi...@gmail.com wrote:
 On Mon, May 9, 2011 at 2:38 PM, Armando Blancas

 armando_blan...@yahoo.com wrote:
  Having no clue what to make of 0.0.1 precisely w.r.t. its previous
  versions numbers, I gathered it's because you can't make out anybody's
  modules anyway, in which I agree.

 Well, the previous modules didn't really have version numbers
 independently (which was part of the problem that Clojure/core have
 addressed with this new approach). Each new contrib library has
 started with a pre-1.0.0 version to indicate they are works in
 progress which is in line with semantic versioning.

 Read the various subsections here for more detail on 
 versioning:http://dev.clojure.org/display/design/How+to+Make+Releases- in
 particular: Clojure/core team must approve first 1.0.0 release.
 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View --http://corfield.org/
 World Singles, LLC. --http://worldsingles.com/
 Railo Technologies, Inc. --http://www.getrailo.com/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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: Efficient moving average

2011-05-09 Thread Andy Fingerhut

On May 9, 2011, at 6:45 AM, Andreas Kostler wrote:

 Hi all,
 I'm trying to calculate the moving average of a certain window size.
 One straight forward approach is:
 (defn lazy-avg [coll]
  (let [[sum cnt] (reduce
   (fn [[v c] val] [(+ val v) (inc c)])
   [0 0]
   coll)]
(if (zero? cnt) 0 (/ sum cnt
 
 (let [window-size 5
  n 100]
  (map lazy-avg (partition window-size 1 (range 0 n)))
 
 This takes about 2 seconds for 10^6 elements on my box. How can I
 improve the runtime?
 A slightly more performant (not much) approach keeping a rolling sum
 would be:
 
 (defn partialsums [start lst]
  (lazy-seq
(if-let [lst (seq lst)]
  (cons start (partialsums (+ start (first lst)) (rest lst)))
  (list start
 
 (defn sliding-window-moving-average [window lst]
  (map #(/ % window)
   (let [start   (apply + (take window lst))
 diffseq (map - (drop window lst) lst)]
 (partialsums start diffseq
 
 However, this causes the jvm to run out of heap space for n  10^6
 
 Is ~ 2 seconds the best I can do?

I took your first example and put it into a Clojure source file all its own, 
using AOT compilation and then timing the results of running the program from 
the command line from start to finish.  I was using a 3-year old MacBook Pro 
with 2.4 GHz Intel Core 2 Duo, Mac OS X 10.6.7, Java provided by Apple 
(1.6.0_24-b07-334-10M3326, java -server is a 64-bit JVM).  Note that I've 
previously found significantly different run time and memory uses from 
different JVMs running on different OSs for the same (hardware, Clojure source 
file, Clojure version) combination.  All of my measurements were for a window 
size of 5 and n=10^6.

For your first set of code above, the lowest elapsed time I got on 3 different 
runs was 10.338 sec.  Total memory GCed was about 1.8 GBytes (I was using 
-Xmx256m on the java command line).

For your second set of code above, the lowest elapsed time among 3 runs was 
6.423 sec, with about 570 Mbytes of memory GCed during the run (also using 
-Xmx256m).

With the source code below, I got as low as 3.329 sec of elapsed time with 
about 340 MBytes of memory GCed during the run (again -Xmx256m).  Unlike your 
programs, this one is not lazy on the input sequence -- it always processes the 
whole thing.  I don't hold it up as a model of Clojure code for readability or 
maintainability, but for squeezing run time out of the inner loop.

Andy Fingerhut


(ns movavg
  (:gen-class))

(set! *warn-on-reflection* true)


(defn sliding-window-moving-average [window lst]
  (let [w (int window)
w-1 (int (dec w))]
(loop [rolling-sum (apply + (take w lst))
   last-w (object-array (take w lst))
   i (int 0)
   avgs (transient [(/ rolling-sum w)])
   lst (drop w lst)]
  (if-let [lst (seq lst)]
(let [old-val (aget last-w i)
  new-val (first lst)
  next-rolling-sum (- (+ rolling-sum new-val) old-val)]
  (aset last-w i new-val)
  (recur next-rolling-sum
 last-w
 (if (== i w-1) (int 0) (inc i))
 (conj! avgs (/ next-rolling-sum w))
 (rest lst)))
;; else
(persistent! avgs)


(defn -main [ args]
  (let [window-size (Integer/parseInt (nth args 0))
n (Integer/parseInt (nth args 1))]
(println (sliding-window-moving-average window-size (range 0 n)

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


Re: Creating instances of types not known at compile time

2011-05-09 Thread Simon Katz
On Mon, May 9, 2011 at 17:50, Chris Perkins chrisperkin...@gmail.comwrote:

 On May 9, 8:00 am, Simon Katz nomisk...@gmail.com wrote:
  I'm trying to implement a function similar to new, but where
  the type is not known at compile time -- so I want to evaluate
  the first argument.
 
  With the help of Google, I found the approach used in new*
  below:
 
  (ns dynamic-new)
 
  (defn new* [type-name-as-symbol  args]
(clojure.lang.Reflector/invokeConstructor
 (resolve type-name-as-symbol)
 (to-array args)))

  Now my questions:
 
  Q1. Is this basically the right approach, or is there some other
  way to implement new*?
 

 Is there a reason that you need to pass a symbol, rather than the
 Class object itself?


Passing the class object does exactly what I want.

Thanks!

Simon

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

Re: ANN: Jark 0.3 (using the nrepl protocol)

2011-05-09 Thread Laurent PETIT
Sooo, my question was *that* silly ? :'-(

2011/5/7 Laurent PETIT laurent.pe...@gmail.com:
 Maybe a silly question, but anyway ...

 for CCW, there is this idea of having it maintain, for each open
 project (probably depending on a flag, but that's out of topic), in
 the background (totally transparently for the user), a running JVM
 environment where CCW would maintain the project classes and
 namespaces loaded and up-to-date. Thus CCW would be able to suggest
 code completion, report errors, etc., without having to rely
 on/interfere with the JVMs the user may have started for his own
 needs.

 Of course, it would be desirable to be able to not blow all the user's
 computer memory ... so maybe having the ability to share JVM between
 several open projects in the IDEA, while keeping isolated different
 clojure environments, would be a plus.

 I had the idea of investigating what the project classlojure has to
 provide for this ... but maybe Jark would also be worth studying for
 this purpose, or would it not be the appropriate tool for the job ?

 2011/5/5 isaac praveen icylis...@gmail.com:
 Hi,

 It is a pleasure to announce the release of Jark 0.3, today.

 Why Jark?
 Startup time of the Java Virtual Machine(JVM) is too slow and thereby
 command-line applications on the JVM are sluggish and very painful to
 use.
 Jark is an attempt to run a persistent JVM daemon and provide a set of
 utilities to control and operate on it.
 It should help in deploying clojure applications on the JVM, running
 command-line applications written in clojure and remote-debugging.

 The motivation is also to provide a very thin nrepl-client that can
 run on any given OS platform. Maybe one on the Android. The client
 host need not even have the JRE installed. The current implementation
 is in python(2.6 or 2.7) as a proof-of-concept and runs only on
 GNU/Linux and Mac OSX.

 Get started: http://icylisper.in/jark/start.html

 Jark has utilites for:
 a. Operating and tuning the JVM
 b. Managing classpaths
 c. Managing packages and repositories that are not project-specific (uses 
 cljr)
 d. Scripting (#!/usr/bin/env jark)  and namespaces.
 All of which can be done remotely.

 This is a sample usage:
 server jark vm start [--port]
 client  jark vm connect [--host] [--port]
 client  jark repl
 ---
 client  jark vm stat
 client  jark cp list
 server jark cp add jar
 client  jark package install -p PACKAGE -v VERSION
 client  jark ns load /path/to.clj
 and so on ..

 The earlier version (0.2) of jark used nailgun as a proof-of-concept
 server and client. The current release (0.3) of jark uses Chas
 Emerick's nrepl protocol for communication. I hope to rewrite the
 client in haskell, so native binaries can be generated, sometime soon.
 Have a look at the roadmap:
 Roadmap: http://icylisper.in/jark/roadmap.html

 Mailing list: https://groups.google.com/group/clojure-jark
 code: https://github.com/icylisper/jark.git

 Special thanks to:
  * Ambrose Bonnaire-Sergeant (for collaborating and providing very
 interesting ideas)
  * Bangalore-clojure group members for continuous feedback:
     Shantanu Kumar
     Abhijith Gopal
     Martin Demello
     Abhijit Hoskeri
 * other early jark users for valuable ideas and fixes

 Thats all folks! Hope you find it useful.
 Screencasts and demos are on the way ...
 --
 isaac
 http://icylisper.in

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


-- 
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: Efficient moving average

2011-05-09 Thread Ken Wesson
On Mon, May 9, 2011 at 6:55 PM, Andy Fingerhut andy.finger...@gmail.com wrote:
 (ns movavg
  (:gen-class))

 (set! *warn-on-reflection* true)


 (defn sliding-window-moving-average [window lst]
  (let [w (int window)
        w-1 (int (dec w))]
    (loop [rolling-sum (apply + (take w lst))
           last-w (object-array (take w lst))

This is mutated in place and recurred with itself, so you can just
move it to the outer let (to some spot after w's initialization, of
course). That might afford a minor speedup, but not if the JIT is
optimizing away the repeated assignment of the reference to itself. It
will make the code a bit more concise and clear.

           i (int 0)
           avgs (transient [(/ rolling-sum w)])
           lst (drop w lst)]

You might get a significant speedup with
 lst (seq (drop w lst))]
here and

      (if-let [lst (seq lst)]

(if lst
here and

        (let [old-val (aget last-w i)
              new-val (first lst)
              next-rolling-sum (- (+ rolling-sum new-val) old-val)]
          (aset last-w i new-val)
          (recur next-rolling-sum
                 last-w
                 (if (== i w-1) (int 0) (inc i))
                 (conj! avgs (/ next-rolling-sum w))
                 (rest lst)))

   (next lst)))
here. Calling seq is fairly expensive.

-- 
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: Reading clojure code of larger domain specific projects

2011-05-09 Thread Ken Wesson
On Mon, May 9, 2011 at 6:43 PM, Mike Meyer m...@mired.org wrote:
 One thing that happens to such posts is they turn into threads of
 best way to solve this problem - where best varies by author.

I'm not sure if you intended this as a criticism of the idea, or if
you are thinking the same thing I am, but I'd like to point out that
that can be a good thing. The varied approaches may be more
instructive than just one, particularly when optimized with different
criteria, and tradeoffs may end up illustrated among things like
speed, memory use, clarity/style of the code, avoidance of
mutation/threadsafety, and other considerations.

As long as things don't get out of hand with arguments about the one
true way (if necessary, moderate the forum to squelch such tangents),
such alternative points of view should be encouraged.

Of course, for Clojure code specifically we already get a fair amount
of traffic in this list that fits this pattern -- though it is mixed
in with other traffic, from announcements of new library versions to
debates on the design of Clojure itself to questions about getting
emacs/vimclojure/counterclockwise up and running and more.

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


ANN: Seesaw 1.0.0 (Clojure + Swing)

2011-05-09 Thread Dave Ray
Just a quick announcement that I've pushed an initial version of
Seesaw, my Clojure + Swing experiment, to Clojars. If anyone gives it
a try, I'd love to hear feedback. On GitHub here:

   https://github.com/daveray/seesaw

Cheers,

Dave

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


Re: ANN: Jark 0.3 (using the nrepl protocol)

2011-05-09 Thread isaac praveen
 Just a question. The general philosophy of clojure is to have good
 base building tools, and maybe the building blocks of more
 integrated solutions could also be based on the same philosophy.
 I mean, all the points listed in b) could / should / may (?) not be
 tied to nrepl-server, should ? Couldn't they live in their own library
 ?

Laurent,

The jark utilities and nREPL server are separate. They just are
packaged together for ease of install and use.

-
isaac

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


Re: [clojure-jark-dev] Re: ANN: Jark 0.3 (using the nrepl protocol)

2011-05-09 Thread isaac praveen

 Of course, it would be desirable to be able to not blow all the user's
 computer memory ... so maybe having the ability to share JVM between
 several open projects in the IDEA, while keeping isolated different
 clojure environments, would be a plus.

 I had the idea of investigating what the project classlojure has to
 provide for this ... but maybe Jark would also be worth studying for
 this purpose, or would it not be the appropriate tool for the job ?

Laurent,

I was thinking of using classlojure in jark and provide isolated
containers  in the same instance of the JVM.
It should be integrated in the coming releases.
I am not sure of the limitations yet. From the looks of it,
classlojure looks usable.

Ooops, somehow missed reading your mail in the thread, earlier.

-- 
isaac

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


A simulation of the Monty Hall Problem

2011-05-09 Thread Ken Wesson
From http://en.wikipedia.org/wiki/Monty_Hall_problem we have this
description of the Monty Hall Problem:

 Suppose you're on a game show and you're given the choice of three
 doors [and will win what is behind the chosen door]. Behind one
 door is a car; behind the others, goats [unwanted booby prizes].
 The car and the goats were placed randomly behind the doors before
 the show. The rules of the game show are as follows: After you have
 chosen a door, the door remains closed for the time being. The game
 show host, Monty Hall, who knows what is behind the doors, now has
 to open one of the two remaining doors, and the door he opens must
 have a goat behind it. If both remaining doors have goats behind
 them, he chooses one [uniformly] at random. After Monty Hall opens
 a door with a goat, he will ask you to decide whether you want to
 stay with your first choice or to switch to the last remaining
 door. Imagine that you chose Door 1 and the host opens Door 3,
 which has a goat. He then asks you Do you want to switch to Door
 Number 2? Is it to your advantage to change your choice?

This Clojure code simulates the Monty Hall problem in an interesting
way: the monty-hall function is passed a contestant function that,
when invoked, a) picks a door at random and b) also returns a function
that re-decides which door to open after Monty opens one of the other
two and gives them the chance to switch (monty-hall does this by
calling that function with the number of the door Monty opened).

Two contestant functions are provided. Both make a uniformly random
initial choice of door. The staying-contestant returns a function that
will make the same choice of door after Monty opens one of the other
two. The switching-contestant will switch to the other unopened door.

The monty-avg function takes a contestant and a number of trials, has
that contestant play that many games, and returns the proportion of
times that contestant won. Example output for 10,000 trials is
included; some people may find the results counterintuitive, but the
math says that the results I got are exactly what they should be (and
that 1000 PhDs were wrong about that).

The code is idiomatic Clojure, using sequence functions in preference
to loop/recur and itself using higher order functions in what might be
described as a continuation-passing style. There is also no mutation
or impure function use except for the calls to rand-int and that rng's
hidden internal state; it could be made fully pure by passing around
an extra parameter in the form of a seq of random bits supplied
externally and, from functions that consume from the seq, returning
the reduced seq.

(defn rand-elt [seq]
  (nth seq (rand-int (count seq

(defn make-monty []
   (rand-elt
 [[:car :goat :goat]
  [:goat :car :goat]
  [:goat :goat :car]]))

(defn monty-hall [contestant]
  (let [m (make-monty)
[door response-fn] (contestant)
other-bad-doors (remove #(= (m %) :car)
   (remove #(= % door)
 [0 1 2]))
wrong-door (rand-elt other-bad-doors)
final-door (response-fn wrong-door)]
(m final-door)))

(defn staying-contestant []
  (let [initial-door (rand-int 3)]
[initial-door
 (constantly initial-door)]))

(defn switching-contestant []
  (let [initial-door (rand-int 3)]
[initial-door
 (fn [wrong-door]
   (first
 (remove #(= % initial-door)
   (remove #(= % wrong-door)
 [0 1 2]]))

(defn monty-avg [contestant n-trials]
  (double
(/
  (count
(filter #(= :car %)
  (repeatedly n-trials #(monty-hall contestant
  n-trials)))

user= (monty-avg staying-contestant 1)
0.3362
user= (monty-avg switching-contestant 1)
0.6616

-- 
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: Reading clojure code of larger domain specific projects

2011-05-09 Thread Christian Schuhegger
Many thanks for all of your contributions so far! I definitely will
(and already have to some extent) go through the recommended links.
One additional project I came across that looks interesting is midje:
https://github.com/marick/Midje/wiki

I see the point of having a forum to discuss best solutions, but that
is a different matter from what I am talking about.

Code looks different if you look at some lines of code or if you look
at projects that have a relevant size (more than 100k lines of code)
and where more than 10 people have worked on over an extended period
of time. In addition the reason for looking for a project that is less
technical and more domain specific is that typically developers have a
very good understanding of how a technical solution should look like.
They have the requirements already in their heads, because they are
the final audience, the end-users. In a domain specific project the
requirements come from outside and the business domain is typically
not clear from the start. The project has to develop ways on how to
deal with the evolution of the understanding/insight into the problem
domain.

You get a balanced view across different styles by looking at several
projects of relevant size. Different teams find different solutions to
similar problems.

Projects that are not open-source but would seem to fall in the
category that I am looking for are FlightCaster and TheDeadline:
http://www.infoq.com/articles/deadline-clojure-appengine

Do you know of any projects of that type that are open-source to be
able to analyse the code?

Many thanks!
Christian

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


Ok, so code is data...

2011-05-09 Thread Bill Robertson
How do I actually manipulate it?  I have some complicated logic that I
would like to transform into html (or maybe xml) for display
purposes.

I'm generating the Clojure code by parsing some nasty Java and
outputting s-expressions.  The Java is basic, but quite deeply
nested.  I want to generate working Clojure to demonstrate what that
can do for us, and get this nastiness documented of course.

Other than going into the source files and transforming it by hand
into a series of defs and quoted lists e.g.  (def my_func '(+ 1 2))
How do I actually just load code w/o evaluating it?

I've found the pretty printer macros, seems like that might be useful
if I wanted to statically transform the code.  I found the walker,
that looks like it might be useful in actually generating the output
(e.g. visit things, spit out (x|ht)ml.

I looked at the various load functions in clojure.core.  With the
exception of load (http://clojure.github.com/clojure/clojure.core-
api.html#clojure.core/load) they all seem to load and evaluate.  Is
load the answer or is it something I haven't found yet?

Once I get the code loaded, I don't think I need anything out of the
ordinary like macros or multi-methods.  I think I can just manipulate
the lists.  Does that sound correct?

I'm sorry if this are a stupid questions, but I've never done anything
in Clojure of any significance, and any helpful answers you provide
would could save me days of stumbling about.

Thanks!


-- 
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: A simulation of the Monty Hall Problem

2011-05-09 Thread Ken Wesson
On Mon, May 9, 2011 at 11:26 PM, Ken Wesson kwess...@gmail.com wrote:
 The code is idiomatic Clojure, using sequence functions in preference
 to loop/recur and itself using higher order functions in what might be
 described as a continuation-passing style. There is also no mutation
 or impure function use except for the calls to rand-int and that rng's
 hidden internal state; it could be made fully pure by passing around
 an extra parameter in the form of a seq of random bits supplied
 externally and, from functions that consume from the seq, returning
 the reduced seq.

Here's the pure version. I've made it COMPLETELY purely functional --
even to the point of making a functional reimplementation of
java.util.Random.nextInt().

The first few functions build up to random-bit-seq, which takes a seed
and returns an infinite lazy sequence of random bits, which is used to
implement rand-num (replaces rand-int in original). The rand-num
function, and things like rand-elt and make-monty, now return a vector
of [random-influenced-return-value
unconsumed-portion-of-random-bit-seq]; rand-num uses a rejection
algorithm (stack-safe thanks to recur) to produce uniform results when
the range is not a power of two (notably, the Monty Hall problem
results in it often being called with 3) and handles the corner case 1
correctly (returning 0 and the whole random-bit-seq, having consumed
none of it).

After that, the original Monty Hall problem functions follow, mostly
altered by a) taking an added parameter of a random bit sequence and
b) returning a vector whose final component is the partially-consumed
random bit sequence. So the sequence threads through all the function
calls being consumed to produce random numbers via rand-num, all
without any actual mutation.

The monty-avg function takes a random seed as an added parameter,
rather than a bit sequence. As one would hope, it produces a fixed
result for a fixed choice of contestant, number-of-trials, and seed --
it is, after all, a pure function. :) Notice also that the sum of the
return value for switching-contestant and staying-contestant will
always be exactly 1, seed and number-of-trials remaining equal,
because every time the switching-contestant would have gotten a goat
the staying-contestant gets a car, and vice versa -- they are
encountering the exact same sequence of games. Nothing is changing,
including any of the random choices, except which final door is
chosen, which has no effect on subsequent games.

I've also included a third contestant, the
sometimes-switching-contestant, who has a fifty percent chance of
switching (and thus consumes one bit of the random bit sequence when
Monty offers the option of switching). As you might expect, this one
wins fifty percent of the time. The number isn't exactly half, though,
despite the above, since he isn't switching on a set of games and
staying on an identical set of games, but rather switching on a set of
games and staying on a different set of games.

All of this passing and returning of side-band parameters cries out
for some sort of simplification -- enter monads. But I leave writing a
version of the below that employs monads as an exercise for the
reader. ;)

Implementing a superior, simulation-grade PRNG such as Mersenne
Twister in a pure-functional manner to implement random-bit-seq is
also left as an exercise for the reader.

One limitation of the pure-functional approach is notable: unlike in
the original, it is possible in this version for the contestant to
cheat by basically stacking the deck -- it could return not the
unconsumed portion of the random-bit-seq but instead a tailored seq
that will control Monty for the next game in the sequence in puppet
fashion to produce a desired result (e.g. a car every time). At the
end is a cheating-contestant function that actually does this.

This may not be a true weakness of pure functionality, though. One can
imagine blocking this form of cheating by providing two random bit
sequences, one that Monty uses and one that the contestant uses --
though the contestant now has to trust Monty not to mess with the
sequence to puppet the contestant. More sophisticatedly, each could
encrypt and decrypt their sequence by xoring it with a fixed,
unknown-to-the-other bit-sequence of fixed length that is cycled, at
least in principle, and thereby pass private information through the
other back to themselves in a manner that would resist both
eavesdropping and any attempt to exert control via tampering; the most
tampering could do is randomize things, and if the private information
was already random this would have no meaningful consequence. One can
also imagine including check digits in private information in
addition to encrypting it, so that any substitution with random data
will (with high likelihood) be detected, making the private data
tamper-evident in a cryptographically-strong manner as well as
resistant to eavesdropping and (directed) tampering.

(def two-48-1 (dec 

Re: Ok, so code is data...

2011-05-09 Thread Justin Kramer
'read' and 'read-string' are what you're looking for. They each read a
single Clojure object from an input source (PushbackReader for read,
String for read-string).

Alternatively, something like this can read all top-level forms from a
file:

(defn read-all
  Reads all top-level forms from f, which will be coerced by
  clojure.java.io/reader into a suitable input source. Not lazy.
  [f]
  (with-open [pbr (java.io.PushbackReader. (clojure.java.io/reader
f))]
(doall
 (take-while
  #(not= ::eof %)
  (repeatedly #(read pbr false ::eof))

(read-all /some/clojure/file.clj)
= ((foo :bar) (baz))

Justin

On May 9, 11:36 pm, Bill Robertson billrobertso...@gmail.com wrote:
 How do I actually manipulate it?  I have some complicated logic that I
 would like to transform into html (or maybe xml) for display
 purposes.

 I'm generating the Clojure code by parsing some nasty Java and
 outputting s-expressions.  The Java is basic, but quite deeply
 nested.  I want to generate working Clojure to demonstrate what that
 can do for us, and get this nastiness documented of course.

 Other than going into the source files and transforming it by hand
 into a series of defs and quoted lists e.g.  (def my_func '(+ 1 2))
 How do I actually just load code w/o evaluating it?

 I've found the pretty printer macros, seems like that might be useful
 if I wanted to statically transform the code.  I found the walker,
 that looks like it might be useful in actually generating the output
 (e.g. visit things, spit out (x|ht)ml.

 I looked at the various load functions in clojure.core.  With the
 exception of load (http://clojure.github.com/clojure/clojure.core-
 api.html#clojure.core/load) they all seem to load and evaluate.  Is
 load the answer or is it something I haven't found yet?

 Once I get the code loaded, I don't think I need anything out of the
 ordinary like macros or multi-methods.  I think I can just manipulate
 the lists.  Does that sound correct?

 I'm sorry if this are a stupid questions, but I've never done anything
 in Clojure of any significance, and any helpful answers you provide
 would could save me days of stumbling about.

 Thanks!

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