Re: iterator-seq runs over

2010-02-16 Thread Stuart Halloway

Hi Rob,

map is lazy, count and butlast are not lazy. Does adding a doall  
around your call to map fix this problem?


Stu

(map handler (iterator-seq result-set)) always throws a  
NoSuchElementException


(map handler (butlast (iterator-seq result-set))) always works.

(count (iterator-seq result-set)) is returning the correct number of
elements. Calls to first, second, nth, also work correctly.

When I manually test a result-set of three elements,
[(handler (.next result-set))
(handler (.next result-set))
(handler (.next result-set))]
evaluates correctly, while adding one more .next call results in the
same NoSuchElementException.

Using butlast fixes the problem, but then I obviously lose the last
element in the result set. This code is replacing vanilla Java code
which used .hasNext() and .next() without problem for a couple of
months, so I doubt it's the class (com.hp.hpl.jena.query.ResultSet)
incorrectly implementing Iterator.

Has anyone else seen this type of behavior?

Rob

--
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: iterator-seq runs over

2010-02-16 Thread Meikel Brandmeyer
Hi,

On Feb 16, 9:55 am, Stuart Halloway stuart.hallo...@gmail.com wrote:

 map is lazy, count and butlast are not lazy. Does adding a doall  
 around your call to map fix this problem?

Argh. butlast is only unlazy of degree one, so to say.

Is there a reason why not to provide a lazy version:

