Re: Stack Overflow problem with Maps

2009-04-27 Thread Christophe Grand
Hi Patrick, Sorry for requesting code you already posted. I'm quite unsure about what functions (in particular get-key-instance) should do. Btw there's two easy ways to test if a collection is empty in clojure (rather than (= 0 (count coll))): (empty? coll) ;; true when empty or (seq coll) ;;

Re: Stack Overflow problem with Maps

2009-04-27 Thread Christophe Grand
Hi Patrick, Please provide some code. fitzpatrick...@googlemail.com a écrit : > I iterate through the list and for each row look up each of the > heading names in the Heading Info List to get an index of where a > particular element should be in the Actual Info List and then i go and > get this

Re: Stack Overflow problem with Maps

2009-04-27 Thread pjfitz
Hi, Here is the code. Each row of data is a string with @ between the three types of data i mentioned. -Row Number -Heading info List -Actual Info List The Heading Info List is created by splitting on , as is the Actual info list. tks, PJ (import '(java.io InputStreamReader OutputStreamWriter))

Re: Stack Overflow problem with Maps

2009-04-27 Thread Dimiter "malkia" Stanev
Unless you provide some kind of isolated source code that reproduces the problem, I don't think it is going to be easy to help you out. But try adding "(doall ..)" to some your "map" calls and others. Even better, look at this excellent explanation why this might be happening by Cristophe Grand:

Re: Stack Overflow problem with Maps

2009-04-27 Thread David Nolen
Can you post your code, always helpful :) On Mon, Apr 27, 2009 at 4:07 PM, fitzpatrick...@googlemail.com < fitzpatrick...@googlemail.com> wrote: > > Hi, > I am working with a very long list and populating it to a map. What i > have is three pieces of data from the list; > -Row Number > -Heading i

Stack Overflow problem with Maps

2009-04-27 Thread fitzpatrick...@googlemail.com
Hi, I am working with a very long list and populating it to a map. What i have is three pieces of data from the list; -Row Number -Heading info List -Actual Info List note: both the Heading Info List and Actual Info List have the same number of elements as each heading name will have a correspondi

Re: Concatenating many lists (stack overflow problem)

2009-03-02 Thread Jason Wolfe
On Mar 2, 2009, at 2:52 AM, Zededarian wrote: > > Ah, I see. Out of curiosity, is there some design reason why clojure > doesn't reduce my original function to the apply version? I mean, > take the function: > (loop [x '(1 2 3) fin '()] > (if x >(recur (cdr x) (concat fin (list x))) >

Re: Concatenating many lists (stack overflow problem)

2009-03-02 Thread Zededarian
Ah, I see. Out of curiosity, is there some design reason why clojure doesn't reduce my original function to the apply version? I mean, take the function: (loop [x '(1 2 3) fin '()] (if x (recur (cdr x) (concat fin (list x))) fin)) Will, at least if I'm interpreting your responses corre

Re: Concatenating many lists (stack overflow problem)

2009-03-01 Thread Jason Wolfe
No, it will be O(n), where the "cool magic" is in the use of lazy sequences. Here's a very simple way to write an O(n) lazy concat: user> (defn my-concat [& seqs] (when-first [s seqs] (if (seq s) (lazy-seq (cons (first s) (apply my-concat (rest s) (rest seqs))

Re: Concatenating many lists (stack overflow problem)

2009-03-01 Thread Zededarian
Thanks! One follow up question, though: will the first solution take O(n^2) time, or is clojure clever enough to keep track of where the end of a sequence is on its own (or, alternately, to start by concatenating the last two elements and working backward)? Or does it do some other cool magic to

Re: Concatenating many lists (stack overflow problem)

2009-03-01 Thread Jason Wolfe
Hi, The problem is that you end up with the front of your worklist being wrapped in nested calls to lazy-seq, one per each call to concat. Then, realizing the first element causes a stack overflow. This wouldn't happen if you reversed the arguments to concat, but then you wouldn't get what you

Concatenating many lists (stack overflow problem)

2009-03-01 Thread Zededarian
My ultimate goal is to get a list of all the words in a file in order. I have a function that will get a list of all the words on one line of this file in order, and I want to efficiently concatenate these lists to end up with one large list. I'm working with about 12000 lines right now, but in

Re: Stack overflow problem

2009-02-09 Thread Jeffrey Straszheim
Did this work for you? Do you understand what the problem was? On Sun, Feb 8, 2009 at 8:06 PM, Jeffrey Straszheim < straszheimjeff...@gmail.com> wrote: > In fact, try this: > > (defn add-children [searchtype statelist] > (let [c (children (first statelist)) >s (rest statelist)]

Re: Stack overflow problem

2009-02-08 Thread Jeffrey Straszheim
In fact, try this: (defn add-children [searchtype statelist] (let [c (children (first statelist)) s (rest statelist)] (cond (= searchtype :breadth-first) (doall (concat s c)) (= searchtype :depth-first) (doall (concat c s) The doall forces the lists the

Re: Stack overflow problem

2009-02-08 Thread Jeffrey Straszheim
Perhaps you are forcing a very long lazy list? Try (.printStackTrace *e) On Sun, Feb 8, 2009 at 9:41 AM, jodocus wrote: > > When I learn a new language, one of the programs I like to write as an > excercise is the n-queens problem (http://en.wikipedia.org/wiki/ > 8_queens

Stack overflow problem

2009-02-08 Thread jodocus
When I learn a new language, one of the programs I like to write as an excercise is the n-queens problem (http://en.wikipedia.org/wiki/ 8_queens). I wrote the program below which runs correctly. Using depth- first search, I have used it to find the solutions for board sizes up to 11 (after which i