Re: heaps in clojure

2011-09-15 Thread Sunil S Nandihalli
Thanks Jason,
 I think some sort of priority queue may be the solution.
Thanks,
Sunil.

On Wed, Sep 14, 2011 at 12:39 AM, Jason Wolfe ja...@w01fe.com wrote:

 There is java.util.PriorityQueue, which is heap-based:


 http://download.oracle.com/javase/1,5.0/docs/api/java/util/PriorityQueue.html

 -Jason


 On Sep 13, 4:44 am, Sunil S Nandihalli sunil.nandiha...@gmail.com
 wrote:
  Hi Everybody,
   I have a very large, but with finite size, collection. I would like to
 get
  like first 10 elements in the sorted list . I would use a heap if I were
 in
  c++ .. is there a inbuilt implementation of this in clojure? .. Is there
  some other way to achieve this? some sort of lazy sort would be perfect.
 I
  know I need the full collection to start with .. but that is fine.
  Thanks,
  Sunil.

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


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

Re: confusion with map and dosync

2011-09-15 Thread Matt Hoyt
Map is lazy so it only gets called when you need something from the sequence.  
To force it to be called you use doall so it would be (doall (map 
queue-copy-fetch fetches-seq)).

You only need the do sequence in queue-copy-fetch but not in process-indexes.
 
Matt Hoyt



From: c.taylor colin.tay...@gmail.com
To: Clojure clojure@googlegroups.com
Sent: Thursday, September 15, 2011 12:39 AM
Subject: confusion with map and dosync

I'm sure this is very straightforward but can someone enlighten me why
queue copy fetch is seemingly never called from within process-indexes
(the 'pre add' line is printed but the 'adding' debug line is never
printed). I've verified the correct contents of fetches-seq.  For a
bonus point can I ask if need the dosync inside q-c-f if its only ever
called from p-i ?

Any comments on style appreciated too.

(defn- queue-copy-fetch [cfetch]
  (println adding  cfetch)
  (dosync
    (alter copy-fetch-queue conj cfetch)))