(defn butlast
  Return a seq of all but the last item in coll.
  [coll]
  (lazy-seq
(let [s (seq coll)]
  (when-let [r (next s)]
(cons (first s) (butlast r))

I see, that butlast is used in the bootstraping early on. But can't
there be a bootstrap version, which does not need the whole machinery,
and a production butlast providing laziness? Or is it not worth the
trouble?

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: First program, in case you want to give hints

2010-02-16 Thread alux
Hello,

the current state of Conway's Prime Machine is at http://paste.lisp.org/+21BR

I'l go on learning. The next state should be seperation of print and
produce. Currently (conway-pm) doesnt return stuff. I dont know if
Clojure can produce infinite lists, like Haskell, and print the items
as they come.


Thank you for the hints.

Regards, alux

On 14 Feb., 16:06, Johnny Kwan johnny.c.k...@gmail.com wrote:
 On Feb 14, 2010, at 8:58 AM, Laurent PETIT wrote:



  2010/2/14 alux alu...@googlemail.com:
  Hello Sean,

  thank you for the answer.

  I used letfn not for recursive swearing, but for the localness. I
  thought the functions to be so special,
  nobody else will use it, so I put it into conway-PM. Is there a non
  recursive let for functions?

  Hello,

  in this case, you can just use let:

  user= (let [some-fn (fn [] hello!)]
   (println (some-fn)))
  hello!
  nil
  user=

  HTH,

  --
  Laurent

 FWIW, you can always define functions privately with defn-.  I prefer that 
 style.

 Johnny



  Thanks for the hint about Lisppaste, didnt know that.

  Regards, alux

  On 13 Feb., 19:25, Sean Devlin francoisdev...@gmail.com wrote:
  Alux,
  Welcome to Clojrue!  Thanks for posting this example.

  At first glance I would combine power-of-two? and what-power-of-2 into
  one fn.  Also, I would change the order you wrote the method calls in
  to favor the .method style

  (defn power-of-2
    Returns log_2(n) iff n is an exact pwoer of 2.  nil otherwise
    (if (= (.bitCount (big-int n)) 1)
      (dec (.bitLength (big-int n

  Also, letfn is for mutually recursive fns (you know, the kind that
  swear at each other :).  I would move big-int, step  power-of-2 into
  their own defns.  That should clean up your definition of conway-PM.

  Sean

  PS - Do you use github or lisppaste?  The general practice is to put
  code in a pastebin, and simply include a link in the mailing list.

  On Feb 13, 11:48 am, alux alu...@googlemail.com wrote:

  Hi,

  I just finished my first (very small) Clojure program. I come from
  Java, so it will be everything but idiomatic Clojure, so I post it
  here and you may give as much criticism as you want. I'm here to
  learn.

  It implements JHConway prime machine. The program does not want to be
  a quick prime generator (the algorithm is interesting but not quick at
  all), but it shall be/become a good implementation of this algorithm.

 http://www.jstor.org/pss/2690263(Thefirstpage is enough to
  implement the algorithm, even if the explanation will come on the next
  pages only.)

  Started like:

  (conway-PM)

  It came up to 563 after about 6 hours on my 1.2 GHz Centrino ;-)

  Thats the program, feel free to tell me stuff (or to ignore me, would
  be a lessen too :)

  (defn conway-PM []
          (let [
                  factors '(17/91 78/85 19/51 23/38 29/33 77/29 95/23 
  77/19 1/17 11/13
  13/11 15/14 15/2 55/1)
                  big-int-class (. 9 
  getClass)]
                  (letfn [
                          (big-int [n];makes a bigint from int, keeps n 
  if bigint already
                                  (let [current-class (. n getClass)]
                                          (if (= current-class 
  big-int-class) n
                                                  (. java.math.BigInteger 
  valueOf n
                          (power-of-two? [n];true iff the integer n is an 
  power of 2.
                                  (= (. (big-int n) bitCount) 1))
                          (what-power-of-2 [n];gets n from 2^n
                                  (- (. (big-int n) bitLength) 1))
                          (step ;Multiplies with the first factor to give 
  an integer.
                                  [n, unused-factors]
                                  (let [factor (first unused-factors)
                                            rest-factors (rest 
  unused-factors)
                                            dummy (* n factor)]
                                  (if (integer? dummy)
                                          dummy
                                          (step n rest-factors]
                          (loop [seed 2]
                                  (let [next (step seed factors)]
                                          (if (power-of-two? next)
                                                  (println 
  (what-power-of-2 next)))
                                          (recur next))

  Regards, alux

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

Re: iterator-seq runs over

2010-02-16 Thread Robert Campbell
Hi Stuart,

That fixes the problem, thank you.

When I ran the result-set through (type), it showed me that the
instance was actually a ResultSetStream. While the Jena ResultSet
interface doesn't act as a closable resource, perhaps the stream was
being closed once the owning QueryExecution obj was closed via
with-open.

Rob



On Tue, Feb 16, 2010 at 9:55 AM, Stuart Halloway
stuart.hallo...@gmail.com wrote:
 Hi Rob,

 map is lazy, count and butlast are not lazy. Does adding a doall around your
 call to map fix this problem?

 Stu

 (map handler (iterator-seq result-set)) always throws a
 NoSuchElementException

 (map handler (butlast (iterator-seq result-set))) always works.

 (count (iterator-seq result-set)) is returning the correct number of
 elements. Calls to first, second, nth, also work correctly.

 When I manually test a result-set of three elements,
 [(handler (.next result-set))
 (handler (.next result-set))
 (handler (.next result-set))]
 evaluates correctly, while adding one more .next call results in the
 same NoSuchElementException.

 Using butlast fixes the problem, but then I obviously lose the last
 element in the result set. This code is replacing vanilla Java code
 which used .hasNext() and .next() without problem for a couple of
 months, so I doubt it's the class (com.hp.hpl.jena.query.ResultSet)
 incorrectly implementing Iterator.

 Has anyone else seen this type of behavior?

 Rob

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

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

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


Re: First program, in case you want to give hints

2010-02-16 Thread Jarkko Oranen


On Feb 16, 12:26 pm, alux alu...@googlemail.com wrote:
 Hello,

 the current state of Conway's Prime Machine is athttp://paste.lisp.org/+21BR

Instead of using a quoted list, a vector is more idiomatic in Clojure.


 I'l go on learning. The next state should be seperation of print and
 produce. Currently (conway-pm) doesnt return stuff. I dont know if
 Clojure can produce infinite lists, like Haskell, and print the items
 as they come.

It can. They're just called infinite sequences. For example, (iterate
inc 0) produces an infinite sequence of integers from 0 onwards. You
can also construct your own infinite sequences using the lazy-seq
macro in a pattern like the following:

(defn count-down [x]
(lazy-seq (cons x (count-down (dec x) ; lazy-seq doesn't
actually evaluate the cons until it's requested

However, often you should start by looking at the core library and see
if there already exists a function to produce a list that you need,
and only afterwards construct things from scratch. For example,
repeatedly and iterate are common seq-producers, and map and
filter are used to transform them. They're all lazy, so infinite
seqs are not problematic.

There is one thing you need to look out for though: Never define a
global reference to an infinite seq. The items in a sequence are
cached, so if you define a global reference to the head, no part of
the seq will ever be garbage collected and its memory usage will be
unbounded.


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


send-off, number of threads processor load

2010-02-16 Thread Alex Ott
Hello all

I have question about send-off, agents  threads - I'm trying to use
send-off to dispatch tasks, that stores some data into central agent.
Tasks could be long running.  I found following situation:
 - when I explicitly create threads and run tasks in them, I have more load
   on machine, that lead to bigger number of simultaneous tasks processed.
   Typically i see about 600% load on my machine with 8 logical processors
   (4cores with hyperthreading)
 - when I use send-off, I get less number of simultaneous connection to
   service, and load usually not bigger as 160%

Questions are: how could I control how much treads are used in agent's
queue?  How can I improve payload on my machine, so Clojure will use all
available resources?

-- 
With best wishes, Alex Ott, MBA
http://alexott.blogspot.com/   http://alexott.net
http://alexott-ru.blogspot.com/

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


Re: When to use loop recur / seq functions?

2010-02-16 Thread Jeff Rose
I think it's preferable to use the sequence functions when possible.
This way you get laziness without having to construct lazy-seqs by
hand, you get automatic chunking for better performance, and you
create code that is easier for other Clojure users to parse.  On the
other hand, if you find yourself jumping through hoops to make
something work with sequences while it would otherwise be cleaner and
simpler with a recursive function, use recur instead.

I think this is the general guideline that was discussed a little
while ago when there was a thread talking about Clojure coding
standards too.

-Jeff

On Feb 15, 5:20 pm, stefanmuenchow stefanmuenc...@gmx.de wrote:
 Hello, I'm new to clojure and have a question concerning recur and
 lazy seqs.

 I implemented a function to calculate the perimeter of a polygon. As
 I'm used to Java and imperative programming, my first approach was to
 use loop/recur ('euclidean-distance' is a helper-function that
 calculates the distance between two points):

 (defn polygon-perimeter
   Calculates the perimeter of a polygon. For this purpose it adds
   up the distances between all points.
   [ pn]
     (loop [p 0.0, points (conj (vec pn) (first pn))]
       (if ( (count points) 1)
         (recur (+ p (euclidean-distance (first points) (second
 points)))
                  (rest points))
         p)))

 I found that this doesn't look very functional, so I tried a different
 approach with use of the sequence library;

 (defn better-perimeter
   Calculates the perimeter of a polygon. For this purpose it adds
   up the distances between all points.
   [ pn]
   (reduce +
     (map #(euclidean-distance (first %) (second %))
             (partition 2 1 (conj (vec pn) (first pn))

 This looks very nice. But then I compared the performance of both
 implementations:

 (dotimes [_ 5] (time (polygon-perimeter [0 1] [1 0] [3 2] [2 3] [0
 2])))
 Elapsed time: 1.129296 msecs
 Elapsed time: 0.156261 msecs
 Elapsed time: 0.153229 msecs
 Elapsed time: 0.153613 msecs
 Elapsed time: 0.152975 msecs

 (dotimes [_ 5] (time (better-perimeter [0 1] [1 0] [3 2] [2 3] [0
 2])))
 Elapsed time: 2.809387 msecs
 Elapsed time: 0.221396 msecs
 Elapsed time: 0.214933 msecs
 Elapsed time: 0.214048 msecs
 Elapsed time: 0.217317 msecs

 As you can see, the loop/recur version is a bit faster (not
 significantly but a little bit). This leads me to a general question:

 What would be the better implementation? When should I use loop/recur
 and when seq library functions? Stuart Halloway writes in his book
 Use recur when you are producing scalar values or small, fixed
 sequences and also Know the sequences library. You can often write
 code without using recur or the lazy apis at all. Pehaps you have
 some more rules of the thumb?

-- 
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: First program, in case you want to give hints

2010-02-16 Thread Sean Devlin
Alux,
This is good progress, keep up the good work.  Here's my
implementation w/Jarkko's suggestions built in.  Take a look at this
AFTER you complete your next iteration :)

http://gist.github.com/305521

I've changed the following

* Imported java.math.BigInteger
* Used the instance? predicate to test if an object is a BigInteger in
your big-int fn.
* I added type hints to special-log.  This lets Clojure use the
specific class methods for the object instead of reflection.  The
result is the code is much faster.
* removed the letfn and placed step in the normal let block.  There's
no mutual recursion, so let will do the job.
* Wrote the producing fn in terms of iterate, so the result is now a
lazy list.

Sean

On Feb 16, 6:38 am, Jarkko Oranen chous...@gmail.com wrote:
 On Feb 16, 12:26 pm, alux alu...@googlemail.com wrote:

  Hello,

  the current state of Conway's Prime Machine is athttp://paste.lisp.org/+21BR

 Instead of using a quoted list, a vector is more idiomatic in Clojure.



  I'l go on learning. The next state should be seperation of print and
  produce. Currently (conway-pm) doesnt return stuff. I dont know if
  Clojure can produce infinite lists, like Haskell, and print the items
  as they come.

 It can. They're just called infinite sequences. For example, (iterate
 inc 0) produces an infinite sequence of integers from 0 onwards. You
 can also construct your own infinite sequences using the lazy-seq
 macro in a pattern like the following:

 (defn count-down [x]
     (lazy-seq (cons x (count-down (dec x) ; lazy-seq doesn't
 actually evaluate the cons until it's requested

 However, often you should start by looking at the core library and see
 if there already exists a function to produce a list that you need,
 and only afterwards construct things from scratch. For example,
 repeatedly and iterate are common seq-producers, and map and
 filter are used to transform them. They're all lazy, so infinite
 seqs are not problematic.

 There is one thing you need to look out for though: Never define a
 global reference to an infinite seq. The items in a sequence are
 cached, so if you define a global reference to the head, no part of
 the seq will ever be garbage collected and its memory usage will be
 unbounded.

-- 
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 Jobs in White Plains, NY (incorrect email in the previous post)

2010-02-16 Thread Eric Thorsen
Thanks for catching that!
care...@thortech-solutions.com

On Feb 7, 5:18 am, Michael Kohl citizen...@gmail.com wrote:
 On Thu, Feb 4, 2010 at 10:29 PM, Eric Thorsen ethor...@enclojure.org wrote:
  ThorTech Solutions
  care...@thotech-solutions.com

 Is the missing 'r' in the mail address a kind of pre-selection of
 applicants? ;-)

 Michael

-- 
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: First program, in case you want to give hints

2010-02-16 Thread alux
I'm curious, but as you told me, I pasted my solution (with a lazy
stream), as annotation of my former program.

http://paste.lisp.org/+21BR/1

So, now I'll have a look at yours.

Thanks, and read you sn.

alux

On 16 Feb., 14:32, Sean Devlin francoisdev...@gmail.com wrote:
 Alux,
 This is good progress, keep up the good work.  Here's my
 implementation w/Jarkko's suggestions built in.  Take a look at this
 AFTER you complete your next iteration :)

 http://gist.github.com/305521

 I've changed the following

 * Imported java.math.BigInteger
 * Used the instance? predicate to test if an object is a BigInteger in
 your big-int fn.
 * I added type hints to special-log.  This lets Clojure use the
 specific class methods for the object instead of reflection.  The
 result is the code is much faster.
 * removed the letfn and placed step in the normal let block.  There's
 no mutual recursion, so let will do the job.
 * Wrote the producing fn in terms of iterate, so the result is now a
 lazy list.

 Sean

 On Feb 16, 6:38 am, Jarkko Oranen chous...@gmail.com wrote:

  On Feb 16, 12:26 pm, alux alu...@googlemail.com wrote:

   Hello,

   the current state of Conway's Prime Machine is 
   athttp://paste.lisp.org/+21BR

  Instead of using a quoted list, a vector is more idiomatic in Clojure.

   I'l go on learning. The next state should be seperation of print and
   produce. Currently (conway-pm) doesnt return stuff. I dont know if
   Clojure can produce infinite lists, like Haskell, and print the items
   as they come.

  It can. They're just called infinite sequences. For example, (iterate
  inc 0) produces an infinite sequence of integers from 0 onwards. You
  can also construct your own infinite sequences using the lazy-seq
  macro in a pattern like the following:

  (defn count-down [x]
      (lazy-seq (cons x (count-down (dec x) ; lazy-seq doesn't
  actually evaluate the cons until it's requested

  However, often you should start by looking at the core library and see
  if there already exists a function to produce a list that you need,
  and only afterwards construct things from scratch. For example,
  repeatedly and iterate are common seq-producers, and map and
  filter are used to transform them. They're all lazy, so infinite
  seqs are not problematic.

  There is one thing you need to look out for though: Never define a
  global reference to an infinite seq. The items in a sequence are
  cached, so if you define a global reference to the head, no part of
  the seq will ever be garbage collected and its memory usage will be
  unbounded.

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


Leaning about VM's, JVM in particular

2010-02-16 Thread Andrey Fedorov
Hi all,

I'm looking for approaches to learn about VM's, the JVM in particular.
I noticed some local university courses use Virtual Machines (Smith,
Nair) [1]. I'm planning on getting it, but would rather query you guys
for opinions first, and recommendations on other books/resources?

Cheers,
Andrey


1. http://www.amazon.com/gp/product/1558609105/

-- 
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: First program, in case you want to give hints

2010-02-16 Thread Sean Devlin
Interesting...  could you add a few test cases?  I want to make sure
my implementation does what you expect.

Thanks,
Sean

On Feb 16, 11:18 am, alux alu...@googlemail.com wrote:
 I'm curious, but as you told me, I pasted my solution (with a lazy
 stream), as annotation of my former program.

 http://paste.lisp.org/+21BR/1

 So, now I'll have a look at yours.

 Thanks, and read you sn.

 alux

 On 16 Feb., 14:32, Sean Devlin francoisdev...@gmail.com wrote:

  Alux,
  This is good progress, keep up the good work.  Here's my
  implementation w/Jarkko's suggestions built in.  Take a look at this
  AFTER you complete your next iteration :)

 http://gist.github.com/305521

  I've changed the following

  * Imported java.math.BigInteger
  * Used the instance? predicate to test if an object is a BigInteger in
  your big-int fn.
  * I added type hints to special-log.  This lets Clojure use the
  specific class methods for the object instead of reflection.  The
  result is the code is much faster.
  * removed the letfn and placed step in the normal let block.  There's
  no mutual recursion, so let will do the job.
  * Wrote the producing fn in terms of iterate, so the result is now a
  lazy list.

  Sean

  On Feb 16, 6:38 am, Jarkko Oranen chous...@gmail.com wrote:

   On Feb 16, 12:26 pm, alux alu...@googlemail.com wrote:

Hello,

the current state of Conway's Prime Machine is 
athttp://paste.lisp.org/+21BR

   Instead of using a quoted list, a vector is more idiomatic in Clojure.

I'l go on learning. The next state should be seperation of print and
produce. Currently (conway-pm) doesnt return stuff. I dont know if
Clojure can produce infinite lists, like Haskell, and print the items
as they come.

   It can. They're just called infinite sequences. For example, (iterate
   inc 0) produces an infinite sequence of integers from 0 onwards. You
   can also construct your own infinite sequences using the lazy-seq
   macro in a pattern like the following:

   (defn count-down [x]
       (lazy-seq (cons x (count-down (dec x) ; lazy-seq doesn't
   actually evaluate the cons until it's requested

   However, often you should start by looking at the core library and see
   if there already exists a function to produce a list that you need,
   and only afterwards construct things from scratch. For example,
   repeatedly and iterate are common seq-producers, and map and
   filter are used to transform them. They're all lazy, so infinite
   seqs are not problematic.

   There is one thing you need to look out for though: Never define a
   global reference to an infinite seq. The items in a sequence are
   cached, so if you define a global reference to the head, no part of
   the seq will ever be garbage collected and its memory usage will be
   unbounded.

-- 
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: send-off, number of threads processor load

2010-02-16 Thread Chouser
On Tue, Feb 16, 2010 at 7:24 AM, Alex Ott alex...@gmail.com wrote:
 Hello all

 I have question about send-off, agents  threads - I'm trying to use
 send-off to dispatch tasks, that stores some data into central agent.
 Tasks could be long running.  I found following situation:
  - when I explicitly create threads and run tasks in them, I have more load
   on machine, that lead to bigger number of simultaneous tasks processed.
   Typically i see about 600% load on my machine with 8 logical processors
   (4cores with hyperthreading)
  - when I use send-off, I get less number of simultaneous connection to
   service, and load usually not bigger as 160%

I don't think there's any limit on the number of threads spawned
by send-off.   ...except that no single agent will ever be
allocated more than one thread at a time.  Are you perhaps doing
lots of send-offs to just one or two agents?

--Chouser
http://joyofclojure.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: First program, in case you want to give hints

2010-02-16 Thread alux
;-)

It didnt exactly do what I did, it just produced the numers I needed
in between, I had to add the filtering.

Then I compared the time, and yours is almost 40% quicker. Cool!
(First time I saw type hints in Clojure. :)

Now the main difference was the call to step. You did it tail call
optimised via recur, I didn't.
Not knowing how this is implemented, I used it for one more timing -
no statistics, just one run - no difference at all.

http://paste.lisp.org/+21BR/2

Thank you!, and I (probably) quit the web for today.

Bye and read you. alux


On 16 Feb., 17:43, Sean Devlin francoisdev...@gmail.com wrote:
 Interesting...  could you add a few test cases?  I want to make sure
 my implementation does what you expect.

 Thanks,
 Sean

 On Feb 16, 11:18 am, alux alu...@googlemail.com wrote:

  I'm curious, but as you told me, I pasted my solution (with a lazy
  stream), as annotation of my former program.

 http://paste.lisp.org/+21BR/1

  So, now I'll have a look at yours.

  Thanks, and read you sn.

  alux

  On 16 Feb., 14:32, Sean Devlin francoisdev...@gmail.com wrote:

   Alux,
   This is good progress, keep up the good work.  Here's my
   implementation w/Jarkko's suggestions built in.  Take a look at this
   AFTER you complete your next iteration :)

  http://gist.github.com/305521

   I've changed the following

   * Imported java.math.BigInteger
   * Used the instance? predicate to test if an object is a BigInteger in
   your big-int fn.
   * I added type hints to special-log.  This lets Clojure use the
   specific class methods for the object instead of reflection.  The
   result is the code is much faster.
   * removed the letfn and placed step in the normal let block.  There's
   no mutual recursion, so let will do the job.
   * Wrote the producing fn in terms of iterate, so the result is now a
   lazy list.

   Sean

   On Feb 16, 6:38 am, Jarkko Oranen chous...@gmail.com wrote:

On Feb 16, 12:26 pm, alux alu...@googlemail.com wrote:

 Hello,

 the current state of Conway's Prime Machine is 
 athttp://paste.lisp.org/+21BR

Instead of using a quoted list, a vector is more idiomatic in Clojure.

 I'l go on learning. The next state should be seperation of print and
 produce. Currently (conway-pm) doesnt return stuff. I dont know if
 Clojure can produce infinite lists, like Haskell, and print the items
 as they come.

It can. They're just called infinite sequences. For example, (iterate
inc 0) produces an infinite sequence of integers from 0 onwards. You
can also construct your own infinite sequences using the lazy-seq
macro in a pattern like the following:

(defn count-down [x]
    (lazy-seq (cons x (count-down (dec x) ; lazy-seq doesn't
actually evaluate the cons until it's requested

However, often you should start by looking at the core library and see
if there already exists a function to produce a list that you need,
and only afterwards construct things from scratch. For example,
repeatedly and iterate are common seq-producers, and map and
filter are used to transform them. They're all lazy, so infinite
seqs are not problematic.

There is one thing you need to look out for though: Never define a
global reference to an infinite seq. The items in a sequence are
cached, so if you define a global reference to the head, no part of
the seq will ever be garbage collected and its memory usage will be
unbounded.

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


Re: Question about how I got run?

2010-02-16 Thread Jeff Schwab

Mike Meyer wrote:


Is there any way to tell if inside a .clj file if it was invoked as a
script by clojure.main, vs. being loaded for use elsewhere?


Use a shebang line that calls a wrapper script, e.g. clj-script, that 
passes a command-line arg to tell the code it's being run as a script.


$ ls
clj-script  example.clj

$ cat clj-script
#!/bin/bash
clj $@ --script

$ cat example.clj
#!/usr/bin/env clj-script
(ns example)
(println
  (if *command-line-args*
I am a script.
I am not a script.))

$ PATH=$PWD:$PATH ./example.clj
I am a script.

$ repl
Clojure 1.2.0-master-SNAPSHOT
user= (use 'example)
I am not a script.
nil

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


Re: Question about how I got run?

2010-02-16 Thread Daniel Werner
On Feb 16, 2:12 am, Mike Meyer mwm-keyword-googlegroups.
620...@mired.org wrote:
 Wouldn't be hard to do, either. Just bind *script-name* (or some such)
 to the path in script-opt, and let the client decide if it's the same
 as *file*.

It would indeed be helpful if clojure.main bound a Var to the name of
the .clj file being run, sort of like argv[0] in C. Like Michał
suggested, there's the gen-class solution, but I personally tend avoid
AOT-compiling Clojure code, which rules out gen-class.

   What I'd like to do is make my unit tests usable in two modes: While
   working on a bug, I'd like to be able to load them in the REPL to
   rerun the subset of interest - possibly just the test which is
   failing. However, I'd also like to be able to feed the script to
   clojure.main with something like clj test.clj and have it run them
   all.

This seems to be a common idiom, especially in the Python community.
clojure.contrib and other Clojure projects seem to follow a different
philosophy: Keep your unit tests in a separate tests/ directory and
invoke them through a Maven/Ant/Leiningen task.

-- 
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: send-off, number of threads processor load

2010-02-16 Thread Alex Ott
Hello

Chouser  at Tue, 16 Feb 2010 12:02:17 -0500 wrote:
 C On Tue, Feb 16, 2010 at 7:24 AM, Alex Ott alex...@gmail.com wrote:
  Hello all
 
  I have question about send-off, agents  threads - I'm trying to use
  send-off to dispatch tasks, that stores some data into central agent.
  Tasks could be long running.  I found following situation:
   - when I explicitly create threads and run tasks in them, I have more load
    on machine, that lead to bigger number of simultaneous tasks processed.
    Typically i see about 600% load on my machine with 8 logical processors
    (4cores with hyperthreading)
   - when I use send-off, I get less number of simultaneous connection to
    service, and load usually not bigger as 160%

 C I don't think there's any limit on the number of threads spawned
 C by send-off.   ...except that no single agent will ever be
 C allocated more than one thread at a time.  Are you perhaps doing
 C lots of send-offs to just one or two agents?

Yes, all send-off are sent to one agent, that accumulate information about
different documents

-- 
With best wishes, Alex Ott, MBA
http://alexott.blogspot.com/http://alexott.net/
http://alexott-ru.blogspot.com/

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


Re: Leaning about VM's, JVM in particular

2010-02-16 Thread Robert Campbell
Some good books that we recommend to get you on your way [to
understanding the JVM/runtime] are: Java Reflection in Action
by Ira R. Forman and Nate Forman. The Java Virtual Machine
Specification 2nd edition by Tim Lindholm.
Effective Java 2nd edition and Java Puzzlers by Joshua Bloch. And
Inside The Java Virtual Machine 2nd
edition by Bill Venners.

- The Joy of Clojure, by Michael Fogus and Chris Houser who are both
active on IRC and this mailing list.

http://www.manning.com/fogus/



On Tue, Feb 16, 2010 at 5:29 PM, Andrey Fedorov anfedo...@gmail.com wrote:
 Hi all,

 I'm looking for approaches to learn about VM's, the JVM in particular.
 I noticed some local university courses use Virtual Machines (Smith,
 Nair) [1]. I'm planning on getting it, but would rather query you guys
 for opinions first, and recommendations on other books/resources?

 Cheers,
 Andrey


 1. http://www.amazon.com/gp/product/1558609105/

 --
 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: newbie question: Please help me stop creating constructors

2010-02-16 Thread Yaron
Sean and Richard perhaps I can address both of your mails in a single
go. Here is an example of one of the functions from my calculator:

(defn tax_deductible_expenses
The total expenses incurred in business month m that are deductible
from federal income tax
[m]
(let
[prepHouse (inflate *Prep_House_0* m)
 fixedMonthlyCost (if (= m (months_in_business)) 0
(fixed_monthly_cost m))]
(condp = (house_state m)
:ForLease (+ fixedMonthlyCost (if (= 
(month_in_rental_cycle m) 0)
prepHouse 0))
:Leased (+ fixedMonthlyCost (* (rental_income m) (+
*Management_Fee* (if (= (month_in_rental_cycle m)
*Months_To_Find_Tenant*) *Tenant_Finding_Fee* 0
:ForSale (+ fixedMonthlyCost (if (= m 
(months_actively_renting))
prepHouse 0))
:Sold (house_sales_expenses m

Right now the function takes a single argument, m which is the month
that tax deductible expenses are being calculated for. All the other
values it needs are constants (e.g. either values provided at the
start by the user or derived values).

Now please look at a test I wrote to make sure the function does what
I think it does:

(deftest tax_deductible_expenses_basic
  (binding
[*Months_To_Find_Tenant* 5
 *Months_In_Lease* 5
 *Lease_Cycles* 1
 *House_Sales_Price_0* 300
 *Monthly_Inflation_Rate* 0.002
 *Buying_Agent_Fee_Type* :Percentage
 *Buying_Agent_Fee_Number* 0.05
 *Selling_Agent_Fee_Type* :FlatFee
 *Selling_Agent_Fee_Number* 1000
 *Other_Sales_Fee_0* 100
 *Excise_Tax* 0.5
 *Original_Loan_Amount* 1
 *Monthly_Loan_Interest* (/ 0.05 12)
 *Months_In_Loan* (* 10 12)
 *Loan_Month_At_Start* 3
 *Prep_House_0* 100
 *Management_Fee* 2
 *Tenant_Finding_Fee* 0.5
 *Months_To_Sell* 3]
 (is (= (tax_deductible_expenses 0) (+ (fixed_monthly_cost 0)
100)))
 (is (= (tax_deductible_expenses 1) (fixed_monthly_cost 1)))
 (is (= (tax_deductible_expenses 5) (+ (fixed_monthly_cost 5) (*
(rental_income 5) 2.5
 (is (= (tax_deductible_expenses 7) (+ (fixed_monthly_cost 7) (*
(rental_income 7) 2
 (is (= (tax_deductible_expenses 10) (+ (fixed_monthly_cost 10)
(inflate 100 10
 (is (= (tax_deductible_expenses 12) (fixed_monthly_cost 12)))
 (is (= (tax_deductible_expenses 13) (house_sales_expenses 13)

For the method tax_deductible_expenses to run it ends up requiring 19
user defined values. That's a whole lot of arguments to pass into a
function. Obviously I could wrap them up in a StructMap but then I get
expressions like (+ 1 (args :B)) which doesn't seem much better than
(+1 (B)).

The issue I'm really trying to put my finger on is - these arguments
really and truly are 'constants' within the context of the calculator.
But they are constants whose values are not known as compile time but
rather are known at run time. Does Clojure have a way to express a
'late bound' constant or is the 'right' solution to pass around 19+
arguments to functions or passing around StructMaps or making
everything into thunks?

   Thanks!

 Yaron

On Feb 15, 1:33 pm, Richard Newman holyg...@gmail.com wrote:
  So imagine the user submits a value A. I will have a value B whose
  definition will be something like (+ 1 A) (yes, more complex in
  reality, but you get the idea).

 In Java, everything's an object, so you go about this by defining some  
 class. All of its private members, its constructors, and its accessors  
 are there to support one thing: should I sell or rent my home?

 That is, rather than saying something like:

 should-i-sell given that:
    current-home-price = 100,000
    current-interest-rate = 5.2%
    ...

 you say

 HomeCalculator c = new HomeCalculator(10, 5.2, ...);
 boolean shouldSell = c.shouldSell();

 and the logic is tied up in the shouldSell method definition.

 When someone calls .setA(...), you have to recompute B, or you have to  
 make sure that B is dynamically computed in .getB().

 That's not how you do things in a functional programming language. You  
 don't define global variables B and A. Define functions that  
 compute things; thread them together; and then push your values in the  
 top.

 Start from the bottom up and the top down together; build a tree of  
 functions that compute what you want. For example, you might think  
 ah, I need to figure out my monthly payment on my mortgage. That's a  
 function of the initial principal, the term, and the rate:

 (defn monthly-payment [principal term-in-months interest-rate]
    ...)

 Then you want to figure out how much more or less you'll pay, assuming  
 a growth in rents of a certain percentage, over some number of months  
 spent living in the house. Let's start by computing a sequence of  
 rents, increasing over time:

 (defn monthly-rent [starting-value monthly-increase]
    (lazy-seq
      starting-value
      

Code Review: how can I make this socket code more functional?

2010-02-16 Thread Matt Culbreth
Hello Group,

I'm writing a web server in Clojure and I'd love to have a bit of help
on a function I have.

This function (and at http://gist.github.com/305909) is used to read
the HTTP request from a client and to then act on it:

(defn handle-request
[in out]
(binding [*in* (BufferedReader. (InputStreamReader. in))]
(let [client-out (OutputStreamWriter. out)]
(loop [lines []]
(let [input (read-line)]
(if
(= (.length input) 0)
;; 0 length line means it's time to serve the
resource
(println lines)
;; add to the lines vector and keep going
;; note it makes the incoming request reversed
(recur (cons input lines

The code works fine; I've left out the bit that actually does
something and replaced it with a println call.  It's not very
functional feeling though.  The loop/recur and the building of a list
seems very imperative to me.  I'd much rather use something from
clojure.contrib.io, probably using read-lines or something.

Thanks for looking and for any suggestions!

Matt

-- 
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: newbie question: Please help me stop creating constructors

2010-02-16 Thread Jarkko Oranen


On Feb 16, 8:27 pm, Yaron ygol...@gmail.com wrote:
 Sean and Richard perhaps I can address both of your mails in a single
 go. Here is an example of one of the functions from my calculator:

 (defn tax_deductible_expenses
         The total expenses incurred in business month m that are deductible
 from federal income tax
         [m]
         (let
                 [prepHouse (inflate *Prep_House_0* m)
                  fixedMonthlyCost (if (= m (months_in_business)) 0
 (fixed_monthly_cost m))]
                 (condp = (house_state m)
                         :ForLease (+ fixedMonthlyCost (if (= 
 (month_in_rental_cycle m) 0)
 prepHouse 0))
                         :Leased (+ fixedMonthlyCost (* (rental_income m) (+
 *Management_Fee* (if (= (month_in_rental_cycle m)
 *Months_To_Find_Tenant*) *Tenant_Finding_Fee* 0
                         :ForSale (+ fixedMonthlyCost (if (= m 
 (months_actively_renting))
 prepHouse 0))
                         :Sold (house_sales_expenses m

 Right now the function takes a single argument, m which is the month
 that tax deductible expenses are being calculated for. All the other
 values it needs are constants (e.g. either values provided at the
 start by the user or derived values).

First, a style nitpick: use foo-bar instead of fooBar or foo_bar
secondly, yes, you really should pass in a map of all the relevant
information. It might help to split up your calculator into multiple
functions, each of which deals with only part of the map. It might
even make sense to group the arguments a bit and pass in multiple
maps, or just some args outside of a map. The ideal is that a function
depends only on its parameters. Having many rebindable globals is
certainly *not* the way to go. :) For derived values, you might be
able to use let-bound locals.


 Now please look at a test I wrote to make sure the function does what
 I think it does:

 (deftest tax_deductible_expenses_basic
   (binding
     [*Months_To_Find_Tenant* 5
      *Months_In_Lease* 5
      *Lease_Cycles* 1
      *House_Sales_Price_0* 300
      *Monthly_Inflation_Rate* 0.002
      *Buying_Agent_Fee_Type* :Percentage
      *Buying_Agent_Fee_Number* 0.05
      *Selling_Agent_Fee_Type* :FlatFee
      *Selling_Agent_Fee_Number* 1000
      *Other_Sales_Fee_0* 100
      *Excise_Tax* 0.5
      *Original_Loan_Amount* 1
      *Monthly_Loan_Interest* (/ 0.05 12)
      *Months_In_Loan* (* 10 12)
      *Loan_Month_At_Start* 3
      *Prep_House_0* 100
      *Management_Fee* 2
      *Tenant_Finding_Fee* 0.5
      *Months_To_Sell* 3]
      (is (= (tax_deductible_expenses 0) (+ (fixed_monthly_cost 0)
 100)))
      (is (= (tax_deductible_expenses 1) (fixed_monthly_cost 1)))
      (is (= (tax_deductible_expenses 5) (+ (fixed_monthly_cost 5) (*
 (rental_income 5) 2.5
      (is (= (tax_deductible_expenses 7) (+ (fixed_monthly_cost 7) (*
 (rental_income 7) 2
      (is (= (tax_deductible_expenses 10) (+ (fixed_monthly_cost 10)
 (inflate 100 10
      (is (= (tax_deductible_expenses 12) (fixed_monthly_cost 12)))
      (is (= (tax_deductible_expenses 13) (house_sales_expenses 13)

 For the method tax_deductible_expenses to run it ends up requiring 19
 user defined values. That's a whole lot of arguments to pass into a
 function. Obviously I could wrap them up in a StructMap but then I get
 expressions like (+ 1 (args :B)) which doesn't seem much better than
 (+1 (B)).

 The issue I'm really trying to put my finger on is - these arguments
 really and truly are 'constants' within the context of the calculator.
 But they are constants whose values are not known as compile time but
 rather are known at run time. Does Clojure have a way to express a
 'late bound' constant or is the 'right' solution to pass around 19+
 arguments to functions or passing around StructMaps or making
 everything into thunks?


If you're passing 19 arguments to a function, it's most likely doing
too much. See if you can split up the logic somewhat.

-- 
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: Code Review: how can I make this socket code more functional?

2010-02-16 Thread Alan Dipert
Hi Matt,
I think what you're looking for is line-seq:
http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/line-seq

In your code, if you pass *in* to line-seq, you'll get back a seq of lines
(the request headers).  Incidentally, I first ran into line-seq in the
course of writing a Clojure web server as a first project.  You can see
line-seq in action on line 52 of this gist, inside the 'handle-request'
function: http://gist.github.com/203329

I'm pretty new to Clojure myself so there might be a better way.  Hope
this helps,

Alan

Excerpts from Matt Culbreth's message of 2010-02-16 16:17:57 -0500:
 Hello Group,
 
 I'm writing a web server in Clojure and I'd love to have a bit of help
 on a function I have.
 
 This function (and at http://gist.github.com/305909) is used to read
 the HTTP request from a client and to then act on it:
 
 (defn handle-request
 [in out]
 (binding [*in* (BufferedReader. (InputStreamReader. in))]
 (let [client-out (OutputStreamWriter. out)]
 (loop [lines []]
 (let [input (read-line)]
 (if
 (= (.length input) 0)
 ;; 0 length line means it's time to serve the
 resource
 (println lines)
 ;; add to the lines vector and keep going
 ;; note it makes the incoming request reversed
 (recur (cons input lines
 
 The code works fine; I've left out the bit that actually does
 something and replaced it with a println call.  It's not very
 functional feeling though.  The loop/recur and the building of a list
 seems very imperative to me.  I'd much rather use something from
 clojure.contrib.io, probably using read-lines or something.
 
 Thanks for looking and for any suggestions!
 
 Matt
 
-- 
Alan Dipert
http://alan.dipert.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: Code Review: how can I make this socket code more functional?

2010-02-16 Thread Wilson MacGyver
assuming you are doing this using java servlet.

you may want to look at how compojure does this.

http://github.com/weavejester/compojure/blob/master/src/compojure/http/servlet.clj

it turns the request into a map.

and then various other parts of compojure can do different things
based on the map.

On Tue, Feb 16, 2010 at 4:17 PM, Matt Culbreth mattculbr...@gmail.com wrote:
 Hello Group,

 I'm writing a web server in Clojure and I'd love to have a bit of help
 on a function I have.

 This function (and at http://gist.github.com/305909) is used to read
 the HTTP request from a client and to then act on it:

 (defn handle-request
    [in out]
    (binding [*in* (BufferedReader. (InputStreamReader. in))]
        (let [client-out (OutputStreamWriter. out)]
            (loop [lines []]
                (let [input (read-line)]
                    (if
                        (= (.length input) 0)
                        ;; 0 length line means it's time to serve the
 resource
                        (println lines)
                        ;; add to the lines vector and keep going
                        ;; note it makes the incoming request reversed
                        (recur (cons input lines

 The code works fine; I've left out the bit that actually does
 something and replaced it with a println call.  It's not very
 functional feeling though.  The loop/recur and the building of a list
 seems very imperative to me.  I'd much rather use something from
 clojure.contrib.io, probably using read-lines or something.

 Thanks for looking and for any suggestions!

 Matt

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



-- 
Omnem crede diem tibi diluxisse supremum.

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


Re: send-off, number of threads processor load

2010-02-16 Thread Timothy Pratley
On 17 February 2010 06:18, Alex Ott alex...@gmail.com wrote:
 send-off to dispatch tasks, that stores some data into central agent.
 Tasks could be long running.
 Yes, all send-off are sent to one agent, that accumulate information about
 different documents

As Chouser pointed out, agents execute one thread at a time such that
their data access is synchronized. This is the coordination model they
expose. You want multiple threads so you need a different coordination
model. I would suggest using a ref as the central data store that can
be accessed by multiple worker threads.

A convenient way of spawning CPU limited worker threads is to use
(submit-future) to be found at the end of this thread:
http://groups.google.com/group/clojure/browse_thread/thread/51cea7e25fdfe653
or at github
http://github.com/timothypratley/strive/blob/master/clj/timothypratley/extensions.clj

However there are of course many different approaches to consider:
* use pcalls if appropriate
* use multiple agents
* use futures or threads
* do work on thread but coordinate with ref/agent/atom


Regards,
Tim.

-- 
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: What is a form, exactly? + Are there any guarantees about the return types of quote and syntax-quote?

2010-02-16 Thread Garth Sheldon-Coulson
Dear Meikel and Michal,

Thanks for your replies.

Meikel is right in observing that my question makes very little sense out of
context.

The reason I'm asking which Java classes can hold Clojure expressions is
that Clojuratica includes a Clojure s-expression reader, and I'm trying to
refine it. The reader allows the user to express Mathematica expressions in
Clojure syntax; for instance, the user can write the Mathematica expression
Apply[Plus, {1, 2}] as (Apply Plus [1 2]), and Clojuratica will evaluate
that expression in Mathematica even though the rest of the program is
written in Clojure. My question arises because I allow the user to unquote
*Clojure* data structures within the Clojure-syntax Mathematica expressions.
For instance, if x is the Clojure vector [1 2], I allow the user to write
(Apply Plus ~x), which evaluates to the same thing as the expression above.
But now suppose x is not a vector but a list (1 2). When the user writes
(Apply Plus ~x), I have to decide whether the list should be treated as an
expression (function 1, argument 2) or a data structure. I want the user to
be able to achieve either goal: unquote the expression (1 2) (like a macro),
or unquote the data (1 2). Hence I was trying to use the underlying Java
type to differentiate between x's that are expressions and x's that are
data: perhaps data if it's a lazy-seq, and expression if it's a cons or a
list.

However, your replies have made me realize that this approach is a mistake.
Instead, I need to decide whether x is an expression or data on the basis of
its context within the larger expression, not on the basis of its type.
That's the way Clojure does it: the seq (1 2) is always an expression,
regardless of its concrete type, unless it's quoted. So, I need to be more
precise about quoting and unquoting in Clojuratica. What I think I've
decided on is something like the following:

(def x '(1 2))

;in Clojuratica:
(Apply Plus ~x)   ; unquotes x as an expression: 1 is a function, 2 is the
argument

(Apply Plus ~~x)   ; unquotes x as data: treats x as the list (1 2)

or something along those lines. I have to try to make it congruent with
Clojure's quoting and unquoting conventions.

Thanks for your input. Your criticism of my premises made me rethink my
approach in a very constructive way.

Garth



On Mon, Feb 15, 2010 at 3:40 PM, Meikel Brandmeyer m...@kotka.de wrote:

 Hi,

 On Sun, Feb 14, 2010 at 08:58:56PM -0500, Garth Sheldon-Coulson wrote:

  (Revised version: What characterizes an expression? Is it correct to say
  that an expression is always something for which seq? returns true and
 never
  something for which seq? returns false?)

 I don't think so. {:a :b} is just an expression (which evaluates to a
 map) as is 5 (evaluating to 5) as is x (evaluating to whatever x is
 bound to) as is (inc 1) (evaluating to 2).

  And please consider the other questions revised as appropriate. In
  particular, please restrict my question about quote and syntax-quote to
  situations where they quote a form demarcated by parens. I would still
 like
  to know whether there is anything certain about the types returned by
 quote
  and syntax-quote when they are called on a paren-demacated form.

 As Clojure is based on abstractions everything relying on specific types
 should be questioned. Especially since in the future reify may kill that
 idea completely.

 My (certainly limited) experience with this kind of questions is: Why do
 you need to know? There may be perfectly valid reasons. Then I would go
 with seq?.

 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.comclojure%2bunsubscr...@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

swank-clojure and Cygwin

2010-02-16 Thread metaperl
Hello,

M-x slime

is failing on Emacs 23.1 under Cygwin as follows below.

My suspicion is that Unix paths are not being converted to Windows via
cygpath http://www.inonit.com/cygwin/faq/
before calling java -jar

===

(require 'swank.swank)

(swank.swank/ignore-protocol-version nil)

(do (.. java.net.InetAddress getLocalHost getHostAddress) nil)
(swank.swank/start-server /cygdrive/c/DOCUME~1/ADMINI~1/LOCALS~1/Temp/
slime.4420 :encoding iso-latin-1-unix)

java.lang.NoClassDefFoundError: clojure/main
Caused by: java.lang.ClassNotFoundException: clojure.main
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: clojure.main.  Program will exit.
Exception in thread main
Process inferior-lisp exited abnormally with code 1


==

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


Destructuring in clojure/binding

2010-02-16 Thread CuppoJava
Hi,
I found this old post:

http://groups.google.com/group/clojure/browse_thread/thread/45e118a638a5af8e/02eab5ae0d9023ff?lnk=gstq=binding+destructuring#02eab5ae0d9023ff

And was wondering what is the status of Stephen's patch?

Is there a reason why clojure/binding does not support destructuring
in its argument list?

(binding [[a b] [1 2]]
  (println a b))

gives:
 java.lang.ClassCastException: clojure.lang.PersistentVector cannot be
cast to clojure.lang.Symbol (NO_SOURCE_FILE:7)


Thanks for the help
  -Patrick

-- 
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: newbie question: Please help me stop creating constructors

2010-02-16 Thread CuppoJava
What do you think of the following style?

(defmacro in-environment [env  body]
  `(binding [*months-to-find-tenant* (:months-to-find-tenant env)
 *months-in-lease* (:months-in-lease env)
 *lease-cycles* (:lease-cycles env)
 etc...]
 ~...@body))

So env is a map that would contain the appropriate constants that
you need. Whenever you need them you can access them like this:

(in-environment env
  (tax-deductible-expenses 1))


That being said, I am not sure if that's the way I would do it. But I
haven't seen the rest of your program and it's possible that this is
perfectly justified.

  -Patrick

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


Re: Question about how I got run?

2010-02-16 Thread Mike Meyer
On Tue, 16 Feb 2010 11:13:28 -0800 (PST)
Daniel Werner daniel.d.wer...@googlemail.com wrote:

 On Feb 16, 2:12 am, Mike Meyer mwm-keyword-googlegroups.
 620...@mired.org wrote:
  Wouldn't be hard to do, either. Just bind *script-name* (or some such)
  to the path in script-opt, and let the client decide if it's the same
  as *file*.
 It would indeed be helpful if clojure.main bound a Var to the name of
 the .clj file being run, sort of like argv[0] in C. Like Michał
 suggested, there's the gen-class solution, but I personally tend avoid
 AOT-compiling Clojure code, which rules out gen-class.

I was surprised that *command-line-args* didn't include the script
name, which would have solved my problem. Of course, my usage is a
special case of the more general Unix trick of having programs vary
their behavior based on the name they were invoked with. And I just
realized another need for wanting the program name: how do I report
the program name in error messages? That's probably what argv[0] is
used for more than anything else.

Maybe the concept name the program was invoked with doesn't make
sense in a Java environment, what with having to have shell wrappers
around AOT code before it can be run anyway. Since clojure code can be
run as script, it might make sense there - if people distribute
applications a scripts instead of AOT code.

   mike
-- 
Mike Meyer m...@mired.org http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

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

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


Re: Question about how I got run?

2010-02-16 Thread Mike Meyer
On Tue, 16 Feb 2010 02:35:03 +0100
Michał Marczyk michal.marc...@gmail.com wrote:

 On 16 February 2010 02:12, Mike Meyer
 mwm-keyword-googlegroups.620...@mired.org wrote:
  To bad. It's really handy, especially as it starts trickling into
  system modules. You get one file that provides the simple command line
  usage plus functions that allow user to get to advanced usage. It also
  restores functionality that appears to be available in Java but not
  clojure, in that properly written scripts can then be invoked either
  from the command line, or as a function by an external caller.
 
 You can use gen-class to make your script runnable by Java. Just be
 sure to provide a -main function (or prefix-main, if you change the
 method prefix).

Might it be worthwhile tweaking clojure.main to run such a function if
it's found in a script that it's executing?

 mike
-- 
Mike Meyer m...@mired.org http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

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

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


Re: newbie question: Please help me stop creating constructors

2010-02-16 Thread Richard Newman

For the method tax_deductible_expenses to run it ends up requiring 19



user defined values. That's a whole lot of arguments to pass into a
function. Obviously I could wrap them up in a StructMap but then I get
expressions like (+ 1 (args :B)) which doesn't seem much better than
(+1 (B)).


Pass them in as a map, and destructure at the start of the function:

  (defn tax-deductible-expenses [{:keys [management-fee
 tenant-finding-fee ...]}]
...)


The issue I'm really trying to put my finger on is - these arguments
really and truly are 'constants' within the context of the calculator.
But they are constants whose values are not known as compile time but
rather are known at run time.


That they're constant does not mean that you shouldn't pass them as  
arguments to your functions.


Most values obtained from users or config files are such run-time  
constants. Heck, many values in most programs are -- HTTP listener  
port, log file location, etc.


You still invoke your HTTP server with a :port argument.

Indeed, the more fixed values you have, the less likely it is that you  
should define a var for each. Maybe one var containing a map, but I'd  
still pass the map around rather than having each function implicitly  
refer to it. It makes testing easier.




Does Clojure have a way to express a
'late bound' constant or is the 'right' solution to pass around 19+
arguments to functions or passing around StructMaps or making
everything into thunks?


The reason you pass them around as arguments is so that the behavior  
of your functions is precisely determined *only* by its arguments --  
they are pure.


That means that you can memoize them, easily write tests for them,  
have them work correctly when part of a lazy sequence (which will  
often be evaluated outside the scope of your bindings), etc.


For example: how would you compare the tax-deductible-expenses of two  
clients? You'd need to invoke the function twice, with a huge nest of  
bindings around each call. Much better would be to store the  
appropriate values in two maps, then say


  ( (tax-deductible-expenses 0 john-data)
 (tax-deductible-expenses 0 bill-data))

-R


--
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: Code Review: how can I make this socket code more functional?

2010-02-16 Thread e
i'm interested in seeing how this progresses ... like how you'd spawn
handlers asynchronously to service the requests.  was thinking about doing
this exercise myself at some point.

On Tue, Feb 16, 2010 at 4:30 PM, Alan Dipert alan.dip...@gmail.com wrote:

 Hi Matt,
 I think what you're looking for is line-seq:

 http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/line-seq

 In your code, if you pass *in* to line-seq, you'll get back a seq of lines
 (the request headers).  Incidentally, I first ran into line-seq in the
 course of writing a Clojure web server as a first project.  You can see
 line-seq in action on line 52 of this gist, inside the 'handle-request'
 function: http://gist.github.com/203329

 I'm pretty new to Clojure myself so there might be a better way.  Hope
 this helps,

 Alan

 Excerpts from Matt Culbreth's message of 2010-02-16 16:17:57 -0500:
  Hello Group,
 
  I'm writing a web server in Clojure and I'd love to have a bit of help
  on a function I have.
 
  This function (and at http://gist.github.com/305909) is used to read
  the HTTP request from a client and to then act on it:
 
  (defn handle-request
  [in out]
  (binding [*in* (BufferedReader. (InputStreamReader. in))]
  (let [client-out (OutputStreamWriter. out)]
  (loop [lines []]
  (let [input (read-line)]
  (if
  (= (.length input) 0)
  ;; 0 length line means it's time to serve the
  resource
  (println lines)
  ;; add to the lines vector and keep going
  ;; note it makes the incoming request reversed
  (recur (cons input lines
 
  The code works fine; I've left out the bit that actually does
  something and replaced it with a println call.  It's not very
  functional feeling though.  The loop/recur and the building of a list
  seems very imperative to me.  I'd much rather use something from
  clojure.contrib.io, probably using read-lines or something.
 
  Thanks for looking and for any suggestions!
 
  Matt
 
 --
 Alan Dipert
 http://alan.dipert.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.comclojure%2bunsubscr...@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

into map?

2010-02-16 Thread Base
Hi All,

I am struggling with inserting items into a map.

I would like to create a function that would create a map that would
look like

{  0 [ 01 2 3] ,
   1 [0 1 2 3] ,
   2 [0 1 2 3] }

and want to do something like

(defn create-map []
(into {} (dotimes [x 2] (assoc x (range 4)

but this, of course, doesnt work, since we are not naming the map
like

(assoc map_name key val)

I started trying to use transients, etc but there has to be an easier
way

-- 
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: into map?

2010-02-16 Thread Timothy Pratley
On 17 February 2010 13:55, Base basselh...@gmail.com wrote:
 {  0 [ 01 2 3] ,
   1 [0 1 2 3] ,
   2 [0 1 2 3] }

 and want to do something like
 (defn create-map []
    (into {} (dotimes [x 2] (assoc x (range 4)


(zipmap (range 3) (repeat 3 (range 4)))

-- 
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: into map?

2010-02-16 Thread Mark Engelberg
dotimes is for side effects.  What you want is to use a for loop that
produces a sequence of key-value pairs.

(into {} (for [i (range 3)] [i (range 4)]))

-- 
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: into map?

2010-02-16 Thread Base
2 things about Clojure

1.  It amazes me how easy it is to get things done
2.  The Clojure Group members are fantastic!

Thanks guys!!


On Feb 16, 10:19 pm, Mark Engelberg mark.engelb...@gmail.com wrote:
 dotimes is for side effects.  What you want is to use a for loop that
 produces a sequence of key-value pairs.

 (into {} (for [i (range 3)] [i (range 4)]))

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


#clojure irc

2010-02-16 Thread Brian Wolf

Hi,

I was wondering if irc #clojure is open to anyone and if it is, what is 
the protocol?


I get cannot send to channel error. I'm not familiar with irc.

Thanks

Brian





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

2010-02-16 Thread Nurullah Akkaya
On Wed, Feb 17, 2010 at 6:10 AM, Brian Wolf brw...@gmail.com wrote:

 Hi,

 I was wondering if irc #clojure is open to anyone and if it is, what is the
 protocol?

 I get cannot send to channel error. I'm not familiar with irc.

 Thanks

 Brian





 --
 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.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



Freenodes new policy to fight spam.
You need to register your nick.

http://www.wikihow.com/Register-a-User-Name-on-Freenode

--
Nurullah Akkaya
http://nakkaya.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: Emacs/Slime -- Slime wont eval but *inferior-lisp* will (Help a newbie out)

2010-02-16 Thread joseph hirn
Thank you Phil. I appreciate your help. Unfortunately I'm still having
issues. Sorry for being a newbie.

Do I still have to do manual edits to my .emacs file for swank-
classpath and whatnot? I started with a blank .emacs file
and .emacs.d directory and followed the recommend use of ELPA. When
installing via ELPA I get the following output to my *Compile-Log*
buffer:


Compiling file /home/mov/.emacs.d/elpa/clojure-mode-1.6/clojure-mode-
pkg.el at Tue Feb 16 23:22:53 2010

Compiling file /home/mov/.emacs.d/elpa/clojure-mode-1.6/clojure-
mode.el at Tue Feb 16 23:22:53 2010
clojure-mode.el:69:1:Warning: cl package required at runtime

In clojure-mode:
clojure-mode.el:196:34:Warning: reference to free variable `paredit-
mode'
clojure-mode.el:196:51:Warning: reference to free variable `paredit-
version'

In clojure-font-lock-extend-region-def:
clojure-mode.el:232:33:Warning: reference to free variable `font-lock-
beg'
clojure-mode.el:239:30:Warning: assignment to free variable `font-lock-
beg'
clojure-mode.el:240:33:Warning: reference to free variable `font-lock-
end'
clojure-mode.el:242:19:Warning: assignment to free variable `font-lock-
end'

In clojure-font-lock-extend-region-comment:
clojure-mode.el:257:26:Warning: reference to free variable `font-lock-
beg'
clojure-mode.el:254:49:Warning: reference to free variable `font-lock-
end'
clojure-mode.el:258:17:Warning: assignment to free variable `font-lock-
beg'
clojure-mode.el:262:17:Warning: assignment to free variable `font-lock-
end'

In clojure-indent-function:
clojure-mode.el:397:33:Warning: reference to free variable
`calculate-lisp-indent-last-sexp'

In clojure-slime-config:
clojure-mode.el:574:11:Warning: assignment to free variable
`swank-clojure-classpath'

In end of data:
clojure-mode.el:684:1:Warning: the following functions are not known
to be defined:
imenu--generic-function, inferior-lisp-proc, switch-to-lisp,
swank-clojure-slime-mode-hook

Compiling no file at Tue Feb 16 23:22:54 2010

Compiling file /home/mov/.emacs.d/elpa/swank-clojure-1.1.0/swank-
clojure-pkg.el at Tue Feb 16 23:22:54 2010

Compiling file /home/mov/.emacs.d/elpa/swank-clojure-1.1.0/swank-
clojure.el at Tue Feb 16 23:22:55 2010
swank-clojure.el:48:1:Error: Cannot open load file: clojure-mode


Then when I M-x slime I get this output to *inferior-lisp* and slime
never loads.


(require 'swank.swank)

(swank.swank/ignore-protocol-version nil)

(do (.. java.net.InetAddress getLocalHost getHostAddress) nil)
(swank.swank/start-server /tmp/slime.28344 :encoding iso-latin-1-
unix)

Clojure 1.1.0
user= java.io.FileNotFoundException: Could not locate swank/
swank__init.class or swank/swank.clj on classpath:  (NO_SOURCE_FILE:0)
user= user= java.lang.ClassNotFoundException: swank.swank
(NO_SOURCE_FILE:0)
user= user= nil
java.lang.ClassNotFoundException: swank.swank (NO_SOURCE_FILE:0)
***

On Feb 15, 4:23 pm, Phil Hagelberg p...@hagelb.org wrote:
 On Mon, Feb 15, 2010 at 12:58 PM, joseph hirn joseph.h...@gmail.com wrote:
  Hello. I've been trying to get emacs/slime running for a while on
  ubuntu 9.10. I used clojure box for Windows and that was excellent but
  this is not running very well for me.

  I compiled clojure and clojure-contrib.jar by cloning the
  repositories, checking out tag 1.1.0 and building them with ant. I
  then followed these instructions to a t (http://riddell.us/tutorial/
  slime_swank/slime_swank.html).  I've downloaded swank-clojure/slime/
  clojure-mode as the instructions but used the latest code (I did not
  checkout a different tag). I have also tried emacs and emacs-snapshot,
  both installed via apt-get.

 Those instructions are pretty old. Have you tried the official readme?

 http://github.com/technomancy/swank-clojure

 Be sure to remove all the manual configuration from following the old
 instructions.

 -Phil

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


Re: Emacs/Slime -- Slime wont eval but *inferior-lisp* will (Help a newbie out)

2010-02-16 Thread joseph hirn
Hi Steve. Thanks for your help. I tried the up to date instructions
per the readme file on swank-clojure homepage (using ELPA)  and now
the problem is that slime never loads. The expression you gave me does
eval in the *inferior-lisp* buffer but I do not get a slime connection
at all now. It is stuck with this at the bottom:

Polling /tmp/slime/28940.. (Abort with `M-x slime-abort-connection')

On Feb 15, 7:07 pm, Steven E. Harris s...@panix.com wrote:
 joseph hirn joseph.h...@gmail.com writes:
  All seems to be well when I M-x slime, but if I enter (+ 1 2) it just
  hangs. If I switch to the *inferior-lisp* buffer and type this
  expression it returns 3 as expected.

 I have the same problem, as documented here:

  http://thread.gmane.org/gmane.comp.java.clojure.user/24894/focus=24956

 In the *inferior-lisp* buffer, try evaluating the following form:

   (.. java.lang.management.ManagementFactory (getRuntimeMXBean) (getName))

 Does that cause SLIME's REPL to finally connect to Swank?

 --
 Steven E. Harris

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


clojure-contrib on Windows

2010-02-16 Thread Ram
I'm having an issue compiling clojure-contrib on Windows.

I downloaded the code from the git repository and when I run Maven,
after compilation it runs through the test suite fails in test-io:

FAIL in (test-as-url) (run-test5405918110152723544.clj:47)
expected: (= (URL. file:/foo) (as-url (File. /foo)))
  actual: (not (= #URL file:/foo #URL file:/C:/foo))

I'm guessing someone expected UNIX style filenames in this test case
and not Windows filenames, but that is besides the issue. The issue is
that the jars aren't actually generating themselves. Am I missing
something? If I am, its probably something really dumb.

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


swank-clojure and debian/stable issue

2010-02-16 Thread Terrence Brannon
After installing swank-clojure via ELPA on emacs23, and type M-x slime, I
get this error:

(require 'swank.swank)

(swank.swank/ignore-protocol-version nil)

(do (.. java.net.InetAddress getLocalHost getHostAddress)
nil)(swank.swank/start-server /tmp/slime.29897 :encoding
iso-latin-1-unix)

Exception in thread main java.lang.NoClassDefFoundError:
clojure.lang.Symbol
   at clojure.main.clinit(main.java:19)
   at java.lang.Class.initializeClass(libgcj.so.70)

Process inferior-lisp exited abnormally with code 1

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

Re: newbie question: Please help me stop creating constructors

2010-02-16 Thread Yaron
I have posted a file (http://www.goland.org/sellorrent.pdf) which
explains the math behind the calculator. The file gives all the
algebra needed to implement the calculator. At the moment I'm just
taking the boneheaded approach and implementing all the logic in
Clojure as more or less a one to one mapping of the functions in the
PDF file.

Please, please, please, keep in mind that the linked article is a very
rough, rough draft. It is not ready for prime time. I am only sharing
it so that you can see what I'm trying to implement and hopefully
guide me to the right way to implement it.

It seems however that the consensus of the group based on what I've
said so far is to pass around state in a structmap. This is nice in
that it makes each function completely self contained (e.g. no
external references). It's unfortunate in that it now means that every
single function needs this extra argument and every variable access
either needs to use the :keys feature in the arguments or has to
directly refer to the keys in the map.

I really wish there was a way for me to just declare a context, define
a bunch of statics and then define all my methods inside of that
context. But it doesn't seem like this is the clojure way of handling
the problem. Where as many aspects of functional programming make a
ton of sense to me having to carry a map around everywhere doesn't
seem like an advantage. But I'm probably just missing something.

   Yaron


On Feb 16, 1:20 pm, Richard Newman holyg...@gmail.com wrote:
  For the method tax_deductible_expenses to run it ends up requiring 19
  user defined values. That's a whole lot of arguments to pass into a
  function. Obviously I could wrap them up in a StructMap but then I get
  expressions like (+ 1 (args :B)) which doesn't seem much better than
  (+1 (B)).

 Pass them in as a map, and destructure at the start of the function:

    (defn tax-deductible-expenses [{:keys [management-fee
                                           tenant-finding-fee ...]}]
      ...)

  The issue I'm really trying to put my finger on is - these arguments
  really and truly are 'constants' within the context of the calculator.
  But they are constants whose values are not known as compile time but
  rather are known at run time.

 That they're constant does not mean that you shouldn't pass them as  
 arguments to your functions.

 Most values obtained from users or config files are such run-time  
 constants. Heck, many values in most programs are -- HTTP listener  
 port, log file location, etc.

 You still invoke your HTTP server with a :port argument.

 Indeed, the more fixed values you have, the less likely it is that you  
 should define a var for each. Maybe one var containing a map, but I'd  
 still pass the map around rather than having each function implicitly  
 refer to it. It makes testing easier.

  Does Clojure have a way to express a
  'late bound' constant or is the 'right' solution to pass around 19+
  arguments to functions or passing around StructMaps or making
  everything into thunks?

 The reason you pass them around as arguments is so that the behavior  
 of your functions is precisely determined *only* by its arguments --  
 they are pure.

 That means that you can memoize them, easily write tests for them,  
 have them work correctly when part of a lazy sequence (which will  
 often be evaluated outside the scope of your bindings), etc.

 For example: how would you compare the tax-deductible-expenses of two  
 clients? You'd need to invoke the function twice, with a huge nest of  
 bindings around each call. Much better would be to store the  
 appropriate values in two maps, then say

    ( (tax-deductible-expenses 0 john-data)
       (tax-deductible-expenses 0 bill-data))

 -R

-- 
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: Emacs/Slime -- Slime wont eval but *inferior-lisp* will (Help a newbie out)

2010-02-16 Thread Phil Hagelberg
On Tue, Feb 16, 2010 at 10:34 PM, joseph hirn joseph.h...@gmail.com wrote:
 Hi Steve. Thanks for your help. I tried the up to date instructions
 per the readme file on swank-clojure homepage (using ELPA)  and now
 the problem is that slime never loads. The expression you gave me does
 eval in the *inferior-lisp* buffer but I do not get a slime connection
 at all now. It is stuck with this at the bottom:

 Polling /tmp/slime/28940.. (Abort with `M-x slime-abort-connection')

What does it say in the *inferior-lisp* buffer? Any messages?

There were some issues with the auto-download of Clojure jars in older
versions Emacs. You can try removing your ~/.swank-clojure directory
and retrying, or you could try upgrading to a recent version of Emacs
(23).

-Phil

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


Re: swank-clojure and debian/stable issue

2010-02-16 Thread Phil Hagelberg
On Tue, Feb 16, 2010 at 2:55 PM, Terrence Brannon scheme...@gmail.com wrote:
 After installing swank-clojure via ELPA on emacs23, and type M-x slime, I
 get this error:
 (require 'swank.swank)
 (swank.swank/ignore-protocol-version nil)
 (do (.. java.net.InetAddress getLocalHost getHostAddress)
 nil)(swank.swank/start-server /tmp/slime.29897 :encoding
 iso-latin-1-unix)
 Exception in thread main java.lang.NoClassDefFoundError:
 clojure.lang.Symbol
    at clojure.main.clinit(main.java:19)
    at java.lang.Class.initializeClass(libgcj.so.70)

Looks like you're using gcj instead of openjdk or Sun's. I don't know
if this is supported by Clojure; but it's not supported by swank. Try
switching to openjdk-6.

-Phil

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


Re: into map?

2010-02-16 Thread Meikel Brandmeyer
Hi,

On Feb 17, 4:19 am, Mark Engelberg mark.engelb...@gmail.com wrote:

 dotimes is for side effects.

As a rule of thumb: everything starting with do is related to side
effects.

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: newbie question: Please help me stop creating constructors

2010-02-16 Thread Richard Newman

It seems however that the consensus of the group based on what I've
said so far is to pass around state in a structmap.


Not necessarily a struct-map. Just a map.


This is nice in
that it makes each function completely self contained (e.g. no
external references). It's unfortunate in that it now means that every
single function needs this extra argument and every variable access
either needs to use the :keys feature in the arguments or has to
directly refer to the keys in the map.


Not necessarily. At some point your functions should be fine-grained  
enough that they only take a couple of arguments. As soon as you drop  
below 6 or 7, where they're all mandatory, switch to ordinary function  
argument style.


Wherever you call those functions should do the unpacking.

E.g.,

(defn outer-1 [{:keys [foo bar baz noo]}]
  (let [interm (foo-bar foo bar)
fiddle (frostrup baz noo)]
(tweep interm fiddle)))

After all, your house-sale-profit function should be expressed in  
terms of two arguments:


(defn house-sale-profit [house-sale-price house-sale-expenses]
  ...)

It doesn't care about the other 17.

Another thing: that big entry point function is like a much tidier  
version of the Java constructor that you created with 19 arguments --  
tidier in that you can use named keys or a map to identify the  
arguments.


--
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: What is a form, exactly? + Are there any guarantees about the return types of quote and syntax-quote?

2010-02-16 Thread Meikel Brandmeyer
Hi,

On Feb 16, 11:26 pm, Garth Sheldon-Coulson g...@mit.edu wrote:


 The reason I'm asking which Java classes can hold Clojure expressions is
 --context snipped---
 list.

Ok. I understand your problem. You have maction - a mix between macro
and function - and you are not sure when to evaluate something
unquoted (function behaviour) and when not (macro behaviour). You
problem arises because you want to allow something like this (silly
example):

(def x '(Apply Plus [1 2]))
(Apply Plus ~x)

I suppose, the Apply call is contained in some wrapper macro?
(mathematica (Apply Plus ~x))? You could provide a mathematica*
function which does the work. Then the user can choose:

(def x '(Apply Plus [1 29])
(def y (list 1 2))

(mathematica (Apply Plus ~(mathematica* x) ~y))

 What I think I've decided on is something like the following:

 (def x '(1 2))

 ;in Clojuratica:
 (Apply Plus ~x)   ; unquotes x as an expression: 1 is a function, 2 is the
 argument

 (Apply Plus ~~x)   ; unquotes x as data: treats x as the list (1 2)

 or something along those lines. I have to try to make it congruent with
 Clojure's quoting and unquoting conventions.

This hijacks a little bit the unquoting. I don't know in how far this
will be of relevance, but if you use something like this in a macro,
you might run into trouble because suddenly the unquoting doesn't
match anymore. However this is only a rather fuzzy fear. You should do
some tests.

Basically it's the same idea as I proposed above: let the user specify
what he wants.

 Thanks for your input. Your criticism of my premises made me rethink my
 approach in a very constructive way.

You are welcome. :)

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: Emacs/Slime -- Slime wont eval but *inferior-lisp* will (Help a newbie out)

2010-02-16 Thread joseph hirn
Thanks again Phil.

The message above where I get FileNotFoundException Could not locate
swank is from my *inferior-lisp* buffer.

I am using emacs 23. I've tried with this and the gtk-snapshot
versions togging using update-alternative --config emacs.

I do not have a ~/.swank-clojure directory. I do have a swank-
clojure-1.1.0 directory from the swank install via elpa in ~/.emacs.d/
swank-clojure-1.1.0 but I have tried deleting that manually several
times and reinstalling it via elpa, no dice. I also had some seemingly
related files in ~/src but I removed all of those to start as fresh as
possible.

I do have CLOJURE_EXT set to ~/.clojure where the clojure.jar and
clojure-contrib.jar files are. Not sure if that affects anything. I
also have the clojure-contrib launcher linked to /usr/bin/clj for
command line REPL which works great.

Thanks again for your help.

On Feb 17, 12:40 am, Phil Hagelberg p...@hagelb.org wrote:
 On Tue, Feb 16, 2010 at 10:34 PM, joseph hirn joseph.h...@gmail.com wrote:
  Hi Steve. Thanks for your help. I tried the up to date instructions
  per the readme file on swank-clojure homepage (using ELPA)  and now
  the problem is that slime never loads. The expression you gave me does
  eval in the *inferior-lisp* buffer but I do not get a slime connection
  at all now. It is stuck with this at the bottom:

  Polling /tmp/slime/28940.. (Abort with `M-x slime-abort-connection')

 What does it say in the *inferior-lisp* buffer? Any messages?

 There were some issues with the auto-download of Clojure jars in older
 versions Emacs. You can try removing your ~/.swank-clojure directory
 and retrying, or you could try upgrading to a recent version of Emacs
 (23).

 -Phil

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


function that converts argument into a single value vector.

2010-02-16 Thread Vagif Verdi
I often find myself creating one line helper functions that i use very
often just because it is easier to write them than try to find them in
contrib.

Here's one:
(defn- to-list [x] (if (vector? x) x [x]))

This one is often needed when working with html form fields.

Is there such a function in contrib ?

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