(defn process-indexes []
  (while (seq @index-process-queue)
    (let [an-index (qpop index-process-queue)
          index-source (:source (:fetch an-index))
          index-content (:doc-seq an-index)
          links-seq ((:copy-link-selector index-source) index-content)
          fetches-seq (map (partial fetch index-source) links-seq)]
      (println   pre add)
      (dosync (map queue-copy-fetch fetches-seq)



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: confusion with map and dosync

2011-09-15 Thread Luc Prefontaine
Map returns a lazy sequence, the list of values is not realized yet,
you need to consume the lazy seq to obtain the values.

You should use (doseq [f fetches-seq] (queue-copy-fetch f))) if you have only 
side effects to generate and do
not care about reusing the values returned by queue-copy-fetch. doseq returns 
nil.

If you need to reuse the results from the calls later, look at doall. This one 
will retain
the head as in:

(doall (map queue-copy-fetch fetches-seq))

It takes some time to get used to lazy sequences. Look carefully at the API doc 
to
spot fns that return lazy sequences. It's not because the REPL gives an output 
that you are
not dealing with a lazy sequence. The REPL will consume the lazy seq if it's 
the last result
available and walk through it to print you an output.

Luc P.

On Wed, 14 Sep 2011 22:39:42 -0700 (PDT)
c.taylor colin.tay...@gmail.com wrote:

 I'm sure this is very straightforward but can someone enlighten me why
 queue copy fetch is seemingly never called from within process-indexes
 (the 'pre add' line is printed but the 'adding' debug line is never
 printed). I've verified the correct contents of fetches-seq.  For a
 bonus point can I ask if need the dosync inside q-c-f if its only ever
 called from p-i ?
 
 Any comments on style appreciated too.
 
 (defn- queue-copy-fetch [cfetch]
   (println adding  cfetch)
   (dosync
 (alter copy-fetch-queue conj cfetch)))
 
 (defn process-indexes []
   (while (seq @index-process-queue)
 (let [an-index (qpop index-process-queue)
   index-source (:source (:fetch an-index))
   index-content (:doc-seq an-index)
   links-seq ((:copy-link-selector index-source) index-content)
   fetches-seq (map (partial fetch index-source) links-seq)]
   (println   pre add)
   (dosync (map queue-copy-fetch fetches-seq)
 
 
 



-- 
Luc P.


The rabid Muppet

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


Re: confusion with map and dosync

2011-09-15 Thread Matt Hoyt
You only need the do sequence in queue-copy-fetch but not in process-indexes 
should be You only need the dosync in queue-copy-fetch but not in 
process-indexes.
 
Matt Hoyt



From: Matt Hoyt mrho...@yahoo.com
To: clojure@googlegroups.com clojure@googlegroups.com
Sent: Thursday, September 15, 2011 1:01 AM
Subject: Re: confusion with map and dosync


Map is lazy so it only gets called when you need something from the sequence.  
To force it to be called you use doall so it would be (doall (map 
queue-copy-fetch fetches-seq)).

You only need the do sequence in queue-copy-fetch but not in process-indexes.
 
Matt Hoyt



From: c.taylor colin.tay...@gmail.com
To: Clojure clojure@googlegroups.com
Sent: Thursday, September 15, 2011 12:39 AM
Subject: confusion with map and dosync

I'm sure this is very straightforward but can someone enlighten me why
queue copy fetch is seemingly never called from within process-indexes
(the 'pre add' line is printed but the 'adding' debug line is never
printed). I've verified the correct contents of fetches-seq.  For a
bonus point can I ask if need the dosync inside q-c-f if its only ever
called from p-i ?

Any comments on style appreciated too.

(defn- queue-copy-fetch [cfetch]
  (println adding  cfetch)
  (dosync
    (alter copy-fetch-queue conj cfetch)))

(defn process-indexes []
  (while (seq @index-process-queue)
    (let [an-index (qpop index-process-queue)
          index-source (:source (:fetch an-index))
          index-content (:doc-seq
 an-index)
          links-seq ((:copy-link-selector index-source) index-content)
          fetches-seq (map (partial fetch index-source) links-seq)]
      (println   pre add)
      (dosync (map queue-copy-fetch fetches-seq)



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Rounding the edges of an Emacs beginner

2011-09-15 Thread Timothy Washington
Nice. Thanks Peter. I use the n, p and v navigations now, but always want to
do that vim / Ctrl-d thing, lol. I figure I just need to spend some time
getting used to emacs' navigation idioms. It's going to take a lot of doing
to pull me away from vim habits.

Tim


On Wed, Sep 14, 2011 at 8:50 PM, Peter Buckley buckmeist...@gmail.comwrote:

 ** In emacs you can give a number to preface many commands, e.g. C-37 C-n
 will perform next line 37 times, and C-37 C-p will perform previous line
 37 times. You can setup keybindings for these as well, but I find the basic
 navigation commands like C-v/M-v (up/down a page) and C-l (center current
 line in the buffer) to be sufficient.
 --
 *From: * Timothy Washington twash...@gmail.com
 *Sender: * clojure@googlegroups.com
 *Date: *Wed, 14 Sep 2011 20:08:28 -0400
 *To: *clojure@googlegroups.com
 *ReplyTo: * clojure@googlegroups.com
 *Subject: *Re: Rounding the edges of an Emacs beginner

 Far out - this is great stuff. Thanks guys.

 Wrt to moving down (or up) a block, vim-style, what I mean is the following
 (all functionality in 'Command Mode').

 In Vim , you press *Ctrl-d* and *Ctrl-u* to go down and up a block
 respectively. Depending on the size of your window, it moves the cursor
 about 1/3rd of the way down (or up) the screen. This is very handy to have
 when just browsing a buffer. You can be more precise by pressing 37k, to
 move the cursor up 37 lines, etc.

 For whatever reason, I haven't been able to find something similar in
 Emacs.


 Tim


 On Wed, Sep 14, 2011 at 3:53 AM, Stefan Kamphausen ska2...@googlemail.com
  wrote:

 Hi,

 just a few follow-ups...

 On Wednesday, September 14, 2011 4:13:47 AM UTC+2, frye wrote:

- ? howto list modes engaged

 Aside from the already mentioned C-h m (aka M-x describe-mode) you will
 want to use

 * C-h k (M-x describe-key) followed by some keybinding to find out what
 that keybinding does
 * C-h w (M-x where-is) followed by the name of some command to find out
 what keybinding exists for that command
 * C-h a PATTERN (M-x apropos) to search for PATTERN in command names and
 variables (ah, I miss hyper-apropos from XEmacs)
 * C-h v VARIABLE (M-x describe-variable) to see the documentation for a
 variable in ELisp (use C-c C-d d on Clojure symbols to see their
 documentation from SLIME)
 * C-h f FUNCTION (M-x describe-function) to see docs for an Elisp-function
 * and finally C-h ? to find out what other help is available

 The built-in help system of Emacs is one of its greatest strengths.


-

? Can you use Emacs / Slime / CDT (debugging) with Ruby / Rails

 ? howto do Code completion (clojure, and elisp )


 Try TAB in the REPL and M-TAB in a Clojure-buffer when you are connected
 to a running image.


 As a VIM'er, I'm trying to do the following using emacs navigation, but
 seem to have missed the levers to pull. I'm using a vim navigation
 plugin http://gitorious.org/evil/pages/Home, which helps a lot.


- ? set line numbers


 I use linum.el written by  Markus Triska:
 (when (try-require 'linum) ;; try require is just a minor wrapper which
 checks, whether a lib is available
   (global-linum-mode))


- ? go to line 'n'

 Since my fingers are used to M-g I bind that key to goto-line :
 (global-set-key (kbd M-g) #'goto-line)


- ? how to jump to matching parentheses

 Meta with left and right cursor keys. Actually those are forward-sexpand
 backward-sexp


- ? move down a chunk like in vim

 What does that mean?


- ? yank 'n' lines - emacs yank puts back some 'killed' text ; HOWTO
copy

 Mark things by first enabling the mark with C-SPC. Move around using your
 usual command.  Copy to the kill-ring with M-w or cut the text and copy it
 to the kill-ring using C-w.  After that you can yank (Emacsspeak for
 'paste') from the kill ring with C-y.  Try M-y right after a C-y to get
 older elements on the kill-ring. For marking, try what C-M-SPC does, also
 hit it several times in a row.
 Warning: if your finger's memory learns this, using modern IDEs may feel
 awkward.

 Regards,
 Stefan

  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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 

using finger trees in two dimensions

2011-09-15 Thread Sunil S Nandihalli
Hi everybody,
Thanks to  Chouser's finger tree data structure, it makes it very simple to
keep some elements in a tree/sequence and efficiently maintain values by
some associative operation on all the elements of the collection .. I guess
chouser himself has given series of talks on that. However, I am trying to
see if I can do something like that for two-dimensional data.

For example,
 let us say I have points spread on XY plane, and two axes each parallel to
one of the coordinate axes. So, this would divide the data/points among the
4 quadrants. Now I would like to be able to efficiently divide the data
using the two axes at random and x's and y's and obtain the value of the
associative operation on the elements of each quadrant. for now it could
simply be the sum of the points coordinate wise..

While I have thought of a few options to make it work for two dimensions but
nothing seems right .. I would love to hear what others might have to say
about this.
Thanks
Sunil.

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

Re: Rounding the edges of an Emacs beginner

2011-09-15 Thread Stefan Kamphausen
Hi,

we're getting totally OT here and should probably better head for 
gnu.emacs.help.  Anyway, just one more bark from me and then I'll be quiet 
(but will respond to mail ;-)

On Thursday, September 15, 2011 2:08:28 AM UTC+2, frye wrote:

 In Vim , you press *Ctrl-d* and *Ctrl-u* to go down and up a block 
 respectively. Depending on the size of your window, it moves the cursor 
 about 1/3rd of the way down (or up) the screen. This is very handy to have 
 when just browsing a buffer. You can be more precise by pressing 37k, to 
 move the cursor up 37 lines, etc.  

 For whatever reason, I haven't been able to find something similar in 
 Emacs. 


OK, I tried what it does in vim.  Some things come to my mind.

1. PgUp/PgDn obviously
2. Try hitting C-l (that's an 'l' like in 'like') several times in a row.  
It won't move your cursor but the line it's on.
3. I've been using some personal binding on my home and end keys for ages 
which moves me  to the beginning/end of a line, beginning/end of the 
currently displayed window and beginning/end of the whole buffer on 
successive hits.  See chb-home and chb-end on 
http://www.skamphausen.de/cgi-bin/ska/dot-emacs.d-slash-init.el.  Combine 
that with C-l.
4. You might want to try out swiss-move.el (shameless self-plug).  Maybe 
it's confusing, maybe helpful.

Cheers,
Stefan

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

autoboxing in 1.3 RC-0

2011-09-15 Thread Sergey Didenko
Hi,

Is it a bug or I'm doing something wrong? I can't get rid of
auto-boxing in the second example, neither by type hinting nor by type
coercing of changed* locals.

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

This compiles fine:

(loop [x 1 changed 0]
  (if (= x 10)
changed
(recur (inc x)
   changed)))

And this gives the warning recur arg for primitive local: changed is
not matching primitive, had: Object, needed: long
Auto-boxing loop arg: change

(loop [x 1 changed 0]
  (if (= x 10)
changed
(recur (inc x)
   (loop [y 1 changed-y changed]
 changed-y

P.S. I omitted recur for the inner loop for clarity.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: heaps in clojure

2011-09-15 Thread Mark Engelberg
You can do one linear pass over your data, accumulating a sorted set of the
best 10 items you've found so far.  You seed the sorted set with the first
10 items from your list, then continue traversing your list.  With each new
item you encounter, you ask if it is any better than the worst of the
best-10-sorted-set.  If it is, then you add it to the sorted-set and boot
out the worst.  Since the sorted set never exceeds 10 items, there is a
small, constant bound for how long the operations on the sorted set will
take.  Thus this is a O(n) algorithm.

On Wed, Sep 14, 2011 at 10:59 PM, Sunil S Nandihalli 
sunil.nandiha...@gmail.com wrote:

 Hi chouser,
  Thanks for your response. but correct me if I am wrong.. wouldn't
 sorted-set completely sort the complete collection without actually taking
 into account that only the first few elements are needed?
 Thanks,
 Sunil.


 On Tue, Sep 13, 2011 at 7:15 PM, Chouser chou...@gmail.com wrote:

 On Tue, Sep 13, 2011 at 7:44 AM, Sunil S Nandihalli
 sunil.nandiha...@gmail.com wrote:
  Hi Everybody,
   I have a very large, but with finite size, collection. I would like to
 get
  like first 10 elements in the sorted list . I would use a heap if I were
 in
  c++ .. is there a inbuilt implementation of this in clojure? .. Is there
  some other way to achieve this? some sort of lazy sort would be perfect.
 I
  know I need the full collection to start with .. but that is fine.

 A seq on a sorted set should be pretty efficient.

 (take 3 (sorted-set 8 2 1 4 6 9 7 3))
 ;= (1 2 3)

 --Chouser

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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: heaps in clojure

2011-09-15 Thread David Powell
Does that work?

There is no guarantee that the top 10 of the overall list matches the top 10
of earlier prefixes, so the candidates that get discarded might be part of
the overall top 10, and the elements that pushed them out could just be
local maxima.

-- 
Dave
On 15 Sep 2011 08:23, Mark Engelberg mark.engelb...@gmail.com wrote:
 You can do one linear pass over your data, accumulating a sorted set of
the
 best 10 items you've found so far. You seed the sorted set with the first
 10 items from your list, then continue traversing your list. With each new
 item you encounter, you ask if it is any better than the worst of the
 best-10-sorted-set. If it is, then you add it to the sorted-set and boot
 out the worst. Since the sorted set never exceeds 10 items, there is a
 small, constant bound for how long the operations on the sorted set will
 take. Thus this is a O(n) algorithm.

 On Wed, Sep 14, 2011 at 10:59 PM, Sunil S Nandihalli 
 sunil.nandiha...@gmail.com wrote:

 Hi chouser,
 Thanks for your response. but correct me if I am wrong.. wouldn't
 sorted-set completely sort the complete collection without actually
taking
 into account that only the first few elements are needed?
 Thanks,
 Sunil.


 On Tue, Sep 13, 2011 at 7:15 PM, Chouser chou...@gmail.com wrote:

 On Tue, Sep 13, 2011 at 7:44 AM, Sunil S Nandihalli
 sunil.nandiha...@gmail.com wrote:
  Hi Everybody,
  I have a very large, but with finite size, collection. I would like to
 get
  like first 10 elements in the sorted list . I would use a heap if I
were
 in
  c++ .. is there a inbuilt implementation of this in clojure? .. Is
there
  some other way to achieve this? some sort of lazy sort would be
perfect.
 I
  know I need the full collection to start with .. but that is fine.

 A seq on a sorted set should be pretty efficient.

 (take 3 (sorted-set 8 2 1 4 6 9 7 3))
 ;= (1 2 3)

 --Chouser

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: heaps in clojure

2011-09-15 Thread Mark Engelberg
If you maintain the invariant that at each point, your sorted set contains
the top 10 you've seen so far, then from that invariant you can conclude
that at the end of the traversal, your sorted set contains the top 10 for
the overall list.

On Thu, Sep 15, 2011 at 12:34 AM, David Powell d...@djpowell.net wrote:

 Does that work?

 There is no guarantee that the top 10 of the overall list matches the top
 10 of earlier prefixes, so the candidates that get discarded might be part
 of the overall top 10, and the elements that pushed them out could just be
 local maxima.

 --
 Dave
 On 15 Sep 2011 08:23, Mark Engelberg mark.engelb...@gmail.com wrote:
  You can do one linear pass over your data, accumulating a sorted set of
 the
  best 10 items you've found so far. You seed the sorted set with the first
  10 items from your list, then continue traversing your list. With each
 new
  item you encounter, you ask if it is any better than the worst of the
  best-10-sorted-set. If it is, then you add it to the sorted-set and boot
  out the worst. Since the sorted set never exceeds 10 items, there is a
  small, constant bound for how long the operations on the sorted set will
  take. Thus this is a O(n) algorithm.
 
  On Wed, Sep 14, 2011 at 10:59 PM, Sunil S Nandihalli 
  sunil.nandiha...@gmail.com wrote:
 
  Hi chouser,
  Thanks for your response. but correct me if I am wrong.. wouldn't
  sorted-set completely sort the complete collection without actually
 taking
  into account that only the first few elements are needed?
  Thanks,
  Sunil.
 
 
  On Tue, Sep 13, 2011 at 7:15 PM, Chouser chou...@gmail.com wrote:
 
  On Tue, Sep 13, 2011 at 7:44 AM, Sunil S Nandihalli
  sunil.nandiha...@gmail.com wrote:
   Hi Everybody,
   I have a very large, but with finite size, collection. I would like
 to
  get
   like first 10 elements in the sorted list . I would use a heap if I
 were
  in
   c++ .. is there a inbuilt implementation of this in clojure? .. Is
 there
   some other way to achieve this? some sort of lazy sort would be
 perfect.
  I
   know I need the full collection to start with .. but that is fine.
 
  A seq on a sorted set should be pretty efficient.
 
  (take 3 (sorted-set 8 2 1 4 6 9 7 3))
  ;= (1 2 3)
 
  --Chouser
 
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
  your first post.
  To unsubscribe from 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

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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: heaps in clojure

2011-09-15 Thread David Powell
But when an element is dropped from the list, you're effectively resetting
its seen-count to zero.  It might be seen again, and it might (if you hadn't
reset the seen-count), have ended up in the top 10.

Or have I misunderstood?

-- 
Dave
On 15 Sep 2011 08:54, Mark Engelberg mark.engelb...@gmail.com wrote:
 If you maintain the invariant that at each point, your sorted set contains
 the top 10 you've seen so far, then from that invariant you can conclude
 that at the end of the traversal, your sorted set contains the top 10 for
 the overall list.

 On Thu, Sep 15, 2011 at 12:34 AM, David Powell d...@djpowell.net wrote:

 Does that work?

 There is no guarantee that the top 10 of the overall list matches the top
 10 of earlier prefixes, so the candidates that get discarded might be
part
 of the overall top 10, and the elements that pushed them out could just
be
 local maxima.

 --
 Dave
 On 15 Sep 2011 08:23, Mark Engelberg mark.engelb...@gmail.com wrote:
  You can do one linear pass over your data, accumulating a sorted set of
 the
  best 10 items you've found so far. You seed the sorted set with the
first
  10 items from your list, then continue traversing your list. With each
 new
  item you encounter, you ask if it is any better than the worst of the
  best-10-sorted-set. If it is, then you add it to the sorted-set and
boot
  out the worst. Since the sorted set never exceeds 10 items, there is a
  small, constant bound for how long the operations on the sorted set
will
  take. Thus this is a O(n) algorithm.
 
  On Wed, Sep 14, 2011 at 10:59 PM, Sunil S Nandihalli 
  sunil.nandiha...@gmail.com wrote:
 
  Hi chouser,
  Thanks for your response. but correct me if I am wrong.. wouldn't
  sorted-set completely sort the complete collection without actually
 taking
  into account that only the first few elements are needed?
  Thanks,
  Sunil.
 
 
  On Tue, Sep 13, 2011 at 7:15 PM, Chouser chou...@gmail.com wrote:
 
  On Tue, Sep 13, 2011 at 7:44 AM, Sunil S Nandihalli
  sunil.nandiha...@gmail.com wrote:
   Hi Everybody,
   I have a very large, but with finite size, collection. I would like
 to
  get
   like first 10 elements in the sorted list . I would use a heap if I
 were
  in
   c++ .. is there a inbuilt implementation of this in clojure? .. Is
 there
   some other way to achieve this? some sort of lazy sort would be
 perfect.
  I
   know I need the full collection to start with .. but that is fine.
 
  A seq on a sorted set should be pretty efficient.
 
  (take 3 (sorted-set 8 2 1 4 6 9 7 3))
  ;= (1 2 3)
 
  --Chouser
 
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient
with
  your first post.
  To unsubscribe from 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

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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

Re: heaps in clojure

2011-09-15 Thread Mark Engelberg
The initial problem statement is to figure out what would be the first 10
items if you sorted the list.

I don't see anything about frequency or how many times you've seen a given
item in the statement of the problem.

When I talk about a best item, I mean it is the first with regard to
whatever comparison method you're using.

On Thu, Sep 15, 2011 at 1:04 AM, David Powell d...@djpowell.net wrote:

 But when an element is dropped from the list, you're effectively resetting
 its seen-count to zero.  It might be seen again, and it might (if you hadn't
 reset the seen-count), have ended up in the top 10.

 Or have I misunderstood?

 --
 Dave
 On 15 Sep 2011 08:54, Mark Engelberg mark.engelb...@gmail.com wrote:
  If you maintain the invariant that at each point, your sorted set
 contains
  the top 10 you've seen so far, then from that invariant you can conclude
  that at the end of the traversal, your sorted set contains the top 10 for
  the overall list.
 
  On Thu, Sep 15, 2011 at 12:34 AM, David Powell d...@djpowell.net
 wrote:
 
  Does that work?
 
  There is no guarantee that the top 10 of the overall list matches the
 top
  10 of earlier prefixes, so the candidates that get discarded might be
 part
  of the overall top 10, and the elements that pushed them out could just
 be
  local maxima.
 
  --
  Dave
  On 15 Sep 2011 08:23, Mark Engelberg mark.engelb...@gmail.com
 wrote:
   You can do one linear pass over your data, accumulating a sorted set
 of
  the
   best 10 items you've found so far. You seed the sorted set with the
 first
   10 items from your list, then continue traversing your list. With each
  new
   item you encounter, you ask if it is any better than the worst of the
   best-10-sorted-set. If it is, then you add it to the sorted-set and
 boot
   out the worst. Since the sorted set never exceeds 10 items, there is a
   small, constant bound for how long the operations on the sorted set
 will
   take. Thus this is a O(n) algorithm.
  
   On Wed, Sep 14, 2011 at 10:59 PM, Sunil S Nandihalli 
   sunil.nandiha...@gmail.com wrote:
  
   Hi chouser,
   Thanks for your response. but correct me if I am wrong.. wouldn't
   sorted-set completely sort the complete collection without actually
  taking
   into account that only the first few elements are needed?
   Thanks,
   Sunil.
  
  
   On Tue, Sep 13, 2011 at 7:15 PM, Chouser chou...@gmail.com wrote:
  
   On Tue, Sep 13, 2011 at 7:44 AM, Sunil S Nandihalli
   sunil.nandiha...@gmail.com wrote:
Hi Everybody,
I have a very large, but with finite size, collection. I would
 like
  to
   get
like first 10 elements in the sorted list . I would use a heap if
 I
  were
   in
c++ .. is there a inbuilt implementation of this in clojure? .. Is
  there
some other way to achieve this? some sort of lazy sort would be
  perfect.
   I
know I need the full collection to start with .. but that is fine.
  
   A seq on a sorted set should be pretty efficient.
  
   (take 3 (sorted-set 8 2 1 4 6 9 7 3))
   ;= (1 2 3)
  
   --Chouser
  
   --
   You received this message because you are subscribed to the Google
   Groups Clojure group.
   To post to this group, send email to clojure@googlegroups.com
   Note that posts from new members are moderated - please be patient
 with
   your first post.
   To unsubscribe from 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
 
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
  your first post.
  To unsubscribe from 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 

Re: heaps in clojure

2011-09-15 Thread David Powell
Ah yeah.  Sorry, I'd superimposed something I was thinking about on to the
original problem.

-- 
Dave
On 15 Sep 2011 09:07, Mark Engelberg mark.engelb...@gmail.com wrote:
 The initial problem statement is to figure out what would be the first 10
 items if you sorted the list.

 I don't see anything about frequency or how many times you've seen a given
 item in the statement of the problem.

 When I talk about a best item, I mean it is the first with regard to
 whatever comparison method you're using.

 On Thu, Sep 15, 2011 at 1:04 AM, David Powell d...@djpowell.net wrote:

 But when an element is dropped from the list, you're effectively
resetting
 its seen-count to zero. It might be seen again, and it might (if you
hadn't
 reset the seen-count), have ended up in the top 10.

 Or have I misunderstood?

 --
 Dave
 On 15 Sep 2011 08:54, Mark Engelberg mark.engelb...@gmail.com wrote:
  If you maintain the invariant that at each point, your sorted set
 contains
  the top 10 you've seen so far, then from that invariant you can
conclude
  that at the end of the traversal, your sorted set contains the top 10
for
  the overall list.
 
  On Thu, Sep 15, 2011 at 12:34 AM, David Powell d...@djpowell.net
 wrote:
 
  Does that work?
 
  There is no guarantee that the top 10 of the overall list matches the
 top
  10 of earlier prefixes, so the candidates that get discarded might be
 part
  of the overall top 10, and the elements that pushed them out could
just
 be
  local maxima.
 
  --
  Dave
  On 15 Sep 2011 08:23, Mark Engelberg mark.engelb...@gmail.com
 wrote:
   You can do one linear pass over your data, accumulating a sorted set
 of
  the
   best 10 items you've found so far. You seed the sorted set with the
 first
   10 items from your list, then continue traversing your list. With
each
  new
   item you encounter, you ask if it is any better than the worst of
the
   best-10-sorted-set. If it is, then you add it to the sorted-set and
 boot
   out the worst. Since the sorted set never exceeds 10 items, there is
a
   small, constant bound for how long the operations on the sorted set
 will
   take. Thus this is a O(n) algorithm.
  
   On Wed, Sep 14, 2011 at 10:59 PM, Sunil S Nandihalli 
   sunil.nandiha...@gmail.com wrote:
  
   Hi chouser,
   Thanks for your response. but correct me if I am wrong.. wouldn't
   sorted-set completely sort the complete collection without actually
  taking
   into account that only the first few elements are needed?
   Thanks,
   Sunil.
  
  
   On Tue, Sep 13, 2011 at 7:15 PM, Chouser chou...@gmail.com wrote:
  
   On Tue, Sep 13, 2011 at 7:44 AM, Sunil S Nandihalli
   sunil.nandiha...@gmail.com wrote:
Hi Everybody,
I have a very large, but with finite size, collection. I would
 like
  to
   get
like first 10 elements in the sorted list . I would use a heap
if
 I
  were
   in
c++ .. is there a inbuilt implementation of this in clojure? ..
Is
  there
some other way to achieve this? some sort of lazy sort would be
  perfect.
   I
know I need the full collection to start with .. but that is
fine.
  
   A seq on a sorted set should be pretty efficient.
  
   (take 3 (sorted-set 8 2 1 4 6 9 7 3))
   ;= (1 2 3)
  
   --Chouser
  
   --
   You received this message because you are subscribed to the Google
   Groups Clojure group.
   To post to this group, send email to clojure@googlegroups.com
   Note that posts from new members are moderated - please be patient
 with
   your first post.
   To unsubscribe from 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
 
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient
with
  your first post.
  To unsubscribe from 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: Mocking out namespaces

2011-09-15 Thread Chris Perkins
On Wednesday, September 14, 2011 11:19:13 AM UTC-4, Brian Hurt wrote:

 Say I have two name spaces, A and B, with A depending on B.  I want to test 
 namespace A, replacing module B with a mock B for testing purposes- 
 preferably without having to load B at all (B sucks in a bunch of stuff, 
 like dependencies on databases and external web sites and etc. that I don't 
 want to deal with in testing).  What is the easy, clojure-approved, 
 mechanism for doing this?  I tried:



my-project
  |-- src
  | |-- A.clj
  | |-- B.clj
  | -- mocks
  | |-- B.clj
  |-- testdriver.clj

# Run with the real B:
java -cp clojure.jar:src clojure.main testdriver.clj

# Run with the mock B:
java -cp clojure.jar:mocks:src clojure.main testdriver.clj

I don't know if my ascii-art directory tree makes any sense at all, but the 
point is that if you put mocks earlier in the classpath than src, then 
the mock B should get loaded instead of the real one.

- Chris

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

Re: Overtone 0.3 released

2011-09-15 Thread Herwig Hochleitner
Thanks, Sam!

I'm really looking forward to play a bit more in depth with overtone
and try to use it in a jam session.

kind regards
-- 
__
Herwig Hochleitner

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Binding *out*

2011-09-15 Thread Nick Mudge
Thanks Stuart and Dave.

On Sep 14, 10:30 am, Stuart Sierra the.stuart.sie...@gmail.com
wrote:
 Hi Nick,

 *out* and *err* are already dynamic, which is what allows `binding` to work.
 You can the  root binding of any Var (even non-dynamic Vars) with `def` or
 `alter-var-root`.

 -Stuart Sierra

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: How to convert general recursion to loop .. recur syntax

2011-09-15 Thread Herwig Hochleitner
Hi,

as you might know, the original version actually does run in fixed
stack space, thanks to lazy sequences.

(defn skl
  [tree]
  (map skl (filter seq? tree)))

loop .. recur is the moral equivalent of a while(true) loop in
imperative style. i.e. a slightly disguised (and somewhat more
structured) goto
Only use that as a lowlevel implementation detail.

You can express mostly anything with the sequence library of clojure

Consider

(defn find-in-tree
  ([tree pred?]
(concat
  (filter pred? tree)
  (mapcat find-in-tree (filter sequential? tree) (repeat pred?)

which of course is much simpler written as

(defn find-in-tree
  ([tree pred?] (filter pred? (flatten tree

all of which are lazy, hence consume constant stack space

kind regards
-- 
__
Herwig Hochleitner

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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 vs Scala - anecdote

2011-09-15 Thread cig
Impressive, wonder if they were running this on a single node or more
widespread?
In a wide spread environment I think Erlang would be the true winner,
though it does not natively have macros :-(
There is an implementation of Lisp for Erlang called LFE (lisp
flavored Erlang) which I looked at, which does have macros and a real
engine underneath.
But clojure is an awesome combination

On Sep 7, 7:32 am, Sean Corfield seancorfi...@gmail.com wrote:
 I just wanted to share this experience from World Singles...

 Back in November 2009, we started developing with Scala. We needed a
 long-running process that published large volumes of changes from our
 member database as XML packets published to a custom search engine.
 The mapping from half a dozen tables in the database to a flat XML
 schema was pretty complex and the company had tried a number of
 solutions with mixed success in the past. I introduced Scala based on
 the promises of performance, concurrency and type safety - and
 conciseness (especially with XML being a native data type in Scala).

 We've been running the Scala publishing daemons in production for most
 of two years. Generally they work pretty well but, under stress, they
 tend to hit Out of Memory exceptions and, after a lot of poking
 around, we became fairly convinced it was due (at least in part) to
 the default actor implementation in Scala. Scala is going to fold in
 Akka soon and we had been considering migrating to Akka anyone...

 But having introduced Clojure this year (after experimenting with it
 since about May last year), we figured we'd have a short spike to
 create a Clojure version of the Scala code to see how it worked out.

 It took about 15 hours to recreate the publishing daemon in Clojure
 and get it to pass all our tests. Today we ran a soak test
 publishing nearly 300,000 profiles in one run. The Scala code would
 fail with OoM exceptions if we hit it with 50,000 profiles in one run
 (sometimes less). The Clojure code sailed thru and is still happily
 running - so we'll be replacing the Scala code during our next
 production build.

 The other aspect that's interesting is that the Scala code totaled
 about 1,000 lines (about 31k characters of code). The Clojure
 replacement is just under 260 lines (around 11.5k characters of code).
 Neither code base has much in the way of comments (*ahem* - I'm not
 proud of that, just pointing out that there's no noise offsetting
 the code comparison). That doesn't include unit tests either, it's
 just the raw production code. The form of the Clojure code mostly
 follows the form of the Scala code, most of the same functions - it
 was very functional Scala - with some refactoring to helper functions
 to make it more modular and more maintainable.

 The net result is (obviously) that we'll be taking the Clojure
 publishing daemon to production and we'll be dropping Scala
 completely.

 Kudos to Rich Hickey and the Clojure/core team for creating a great
 general purpose language that can solve big problems - thank you!
 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View --http://corfield.org/
 World Singles, LLC. --http://worldsingles.com/
 Railo Technologies, Inc. --http://www.getrailo.com/

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

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


Clojure videocast mentioning SuperCSV?

2011-09-15 Thread James P
I've been watching a bunch of Clojure videocasts lately, and there was one 
which mentioned using the Java library SuperCSV. Unfortunately I can't 
recall which videocast it was, can someone remind me please? Many thanks.

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

Watching namespaces

2011-09-15 Thread Stathis Sideris
Hello,

Is it somehow possible to monitor all namespaces for new defs or re-
defs (and defns etc). Generally, it it possible to implement some sort
of notification whenever something is added or updated to a namespace?
I don't mind even the solution is hacky or not very fast.

The reason I'm asking is because such functionality would be very
useful for creating development tools that would react to the
developer eval-ing a function or re-compiling a file etc.

Thanks,

Stathis

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Watching namespaces

2011-09-15 Thread Herwig Hochleitner
I was about to say that you best bet would be redefining the relevant
functions/macros, when I realized that you cannot do that with def,
because it's a special form.
So short of patching clojure, I don't think one can monitor var
interning. (addition to a namespace)

What you can do, is monitoring redefinition:

 (def x old value)
 (add-watch #'x :redef println)
 (def x new value)
:redef #'user/x old value new value

kind regards

2011/9/15 Stathis Sideris side...@gmail.com:
 Hello,

 Is it somehow possible to monitor all namespaces for new defs or re-
 defs (and defns etc). Generally, it it possible to implement some sort
 of notification whenever something is added or updated to a namespace?
 I don't mind even the solution is hacky or not very fast.

 The reason I'm asking is because such functionality would be very
 useful for creating development tools that would react to the
 developer eval-ing a function or re-compiling a file etc.

 Thanks,

 Stathis

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



-- 
__
Herwig Hochleitner

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


ClojureScript auto-recompile option

2011-09-15 Thread Stuart Campbell
Hello,

I've written a small hack for the ClojureScript compiler that is useful for
working with static HTML projects. When invoked with the :watch option, the
cljsc program watches a source directory and recompiles sources whenever a
change is detected.

https://github.com/harto/clojurescript/commit/f5bb720523f7121ab5fc8add014fd64846dc8e19

Usage: cljsc src '{:watch true}' foo.js

The change depends on the jpathwatch library, which should be downloaded (
http://sourceforge.net/projects/jpathwatch/files/jpathwatch-0-94.zip/download)
into the clojurescript/lib directory.

Regards,
Stuart

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

Re: How to convert general recursion to loop .. recur syntax

2011-09-15 Thread Chouser
On Thu, Sep 15, 2011 at 8:56 AM, Herwig Hochleitner
hhochleit...@gmail.com wrote:
 Hi,

 as you might know, the original version actually does run in fixed
 stack space, thanks to lazy sequences.

You are right!

Without testing it I had thought that the way recursion was used would
cause skl to overflow the stack if the input tree was very deep on its
first elements.

 (defn skl
  [tree]
  (map skl (filter seq? tree)))

But in testing this skl fn I couldn't get it to overflow.  This is
because the tree is not flattened, and so calling 'first' on the top
level of the resulting tree only forces the top-level map, whose first
item remains a lazy seq, neatly avoiding an overflow error.

Good catch, Herwig!

 Consider

 (defn find-in-tree
  ([tree pred?]
    (concat
      (filter pred? tree)
      (mapcat find-in-tree (filter sequential? tree) (repeat pred?)

 which of course is much simpler written as

 (defn find-in-tree
  ([tree pred?] (filter pred? (flatten tree

 all of which are lazy, hence consume constant stack space

Alas, this suffers from exactly the problem that I incorrectly
believed skl suffered from.  It works fine for some trees:

(find-in-tree (reduce list (range 1000)) #(when-not (seq? %) (even? %)))
;= (0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44
46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90
92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126
128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160
162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194
196 198 200 202 204 ...)

But the lazy seqs form a chain so that in order to return the first
element of the result, they seqs must each force the next in the
chain, consuming call stack frames as they go.  Provide a tree deep
enough and it overflows the stack:

(find-in-tree (reduce list (range 1)) #(when-not (seq? %) (even? %)))
; StackOverflowError   clojure.lang.RT.boundedLength (RT.java:1607)


Nevertheless let us now marvel for a moment at the beauty of lazy
seqs, that they can sometimes avoid both premature computation and
stack overflows, even in cases where no amount of
tail-call-optimization would help! And all this while delivering code
so similar to the problem statement and therefore concise, compared to
the long and tortured loop/recur version I posted yesterday.

--Chouser

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Watching namespaces

2011-09-15 Thread Laurent PETIT
2011/9/15 Stathis Sideris side...@gmail.com

 Hello,

 Is it somehow possible to monitor all namespaces for new defs or re-
 defs (and defns etc). Generally, it it possible to implement some sort
 of notification whenever something is added or updated to a namespace?


Not that I'm aware of.


 I don't mind even the solution is hacky or not very fast.

 The reason I'm asking is because such functionality would be very
 useful for creating development tools that would react to the
 developer eval-ing a function or re-compiling a file etc.

 Thanks,

 Stathis

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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: How to convert general recursion to loop .. recur syntax

2011-09-15 Thread Ken Wesson
On Thu, Sep 15, 2011 at 8:56 AM, Herwig Hochleitner
hhochleit...@gmail.com wrote:
 Consider

 (defn find-in-tree
  ([tree pred?]
    (concat
      (filter pred? tree)
      (mapcat find-in-tree (filter sequential? tree) (repeat pred?)

 which of course is much simpler written as

 (defn find-in-tree
  ([tree pred?] (filter pred? (flatten tree

Not quite -- these differ in the case where pred? sometimes fires for
a subtree and not just for leaves. The latter will miss all the
subtrees for which pred? returns logical true.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: autoboxing in 1.3 RC-0

2011-09-15 Thread David Nolen
On Thu, Sep 15, 2011 at 3:18 AM, Sergey Didenko sergey.dide...@gmail.comwrote:

 Hi,

 Is it a bug or I'm doing something wrong? I can't get rid of
 auto-boxing in the second example, neither by type hinting nor by type
 coercing of changed* locals.

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

 This compiles fine:

 (loop [x 1 changed 0]
  (if (= x 10)
changed
(recur (inc x)
   changed)))

 And this gives the warning recur arg for primitive local: changed is
 not matching primitive, had: Object, needed: long
 Auto-boxing loop arg: change

 (loop [x 1 changed 0]
  (if (= x 10)
changed
(recur (inc x)
   (loop [y 1 changed-y changed]
 changed-y

 P.S. I omitted recur for the inner loop for clarity.


Loop itself will return boxed values I think.

David

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

Re: Clojure vs Scala - anecdote

2011-09-15 Thread Sean Corfield
On Wed, Sep 14, 2011 at 11:15 PM, cig clifford.goldb...@gmail.com wrote:
 Impressive, wonder if they were running this on a single node or more
 widespread?

We run an instance of the process on multiple nodes, configured
slightly differently. We needed some parallelization to improve
throughput but didn't need a massive net of processes. And we needed
JVM interop so Erlang is out (and Erjang isn't yet mature enough - at
least, not last time I looked).

 But clojure is an awesome combination

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

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

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


Re: ClojureScript gets defrecord

2011-09-15 Thread Devin Walters
Great news! Looking forward to trying it out this afternoon.

Cheers,
Devin

On Sep 14, 2011, at 2:48 PM, Tom Hickey wrote:

 Hi all,
 
 With sign-off from Rich, I have pushed my defrecord work onto master.
 
 Please try it out and let me know if you experience any issues.
 
 Cheers,
 Tom Hickey
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from 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: Rounding the edges of an Emacs beginner

2011-09-15 Thread gaz jones
M-{ and M-} in emacs go forward/backwards a paragraph. when in code,
this often translates well to moving around between
fragments/functions etc. you also have C-v and M-v for
forward/backward a page and then C-l for centering on the current
line. i use all of those a lot...

On Thu, Sep 15, 2011 at 2:15 AM, Stefan Kamphausen
ska2...@googlemail.com wrote:
 Hi,

 we're getting totally OT here and should probably better head for
 gnu.emacs.help.  Anyway, just one more bark from me and then I'll be quiet
 (but will respond to mail ;-)

 On Thursday, September 15, 2011 2:08:28 AM UTC+2, frye wrote:

 In Vim , you press Ctrl-d and Ctrl-u to go down and up a block
 respectively. Depending on the size of your window, it moves the cursor
 about 1/3rd of the way down (or up) the screen. This is very handy to have
 when just browsing a buffer. You can be more precise by pressing 37k, to
 move the cursor up 37 lines, etc.

 For whatever reason, I haven't been able to find something similar in
 Emacs.

 OK, I tried what it does in vim.  Some things come to my mind.

 1. PgUp/PgDn obviously
 2. Try hitting C-l (that's an 'l' like in 'like') several times in a row.
 It won't move your cursor but the line it's on.
 3. I've been using some personal binding on my home and end keys for ages
 which moves me  to the beginning/end of a line, beginning/end of the
 currently displayed window and beginning/end of the whole buffer on
 successive hits.  See chb-home and chb-end on
 http://www.skamphausen.de/cgi-bin/ska/dot-emacs.d-slash-init.el.  Combine
 that with C-l.
 4. You might want to try out swiss-move.el (shameless self-plug).  Maybe
 it's confusing, maybe helpful.

 Cheers,
 Stefan

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your
 first post.
 To unsubscribe from 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: autoboxing in 1.3 RC-0

2011-09-15 Thread Sean Corfield
On Thu, Sep 15, 2011 at 7:50 AM, David Nolen dnolen.li...@gmail.com wrote:
 Loop itself will return boxed values I think.

Looks that way. The following code has no reflection warning:

(loop [x 1 changed 0]
 (if (= x 10)
   changed
   (recur (inc x)
  (long (loop [y 1 changed-y changed]
  changed-y)
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

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

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


Re: Clojure vs Scala - anecdote

2011-09-15 Thread Edward Garson
Native Erlang does have a macro facility, but it is not as powerful as
Lisp/Clojure's.

On Sep 15, 2:15 am, cig clifford.goldb...@gmail.com wrote:
[snip]
 In a wide spread environment I think Erlang would be the true winner,
 though it does not natively have macros :-(
[snip]

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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 vs Scala - anecdote

2011-09-15 Thread Raoul Duke
On Thu, Sep 15, 2011 at 9:24 AM, Edward Garson egar...@gmail.com wrote:
 Native Erlang does have a macro facility, but it is not as powerful as
 Lisp/Clojure's.

lfe, baby, though of course that is not native erlang.

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


java interop question: how to access Class object statically

2011-09-15 Thread Andrew Xue
Hi all --

Trying to basically do something like Integer.class -- but ...

user= (Integer/class)
user= java.lang.NoSuchFieldException: class (NO_SOURCE_FILE:2)

user= (Integer/getClass)
java.lang.NoSuchFieldException: getClass (NO_SOURCE_FILE:4)


Some (not so pretty) workarounds are

(.getClass (Integer. 0))
(class 0)

but there must be a better more idiomatic way to do this? Thanks

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


Re: java interop question: how to access Class object statically

2011-09-15 Thread Dave Ray
How about just Integer? :)

Clojure Integer
java.lang.Integer
Clojure (class Integ­er)
java.lang.Class

Dave

On Thu, Sep 15, 2011 at 1:31 PM, Andrew Xue and...@lumoslabs.com wrote:
 Hi all --

 Trying to basically do something like Integer.class -- but ...

 user= (Integer/class)
 user= java.lang.NoSuchFieldException: class (NO_SOURCE_FILE:2)

 user= (Integer/getClass)
 java.lang.NoSuchFieldException: getClass (NO_SOURCE_FILE:4)


 Some (not so pretty) workarounds are

 (.getClass (Integer. 0))
 (class 0)

 but there must be a better more idiomatic way to do this? Thanks

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


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: ClojureScript gets defrecord

2011-09-15 Thread David Nolen
Any particular reason that records print differently than in Clojure? I also
see that records don't print w/ their namespace attached.

A related bug I encountered was that when I try to put the record literal
back into the REPL, Java complains about not being able to find the class.

David

On Wed, Sep 14, 2011 at 3:48 PM, Tom Hickey thic...@gmail.com wrote:

 Hi all,

 With sign-off from Rich, I have pushed my defrecord work onto master.

 Please try it out and let me know if you experience any issues.

 Cheers,
 Tom Hickey

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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: ClojureScript gets defrecord

2011-09-15 Thread Tom Hickey
Printing is not meant to be different. Maybe I was using against an
older version of Clojure when I was comparing output. Should be fixed
on master.

Thanks for the report.

Tom

On Sep 15, 4:00 pm, David Nolen dnolen.li...@gmail.com wrote:
 Any particular reason that records print differently than in Clojure? I also
 see that records don't print w/ their namespace attached.

 A related bug I encountered was that when I try to put the record literal
 back into the REPL, Java complains about not being able to find the class.

 David







 On Wed, Sep 14, 2011 at 3:48 PM, Tom Hickey thic...@gmail.com wrote:
  Hi all,

  With sign-off from Rich, I have pushed my defrecord work onto master.

  Please try it out and let me know if you experience any issues.

  Cheers,
  Tom Hickey

  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
  your first post.
  To unsubscribe from 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: Watching namespaces

2011-09-15 Thread Chas Emerick
Yes, this has been suggested in the past, and would enable all sorts of useful 
tooling features.

The off-the-top-of-my-head solution (a priori of a proper statement of the 
problem :-P would be for all namespaces (c.l.Namespace/namespaces) and each 
namespace's aliases and mappings to be held in atoms — which could then have 
watches set on them.  Each aliases and mappings are already held in 
AtomicReferences, so things are halfway there in a sense.

Along the same lines, there's been talk in the past of attempting to make 
loading code transactional.  At a minimum, this would imply using refs instead 
of atoms for the structures mentioned above, with each ns/require/use/load 
usage implying a dosync over the affected references.

There may well be bootstrapping issues with such changes.

- Chas

On Sep 15, 2011, at 9:03 AM, Stathis Sideris wrote:

 Hello,
 
 Is it somehow possible to monitor all namespaces for new defs or re-
 defs (and defns etc). Generally, it it possible to implement some sort
 of notification whenever something is added or updated to a namespace?
 I don't mind even the solution is hacky or not very fast.
 
 The reason I'm asking is because such functionality would be very
 useful for creating development tools that would react to the
 developer eval-ing a function or re-compiling a file etc.
 
 Thanks,
 
 Stathis
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from 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: autoboxing in 1.3 RC-0

2011-09-15 Thread Ken Wesson
On Thu, Sep 15, 2011 at 10:50 AM, David Nolen dnolen.li...@gmail.com wrote:
 On Thu, Sep 15, 2011 at 3:18 AM, Sergey Didenko sergey.dide...@gmail.com
 wrote:
 Auto-boxing loop arg: change

 (loop [x 1 changed 0]
  (if (= x 10)
    changed
    (recur (inc x)
           (loop [y 1 changed-y changed]
             changed-y

 Loop itself will return boxed values I think.
 David

It shouldn't, if all the return paths out of the loop return an
unboxed primitive of the same type and an unboxed primitive of that
type is an acceptable input to the enclosing expression, which is the
case here.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: How to convert general recursion to loop .. recur syntax

2011-09-15 Thread octopusgrabbus
Thanks for clarifying the stack space issue. I got confused with the 
original implementation, and was unsure it would run with a large sequence.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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 vs Scala - anecdote

2011-09-15 Thread Tal Liron
On Tuesday, September 13, 2011 1:44:09 PM UTC-5, Sean Corfield wrote:

 It was intended to be purely anecdotal but that doesn't seem to satisfy 
 anyone! :)

Homer: You know, when I was a boy, I really wanted a catcher's mitt, but my 
dad wouldn't get it for me. So I held my breath until I passed out and 
banged my head on the coffee table. The doctor thought I might have brain 
damage.
Bart: Dad, what's the point of this story?
Homer: I like stories.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: autoboxing in 1.3 RC-0

2011-09-15 Thread pmbauer
I ran into this exact issue on an alioth benchmark.
Adding the explicit (long ...) conversion gets rid of the reflection 
warning, but didn't have a significant effect on performance.
The inner loop is still boxing the return value.

On Thursday, September 15, 2011 8:36:53 AM UTC-7, Sean Corfield wrote:

 On Thu, Sep 15, 2011 at 7:50 AM, David Nolen dnolen...@gmail.com wrote:
  Loop itself will return boxed values I think.

 Looks that way. The following code has no reflection warning:

 (loop [x 1 changed 0]
  (if (= x 10)
changed
(recur (inc x)
   (long (loop [y 1 changed-y changed]
   changed-y)
 -- 
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/
 World Singles, LLC. -- http://worldsingles.com/
 Railo Technologies, Inc. -- http://www.getrailo.com/

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



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

Re: autoboxing in 1.3 RC-0

2011-09-15 Thread pmbauer
see 
https://github.com/clojure/test.benchmark/blob/master/src/main/clojure/alioth/mandelbrot.clj#L49

There's two ways to get rid of the reflection warning:
1) another function, appropriately type hinted
2) explicit conversion to long

According to my measurements for this particular case, option 2 is 
fractionally faster by ~3% over option 1.
Expectation would be the explicit conversion to long shouldn't be needed.

On Thursday, September 15, 2011 8:16:10 PM UTC-7, pmbauer wrote:

 I ran into this exact issue on an alioth benchmark.
 Adding the explicit (long ...) conversion gets rid of the reflection 
 warning, but didn't have a significant effect on performance.
 The inner loop is still boxing the return value.

 On Thursday, September 15, 2011 8:36:53 AM UTC-7, Sean Corfield wrote:

 On Thu, Sep 15, 2011 at 7:50 AM, David Nolen dnol...@gmail.com wrote:
  Loop itself will return boxed values I think.

 Looks that way. The following code has no reflection warning:

 (loop [x 1 changed 0]
  (if (= x 10)
changed
(recur (inc x)
   (long (loop [y 1 changed-y changed]
   changed-y)
 -- 
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/
 World Singles, LLC. -- http://worldsingles.com/
 Railo Technologies, Inc. -- http://www.getrailo.com/

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



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

Re: ClojureScript auto-recompile option

2011-09-15 Thread Chris Granger
FWIW there's also cljs-watch:

http://github.com/ibdknox/cljs-watch

On Sep 15, 6:35 am, Stuart Campbell stu...@harto.org wrote:
 Hello,

 I've written a small hack for the ClojureScript compiler that is useful for
 working with static HTML projects. When invoked with the :watch option, the
 cljsc program watches a source directory and recompiles sources whenever a
 change is detected.

 https://github.com/harto/clojurescript/commit/f5bb720523f7121ab5fc8ad...

 Usage: cljsc src '{:watch true}' foo.js

 The change depends on the jpathwatch library, which should be downloaded 
 (http://sourceforge.net/projects/jpathwatch/files/jpathwatch-0-94.zip/...)
 into the clojurescript/lib directory.

 Regards,
 Stuart

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