Re: Stack Overflow developer survey

2020-02-07 Thread Alan Moore
Done.

Alan

On Wednesday, February 5, 2020 at 8:02:13 PM UTC-8, Sean Corfield wrote:
>
> I've been encouraging folks to take the survey and write in Clojure. 
> Representation matters!
>
> On Wed, Feb 5, 2020 at 5:45 PM Matching Socks  > wrote:
>
>> Today, I noticed an invitation to complete the Stack Overflow developer 
>> survey.
>>
>> (Clojure was not on the menu.)
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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
>> clo...@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 unsubscribe from this group and stop receiving emails from it, send an 
>> email to clo...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/clojure/f46ba1b5-72db-4a72-be41-6f0d83cd7839%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/clojure/f46ba1b5-72db-4a72-be41-6f0d83cd7839%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>
>
> -- 
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
> World Singles Networks, LLC. -- https://worldsinglesnetworks.com/
>
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/7b3ec32e-0eab-454b-ba7f-c851196ffe29%40googlegroups.com.


Re: Stack Overflow developer survey

2020-02-05 Thread Sean Corfield
I've been encouraging folks to take the survey and write in Clojure.
Representation matters!

On Wed, Feb 5, 2020 at 5:45 PM Matching Socks  wrote:

> Today, I noticed an invitation to complete the Stack Overflow developer
> survey.
>
> (Clojure was not on the menu.)
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/clojure/f46ba1b5-72db-4a72-be41-6f0d83cd7839%40googlegroups.com
> <https://groups.google.com/d/msgid/clojure/f46ba1b5-72db-4a72-be41-6f0d83cd7839%40googlegroups.com?utm_medium=email_source=footer>
> .
>


-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles Networks, LLC. -- https://worldsinglesnetworks.com/

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

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/CAD4thx9jwwM9vmB09%3DF_%3DasXqTnjGymX6LxS0inKDQcP54NT0A%40mail.gmail.com.


Stack Overflow developer survey

2020-02-05 Thread Matching Socks
Today, I noticed an invitation to complete the Stack Overflow developer 
survey.

(Clojure was not on the menu.)

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/f46ba1b5-72db-4a72-be41-6f0d83cd7839%40googlegroups.com.


Re: error in process filter: Stack overflow in regexp matcher

2018-12-25 Thread nenad mitrovic
Thank you Andy, after I changed ~/.lein/profiles.clj file to a different 
nam, it works now. I can see all of 1400 files.

Am Dienstag, 25. Dezember 2018 04:24:00 UTC+1 schrieb Justin Smith:
>
> This isn't a clojure issue.
>
> A reference to "process filter" indicates this is an emacs problem. Its 
> regex syntax matcher tends to blow up on long lines.
>
> On Mon, Dec 24, 2018, 14:57 Andy Fingerhut  > wrote:
>
>> I would recommend trying to temporarily rename ~/.lein/profiles.clj to a 
>> different name, so that there is no such file with that name any more, and 
>> try your file-seq expression again to see if it behaves any differently.
>>
>> Andy
>>
>> On Mon, Dec 24, 2018 at 1:38 PM nenad mitrovic > > wrote:
>>
>>> Sorry, here is profiles.clj
>>>
>>> {:user
>>>   {
>>>   :java-cmd "C:\\Program Files\\Java\\jdk1.8.0_111\\bin\\java.exe"
>>>   :plugins [
>>>   
>>> [cider/cider-nrepl "0.8.1"]
>>> [luminus/lein-template "2.9.9.2"]
>>>
>>> ]
>>>}
>>>  }
>>>
>>> On Monday, December 24, 2018 at 10:12:04 PM UTC+1, nenad mitrovic wrote:
>>>>
>>>> I am trying to execute this piece of code: (rest (file-seq (file (str 
>>>> "corpus/" "ham"))).
>>>> When I execute I get this error: "error in process filter: Stack 
>>>> overflow in regexp matcher".
>>>> I have 1400 files in corpus/ham folder. But when I execute only three 
>>>> file it works.
>>>>
>>> -- 
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send 
>>> an email to clojure+u...@googlegroups.com .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: error in process filter: Stack overflow in regexp matcher

2018-12-24 Thread Justin Smith
This isn't a clojure issue.

A reference to "process filter" indicates this is an emacs problem. Its
regex syntax matcher tends to blow up on long lines.

On Mon, Dec 24, 2018, 14:57 Andy Fingerhut  wrote:

> I would recommend trying to temporarily rename ~/.lein/profiles.clj to a
> different name, so that there is no such file with that name any more, and
> try your file-seq expression again to see if it behaves any differently.
>
> Andy
>
> On Mon, Dec 24, 2018 at 1:38 PM nenad mitrovic 
> wrote:
>
>> Sorry, here is profiles.clj
>>
>> {:user
>>   {
>>   :java-cmd "C:\\Program Files\\Java\\jdk1.8.0_111\\bin\\java.exe"
>>   :plugins [
>>
>> [cider/cider-nrepl "0.8.1"]
>> [luminus/lein-template "2.9.9.2"]
>>
>> ]
>>}
>>  }
>>
>> On Monday, December 24, 2018 at 10:12:04 PM UTC+1, nenad mitrovic wrote:
>>>
>>> I am trying to execute this piece of code: (rest (file-seq (file (str
>>> "corpus/" "ham"))).
>>> When I execute I get this error: "error in process filter: Stack
>>> overflow in regexp matcher".
>>> I have 1400 files in corpus/ham folder. But when I execute only three
>>> file it works.
>>>
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: error in process filter: Stack overflow in regexp matcher

2018-12-24 Thread Andy Fingerhut
I would recommend trying to temporarily rename ~/.lein/profiles.clj to a
different name, so that there is no such file with that name any more, and
try your file-seq expression again to see if it behaves any differently.

Andy

On Mon, Dec 24, 2018 at 1:38 PM nenad mitrovic 
wrote:

> Sorry, here is profiles.clj
>
> {:user
>   {
>   :java-cmd "C:\\Program Files\\Java\\jdk1.8.0_111\\bin\\java.exe"
>   :plugins [
>
> [cider/cider-nrepl "0.8.1"]
> [luminus/lein-template "2.9.9.2"]
>
> ]
>}
>  }
>
> On Monday, December 24, 2018 at 10:12:04 PM UTC+1, nenad mitrovic wrote:
>>
>> I am trying to execute this piece of code: (rest (file-seq (file (str
>> "corpus/" "ham"))).
>> When I execute I get this error: "error in process filter: Stack overflow
>> in regexp matcher".
>> I have 1400 files in corpus/ham folder. But when I execute only three
>> file it works.
>>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: error in process filter: Stack overflow in regexp matcher

2018-12-24 Thread nenad mitrovic
windows 8.1, java 1.8.0_191, clojure 1.8.0


profiles.clj contains the following content:

{:profiles/dev  {:env {:database-url 
"jdbc:postgresql://localhost/spam_filter_dev?user=db_user_name_here=db_user_password_here"}}
 :profiles/test {:env {:database-url 
"jdbc:postgresql://localhost/spam_filter_test?user=db_user_name_here=db_user_password_here"}}}

and here is project.clj

(defproject spam-filter "0.1.0-SNAPSHOT"



  :description "FIXME: write description"

  :url "http://example.com/FIXME;



  :dependencies [[org.clojure/clojure "1.8.0"]

 [selmer "1.0.0"]

 [markdown-clj "0.9.85"]

 [luminus/config "0.5"]

 [ring-middleware-format "0.7.0"]

 [metosin/ring-http-response "0.6.5"]

 [bouncer "1.0.0"]

 [org.webjars/bootstrap "4.0.0-alpha.2"]

 [org.webjars/font-awesome "4.5.0"]

 [org.webjars.bower/tether "1.1.1"]

 [org.webjars/jquery "2.2.0"]

 [org.clojure/tools.logging "0.3.1"]

 [com.taoensso/tower "3.0.2"]

 [compojure "1.4.0"]

 [ring-webjars "0.1.1"]

 [ring/ring-defaults "0.1.5"]

 [ring "1.4.0" :exclusions [ring/ring-jetty-adapter]]

 [mount "0.1.8"]

 [luminus-nrepl "0.1.2"]

 [migratus "0.8.9"]
 [conman "0.3.0"]
 [org.postgresql/postgresql "9.4-1206-jdbc4"]
 [org.webjars/webjars-locator-jboss-vfs "0.1.0"]
 [luminus-immutant "0.1.0"]
 [luminus-log4j "0.1.2"]]



  :min-lein-version "2.0.0"

  :uberjar-name "spam-filter.jar"

  :jvm-opts ["-server"]

  :source-paths ["src/clj"]

  :resource-paths ["resources"]



  :main spam-filter.core

  :migratus {:store :database}



  :plugins [[lein-environ "1.0.1"]

[migratus-lein "0.2.1"]]

  :profiles

  {:uberjar {:omit-source true

 :env {:production true}

 :aot :all

 :source-paths ["env/prod/clj"]

 :resource-paths ["env/prod/resources"]}

   :dev   [:project/dev :profiles/dev]

   :test  [:project/test :profiles/test]

   :project/dev  {:dependencies [[prone "1.0.1"]

 [ring/ring-mock "0.3.0"]

 [ring/ring-devel "1.4.0"]

 [pjstadig/humane-test-output "0.7.1"]

 [mvxcvi/puget "1.0.0"]]

  

  

  :source-paths ["env/dev/clj" "test/clj"]

  :resource-paths ["env/dev/resources"]

  :repl-options {:init-ns user}

  :injections [(require 'pjstadig.humane-test-output)

   (pjstadig.humane-test-output/activate!)]

  ;;when :nrepl-port is set the application starts the 
nREPL server on load

  :env {:devtrue

:port   3000

:nrepl-port 7000}}

   :project/test {:env {:test   true

:port   3001

:nrepl-port 7001}}

   :profiles/dev {}

   :profiles/test {}})


On Monday, December 24, 2018 at 10:12:04 PM UTC+1, nenad mitrovic wrote:
>
> I am trying to execute this piece of code: (rest (file-seq (file (str 
> "corpus/" "ham"))).
> When I execute I get this error: "error in process filter: Stack overflow 
> in regexp matcher".
> I have 1400 files in corpus/ham folder. But when I execute only three file 
> it works.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: error in process filter: Stack overflow in regexp matcher

2018-12-24 Thread nenad mitrovic
Sorry, here is profiles.clj

{:user
  {
  :java-cmd "C:\\Program Files\\Java\\jdk1.8.0_111\\bin\\java.exe"
  :plugins [
  
[cider/cider-nrepl "0.8.1"]
[luminus/lein-template "2.9.9.2"]

]
   }
 }

On Monday, December 24, 2018 at 10:12:04 PM UTC+1, nenad mitrovic wrote:
>
> I am trying to execute this piece of code: (rest (file-seq (file (str 
> "corpus/" "ham"))).
> When I execute I get this error: "error in process filter: Stack overflow 
> in regexp matcher".
> I have 1400 files in corpus/ham folder. But when I execute only three file 
> it works.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: error in process filter: Stack overflow in regexp matcher

2018-12-24 Thread Andy Fingerhut
I have just tried to reproduce a similar case on a system running Mac OS X
10.13.6, Oracle/Apple Java 1.8.0_192, Clojure 1.9.0, and Leiningen 2.8.3,
and a directory containing 1400 files.  I did not see the error you did.

What versions of OS, Java, Clojure, and anything on top of Clojure (e.g.
Leiningen) are you using?

If you are using Leiningen, what is the contents of your
~/.lein/profiles.clj and project.clj files, if any?  Some add-on plugins
that modify what is shown in the REPL, e.g. that auto-pretty-print results,
can have errors parsing some input, or printing some output, even if
Clojure by itself has no problems.  If you can reproduce your problem using
a `clj` command line that avoids using Leiningen, for example, that would
help determine whether it is caused by something in your Leiningen setup,
vs. elsewhere.

Andy

On Mon, Dec 24, 2018 at 1:12 PM nenad mitrovic 
wrote:

> I am trying to execute this piece of code: (rest (file-seq (file (str
> "corpus/" "ham"))).
> When I execute I get this error: "error in process filter: Stack overflow
> in regexp matcher".
> I have 1400 files in corpus/ham folder. But when I execute only three file
> it works.
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


error in process filter: Stack overflow in regexp matcher

2018-12-24 Thread nenad mitrovic
I am trying to execute this piece of code: (rest (file-seq (file (str 
"corpus/" "ham"))).
When I execute I get this error: "error in process filter: Stack overflow 
in regexp matcher".
I have 1400 files in corpus/ham folder. But when I execute only three file 
it works.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Stack Overflow Question

2016-12-25 Thread Jiacai Liu
I have left a comment below your answer on StackOverflow, can you explain 
it a little more. thanks

On Saturday, December 24, 2016 at 11:12:03 PM UTC+8, James Reeves wrote:
>
> On 24 December 2016 at 11:48, Jiacai Liu  > wrote:
>
>> how to make correct fn args when create fn using macro
>> http://stackoverflow.com/q/41312963/2163429?sem=2
>>
>
> For reference, I posted an answer on StackOverflow.
>
> - James 
>
>

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


Re: Stack Overflow Question

2016-12-24 Thread James Reeves
On 24 December 2016 at 11:48, Jiacai Liu  wrote:

> how to make correct fn args when create fn using macro
> http://stackoverflow.com/q/41312963/2163429?sem=2
>

For reference, I posted an answer on StackOverflow.

- James

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


Re: Stack Overflow Question

2016-12-24 Thread Jiacai Liu


your version is obviously wrong, when '~param will try to resolve param, 
but no luck

On Saturday, December 24, 2016 at 10:07:15 PM UTC+8, Jim foo.bar wrote:
>
> try the following:
>
> (defmacro defapihandler [handler-name params & body]
>   `(defn ~handler-name ['~passed-param]
>  (let [param-keys# (vec (map (comp symbol name :key)
> ~params))
>{:keys param-keys#} '~passed-param]
>;; some check
>~@body)))
>
>
>
> Sorry for brevity, I'm on my phone...
> Dimitris
>
> On 24/12/16 13:23, Jiacai Liu wrote:
>
> I don’t think your answer is correct. From the expaned macro
>
> (defn create-user [passed-param__10243__auto__]
>   (let [param-keys__10244__auto__ (vec
> (map
>   (comp symbol name :key)
>   [{:key :username,
> :checkers []}]))
> {:keys param-keys__10244__auto__} passed-param__10243__auto__]
> (do (println username
>
> and following test
>
> (let [some-keys '[a b]
>   {:keys some-keys} {:a 1 :b 2}]
>   ; thows Don't know how to create ISeq from: clojure.lang.Symbol
>   (println a b))
>
> (let [{:keys [a b]} {:a 1 :b 2}]
>   ; ok
>   (println a b))
>
> I think it is in let destructuring form, we can’t use dynamic var to 
> represent symbols
>
>
>
> On Saturday, December 24, 2016 at 8:43:42 PM UTC+8, Jim foo.bar wrote: 
>>
>> you need to use `'~passed-param` in your arg-vector, and the same 
>> whenever you use it inside the newly defined fn.
>>
>>
>> HTH,
>>
>> Dimitris
>>
>> On 24/12/16 11:48, Jiacai Liu wrote:
>>
>> how to make correct fn args when create fn using macro
>> http://stackoverflow.com/q/41312963/2163429?sem=2
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+u...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Stack Overflow Question

2016-12-24 Thread dimitris

try the following:

|(defmacrodefapihandler [handler-name params & body]`(defn~handler-name 
['~passed-param](let[param-keys# (vec(map(comp symbol name 
:key)~params)){:keysparam-keys#}'~passed-param];; some check~@body))) |


Sorry for brevity, I'm on my phone...
Dimitris

On 24/12/16 13:23, Jiacai Liu wrote:


I don’t think your answer is correct. From the expaned macro

|(defn create-user [passed-param__10243__auto__] (let 
[param-keys__10244__auto__ (vec (map (comp symbol name :key) [{:key 
:username, :checkers []}])) {:keys param-keys__10244__auto__} 
passed-param__10243__auto__] (do (println username |


and following test

|(let [some-keys '[a b] {:keys some-keys} {:a 1 :b 2}] ; thows Don't 
know how to create ISeq from: clojure.lang.Symbol (println a b)) (let 
[{:keys [a b]} {:a 1 :b 2}] ; ok (println a b)) |


I think it is in let destructuring form, we can’t use dynamic var to 
represent symbols





On Saturday, December 24, 2016 at 8:43:42 PM UTC+8, Jim foo.bar wrote:

you need to use `'~passed-param` in your arg-vector, and the same
whenever you use it inside the newly defined fn.


HTH,

Dimitris


On 24/12/16 11:48, Jiacai Liu wrote:

how to make correct fn args when create fn using macro
http://stackoverflow.com/q/41312963/2163429?sem=2

-- 
You received this message because you are subscribed to the Google

Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it,
send an email to clojure+u...@googlegroups.com .
For more options, visit https://groups.google.com/d/optout
.


--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Stack Overflow Question

2016-12-24 Thread Jiacai Liu


I don’t think your answer is correct. From the expaned macro

(defn create-user [passed-param__10243__auto__]
  (let [param-keys__10244__auto__ (vec
(map
  (comp symbol name :key)
  [{:key :username,
:checkers []}]))
{:keys param-keys__10244__auto__} passed-param__10243__auto__]
(do (println username

and following test

(let [some-keys '[a b]
  {:keys some-keys} {:a 1 :b 2}]
  ; thows Don't know how to create ISeq from: clojure.lang.Symbol
  (println a b))

(let [{:keys [a b]} {:a 1 :b 2}]
  ; ok
  (println a b))

I think it is in let destructuring form, we can’t use dynamic var to 
represent symbols



On Saturday, December 24, 2016 at 8:43:42 PM UTC+8, Jim foo.bar wrote:
>
> you need to use `'~passed-param` in your arg-vector, and the same whenever 
> you use it inside the newly defined fn.
>
>
> HTH,
>
> Dimitris
>
> On 24/12/16 11:48, Jiacai Liu wrote:
>
> how to make correct fn args when create fn using macro
> http://stackoverflow.com/q/41312963/2163429?sem=2
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+u...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Stack Overflow Question

2016-12-24 Thread dimitris
you need to use `'~passed-param` in your arg-vector, and the same 
whenever you use it inside the newly defined fn.



HTH,

Dimitris


On 24/12/16 11:48, Jiacai Liu wrote:

how to make correct fn args when create fn using macro
http://stackoverflow.com/q/41312963/2163429?sem=2
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Stack Overflow Question

2016-12-24 Thread Jiacai Liu
how to make correct fn args when create fn using macro
http://stackoverflow.com/q/41312963/2163429?sem=2

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: stack overflow

2015-12-13 Thread Sunil S Nandihalli
Thanks Andy for the response. I was able to make it work by modifying the
code in the following way

(let [modulo 10007
  trunc #(mod % modulo)
  mult-m (comp trunc *)
  add-m (comp trunc +)
  h (fn [mf l]
  (if (<= l 1) 1
  (trunc (reduce add-m 0
 (map #(mult-m (mf mf (- l % 1)) (mf mf %))
  (range l))
  mf (memoize h)]
  (defn num-trees [n]
(doseq [i (range n)] (mf mf i))
(mf mf n)))

I was able to fix the problem by progressively building up the answer
bottom up.

Regards,
Sunil


On Sun, Dec 13, 2015 at 3:03 PM, Andy Fingerhut <andy.finger...@gmail.com>
wrote:

> You can increase the maximum stack size in your JVM with command line
> options when you start it.
>
> You can reduce the amount of stack memory required per recursive
> iteration.  I don't know if let-bound symbols like modulo, trunc, mult-m,
> and add-m require separate stack space per recursive call in your function
> or not, but if they do, in your function those could easily be made into
> separate functions defined outside of num-trees.
>
> The biggest way to avoid using stack space is to write the code in a way
> that doesn't make recursive calls, but this can often be fairly
> inconvenient for functions that are naturally written recursively.
> Increasing the maximum stack size would be a lot quicker.
>
> Andy
>
> On Sat, Dec 12, 2015 at 9:38 PM, Sunil S Nandihalli <
> sunil.nandiha...@gmail.com> wrote:
>
>> Hi Everybody,
>> I wrote the simple function for computing the number of
>> binary-search-trees that can be formed from a sequence of numbers from 1 to
>> N using memoization. I get a stack-overflow for values more than N of 196.
>> Can anybody help me in figuring out how to fix this?
>> Thanks,
>> Sunil.
>>
>> (defn num-trees [n]
>>   (let [modulo 10007
>> trunc #(mod % modulo)
>> mult-m (comp trunc *)
>> add-m (comp trunc +)
>> h (fn [mf l]
>> (if (<= l 1) 1
>> (trunc (reduce add-m 0
>>(map #(mult-m (mf mf (- l % 1)) (mf mf %))
>> (range l))
>> mf (memoize h)]
>> (mf mf n)))
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: stack overflow

2015-12-13 Thread Andy Fingerhut
You can increase the maximum stack size in your JVM with command line
options when you start it.

You can reduce the amount of stack memory required per recursive
iteration.  I don't know if let-bound symbols like modulo, trunc, mult-m,
and add-m require separate stack space per recursive call in your function
or not, but if they do, in your function those could easily be made into
separate functions defined outside of num-trees.

The biggest way to avoid using stack space is to write the code in a way
that doesn't make recursive calls, but this can often be fairly
inconvenient for functions that are naturally written recursively.
Increasing the maximum stack size would be a lot quicker.

Andy

On Sat, Dec 12, 2015 at 9:38 PM, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:

> Hi Everybody,
> I wrote the simple function for computing the number of
> binary-search-trees that can be formed from a sequence of numbers from 1 to
> N using memoization. I get a stack-overflow for values more than N of 196.
> Can anybody help me in figuring out how to fix this?
> Thanks,
> Sunil.
>
> (defn num-trees [n]
>   (let [modulo 10007
> trunc #(mod % modulo)
> mult-m (comp trunc *)
> add-m (comp trunc +)
> h (fn [mf l]
> (if (<= l 1) 1
> (trunc (reduce add-m 0
>(map #(mult-m (mf mf (- l % 1)) (mf mf %))
> (range l))
> mf (memoize h)]
> (mf mf n)))
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: stack overflow

2015-12-13 Thread Mark Engelberg
Call your memoized function on values 1 .. n-1 first, before calling it on
n.
On Dec 12, 2015 9:45 PM, "Sunil S Nandihalli" <sunil.nandiha...@gmail.com>
wrote:

> a small correction. The function computes the modulo 10007 of the
> answer and not the answer itself. I ran it in the repl.
> Thanks,
> Sunil.
>
> On Sun, Dec 13, 2015 at 11:08 AM, Sunil S Nandihalli <
> sunil.nandiha...@gmail.com> wrote:
>
>> Hi Everybody,
>> I wrote the simple function for computing the number of
>> binary-search-trees that can be formed from a sequence of numbers from 1 to
>> N using memoization. I get a stack-overflow for values more than N of 196.
>> Can anybody help me in figuring out how to fix this?
>> Thanks,
>> Sunil.
>>
>> (defn num-trees [n]
>>   (let [modulo 10007
>> trunc #(mod % modulo)
>> mult-m (comp trunc *)
>> add-m (comp trunc +)
>> h (fn [mf l]
>> (if (<= l 1) 1
>> (trunc (reduce add-m 0
>>(map #(mult-m (mf mf (- l % 1)) (mf mf %))
>> (range l))
>> mf (memoize h)]
>> (mf mf n)))
>>
>>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: stack overflow

2015-12-13 Thread Sunil S Nandihalli
Thanks Mark. That is exactly what I ended up doing.

Regards,
Sunil.

On Sun, Dec 13, 2015 at 8:45 PM, Mark Engelberg <mark.engelb...@gmail.com>
wrote:

> Call your memoized function on values 1 .. n-1 first, before calling it on
> n.
> On Dec 12, 2015 9:45 PM, "Sunil S Nandihalli" <sunil.nandiha...@gmail.com>
> wrote:
>
>> a small correction. The function computes the modulo 10007 of the
>> answer and not the answer itself. I ran it in the repl.
>> Thanks,
>> Sunil.
>>
>> On Sun, Dec 13, 2015 at 11:08 AM, Sunil S Nandihalli <
>> sunil.nandiha...@gmail.com> wrote:
>>
>>> Hi Everybody,
>>> I wrote the simple function for computing the number of
>>> binary-search-trees that can be formed from a sequence of numbers from 1 to
>>> N using memoization. I get a stack-overflow for values more than N of 196.
>>> Can anybody help me in figuring out how to fix this?
>>> Thanks,
>>> Sunil.
>>>
>>> (defn num-trees [n]
>>>   (let [modulo 10007
>>> trunc #(mod % modulo)
>>> mult-m (comp trunc *)
>>> add-m (comp trunc +)
>>> h (fn [mf l]
>>> (if (<= l 1) 1
>>> (trunc (reduce add-m 0
>>>(map #(mult-m (mf mf (- l % 1)) (mf mf %))
>>> (range l))
>>> mf (memoize h)]
>>> (mf mf n)))
>>>
>>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


stack overflow

2015-12-12 Thread Sunil S Nandihalli
Hi Everybody,
I wrote the simple function for computing the number of binary-search-trees
that can be formed from a sequence of numbers from 1 to N using
memoization. I get a stack-overflow for values more than N of 196. Can
anybody help me in figuring out how to fix this?
Thanks,
Sunil.

(defn num-trees [n]
  (let [modulo 10007
trunc #(mod % modulo)
mult-m (comp trunc *)
add-m (comp trunc +)
h (fn [mf l]
(if (<= l 1) 1
(trunc (reduce add-m 0
   (map #(mult-m (mf mf (- l % 1)) (mf mf %))
(range l))
mf (memoize h)]
(mf mf n)))

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


Re: stack overflow

2015-12-12 Thread Sunil S Nandihalli
a small correction. The function computes the modulo 10007 of the
answer and not the answer itself. I ran it in the repl.
Thanks,
Sunil.

On Sun, Dec 13, 2015 at 11:08 AM, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:

> Hi Everybody,
> I wrote the simple function for computing the number of
> binary-search-trees that can be formed from a sequence of numbers from 1 to
> N using memoization. I get a stack-overflow for values more than N of 196.
> Can anybody help me in figuring out how to fix this?
> Thanks,
> Sunil.
>
> (defn num-trees [n]
>   (let [modulo 10007
> trunc #(mod % modulo)
> mult-m (comp trunc *)
> add-m (comp trunc +)
> h (fn [mf l]
> (if (<= l 1) 1
> (trunc (reduce add-m 0
>(map #(mult-m (mf mf (- l % 1)) (mf mf %))
> (range l))
> mf (memoize h)]
> (mf mf n)))
>
>

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


Re: Lazy Sequence Results in Stack Overflow

2015-09-28 Thread Yoshinori Kohyama
Hi, Charles and all.

Here is my definition of prime numbers:
https://gist.github.com/kohyama/8e599b2e765ad4256f32

HTH.

Yoshinori Kohyama

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Lazy Sequence Results in Stack Overflow

2015-09-26 Thread Gary Verhaegen
Primes are hard, because you essentially need to track all previous primes.

Here's one way to think about what you're doing here. First, you
create a lazy sequence of infinite numbers from 3 and up. This is done
by building a cons cell with 3 as the head and (iterate inc 4) as the
tail.

Then you filter that. From now on, every time you want the next
element, you'll have to run two functons: inc and odd?, plus some
extra processing for iterate and filter which both build up an
intermediate lazy seq.

Then you call sieve, which yet again builds up a new lazy seq that
accumulates more functions on its tail: assoc-nth, drop-while and a
recursive call to sieve. And assoc-nth itself still wraps a bunch of
other functions on your tail.

Now, the crucial part here is that most of these functions never go
away: for each new element that you compute, you add additional
function calls to each subsequent element. So that getting the 5th
element requires more additional elements than getting the 4th.

In some way, you have chosen to encode your list of previous primes as
accumulated functions. By the 500th prime, you have some much
accumulated functions that your call stack itself blows the stack.

With your implementation, on my computer, I only get about 300:

(defn num-primes
  [prime-seq]
  (try (doall prime-seq)
   (catch StackOverflowError e
 (count prime-seq

=> (time (num-primes primes))
"Elapsed time: 62385.706564 msecs"
325

A slightly more direct approach to the sieve (though arguably not a
true sieve), which has the same problem, in a more obvious way, would
be:

(defn filter-primes
  []
  (let [helper (fn helper [n]
 (lazy-seq (cons n (remove #(zero? (mod % n))
   (helper (inc n))]
(helper 2)))

=> (time (max-prime (filter-primes)))
"Elapsed time: 472.078328 msecs"
251

Two things to note:

* I've turned the sequence into a defn instead of a def. This makes it
possible to not hold onto the head. Since we get a stack overflow
around 300 integers here, this is no biggie, but it's a good practice
when defining potentially very long lazy seqs.
* It should be much more clear here that each prime is adding a call
to remove: whereas the 2 gets returned directly, the 3 has to go
through a mod 2 operation, then a remove function has to check that it
returned false. Similarly, the 5 will, in this very naive
implementation, need to check that it is not divisible by either 2, 3,
or 4, so we now have a "stack" of three remove functions to go
through.

A closer implementation to yours would be:

(defn filter-primes2
  []
  (let [sieve (fn [ls]
(let [p (first ls)]
  (lazy-seq
(cons p (remove #(zero? (mod % p)) ls)]
(sieve (iterate inc 2

=> (time (num-primes (filter-primes2)))
"Elapsed time: 59021.93554 msecs"
325

However, storing "primes found so far" into a stack of functions is
not very efficient (in either memory or computation), and the sieve
only really shines when it's used on vectors of known length (because
then there's no division), not on lazy seqs of potentially infinite
length. Here's an attempt to combine the advantages of the sieve with
lazy seqs:

(defn array-sieve
  []
  (let [sieve (fn [n]
(let [a (long-array n)]
  (loop [idx 0]
(when (< idx n)
  (aset-long a idx (+ 2 idx))
  (recur (inc idx
  (loop [idx 0]
(when (and (< idx n)
   (not= 0 (aget a idx)))
  (let [v (aget a idx)]
(loop [idx2 (+ idx v)]
  (when (< idx2 n)
(aset-long a idx2 0)
(recur (+ v idx2))
(when (< idx n)
  (recur (inc idx
  (vec (remove zero? a
generator (fn [[prev-idx known-primes prev-prime]]
(let [next-idx (inc prev-idx)
  known-primes (if (< next-idx (count known-primes))
 known-primes
 (loop [n (* 2 next-idx)]
   (let [k (sieve n)]
 (if (> (count k) next-idx)
   k

(recur (* 2 n))
  next-prime (get known-primes next-idx)]
  [next-idx known-primes next-prime]))]
(->> [0 [2] 2]
 (iterate generator)
 (map last

=> (time (nth (array-sieve) (dec 10)))
"Elapsed time: 13454.668724 msecs"
1299709

(You can check e.g. here that this is correct:
https://primes.utm.edu/nthprime/index.php#nth; the dec is there
because this

Re: Lazy Sequence Results in Stack Overflow

2015-09-26 Thread William la Forge
Why not turn this problem on its head? Have a vector of lists of prime 
factors for each i. March through this vector and for each prime factor in 
the current list, add that prime factor p to list i + p. And if i has no 
prime factors, then it is a prime itself and add it to the list at 2 * i.

So the only test for prime is if i has no prime factors as determined by 
propagating the prime factors forward, not through a mod function.

On Wednesday, September 23, 2015 at 8:14:39 PM UTC-4, Charles Reese wrote:
>
> I want to compute a lazy sequence of primes.
>
> Here is the interface:
>
> user=> (take 10 primes)
> (2 3 5 7 11 13 17 19 23 29)
>
> So far, so good.
>
> However, when I take 500 primes, this results in a stack overflow.
>
>   core.clj:  133  clojure.core/seq
>   core.clj: 2595  clojure.core/filter/fn
>   LazySeq.java:   40  clojure.lang.LazySeq/sval
>   LazySeq.java:   49  clojure.lang.LazySeq/seq
>RT.java:  484  clojure.lang.RT/seq
>   core.clj:  133  clojure.core/seq
>   core.clj: 2626  clojure.core/take/fn
>   LazySeq.java:   40  clojure.lang.LazySeq/sval
>   LazySeq.java:   49  clojure.lang.LazySeq/seq
>  Cons.java:   39  clojure.lang.Cons/next
>   LazySeq.java:   81  clojure.lang.LazySeq/next
>RT.java:  598  clojure.lang.RT/next
>   core.clj:   64  clojure.core/next
>   core.clj: 2856  clojure.core/dorun
>   core.clj: 2871  clojure.core/doall
>   core.clj: 2910  clojure.core/partition/fn
>   LazySeq.java:   40  clojure.lang.LazySeq/sval
>   LazySeq.java:   49  clojure.lang.LazySeq/seq
>RT.java:  484  clojure.lang.RT/seq
>   core.clj:  133  clojure.core/seq
>   core.clj: 2551  clojure.core/map/fn
>   LazySeq.java:   40  clojure.lang.LazySeq/sval
>   LazySeq.java:   49  clojure.lang.LazySeq/seq
>RT.java:  484  clojure.lang.RT/seq
>   core.clj:  133  clojure.core/seq
>   core.clj: 3973  clojure.core/interleave/fn
>   LazySeq.java:   40  clojure.lang.LazySeq/sval
>   
> I'm wondering what is the problem here and, more generally, when working 
> with lazy sequences, how should I approach this class of error?
>
> Here is the code.
>
> (defn assoc-nth
>   "Returns a lazy seq of coll, replacing every nth element by val
>
>   Ex:
>   user=> (assoc-nth [3 4 5 6 7 8 9 10] 2 nil)
>   (3 nil 5 nil 7 nil 9 nil)
>   "
>   [coll n val]
>   (apply concat
>  (interleave
>   (map #(take (dec n) %) (partition n coll)) (repeat [val]
>
> (defn sieve
>   "Returns a lazy seq of primes by Eratosthenes' method
>
>   Ex:
>   user=> (take 4 (sieve (iterate inc 2)))
>   (2 3 5 7)
>
>   user=> (take 10 (sieve (iterate inc 2)))
>   (2 3 5 7 11 13 17 19 23 29)
>   "
>   [s]
>   (lazy-seq
>(if (seq s)
>  (cons (first s) (sieve
>   (drop-while nil? (assoc-nth (rest s) (first s) 
> nil
>  [])))
>
> (def primes
>   "Returns a lazy seq of primes
>
>   Ex:
>   user=> (take 10 primes)
>   (2 3 5 7 11 13 17 19 23 29)
>   "
>   (concat [2] (sieve (filter odd? (iterate inc 3)
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Lazy Sequence Results in Stack Overflow

2015-09-23 Thread Charles Reese
I want to compute a lazy sequence of primes.

Here is the interface:

user=> (take 10 primes)
(2 3 5 7 11 13 17 19 23 29)

So far, so good.

However, when I take 500 primes, this results in a stack overflow.

  core.clj:  133  clojure.core/seq
  core.clj: 2595  clojure.core/filter/fn
  LazySeq.java:   40  clojure.lang.LazySeq/sval
  LazySeq.java:   49  clojure.lang.LazySeq/seq
   RT.java:  484  clojure.lang.RT/seq
  core.clj:  133  clojure.core/seq
  core.clj: 2626  clojure.core/take/fn
  LazySeq.java:   40  clojure.lang.LazySeq/sval
  LazySeq.java:   49  clojure.lang.LazySeq/seq
 Cons.java:   39  clojure.lang.Cons/next
  LazySeq.java:   81  clojure.lang.LazySeq/next
   RT.java:  598  clojure.lang.RT/next
  core.clj:   64  clojure.core/next
  core.clj: 2856  clojure.core/dorun
  core.clj: 2871  clojure.core/doall
  core.clj: 2910  clojure.core/partition/fn
  LazySeq.java:   40  clojure.lang.LazySeq/sval
  LazySeq.java:   49  clojure.lang.LazySeq/seq
   RT.java:  484  clojure.lang.RT/seq
  core.clj:  133  clojure.core/seq
  core.clj: 2551  clojure.core/map/fn
  LazySeq.java:   40  clojure.lang.LazySeq/sval
  LazySeq.java:   49  clojure.lang.LazySeq/seq
   RT.java:  484  clojure.lang.RT/seq
  core.clj:  133  clojure.core/seq
  core.clj: 3973  clojure.core/interleave/fn
  LazySeq.java:   40  clojure.lang.LazySeq/sval
  
I'm wondering what is the problem here and, more generally, when working 
with lazy sequences, how should I approach this class of error?

Here is the code.

(defn assoc-nth
  "Returns a lazy seq of coll, replacing every nth element by val

  Ex:
  user=> (assoc-nth [3 4 5 6 7 8 9 10] 2 nil)
  (3 nil 5 nil 7 nil 9 nil)
  "
  [coll n val]
  (apply concat
 (interleave
  (map #(take (dec n) %) (partition n coll)) (repeat [val]

(defn sieve
  "Returns a lazy seq of primes by Eratosthenes' method

  Ex:
  user=> (take 4 (sieve (iterate inc 2)))
  (2 3 5 7)

  user=> (take 10 (sieve (iterate inc 2)))
  (2 3 5 7 11 13 17 19 23 29)
  "
  [s]
  (lazy-seq
   (if (seq s)
 (cons (first s) (sieve
  (drop-while nil? (assoc-nth (rest s) (first s) 
nil
 [])))

(def primes
  "Returns a lazy seq of primes

  Ex:
  user=> (take 10 primes)
  (2 3 5 7 11 13 17 19 23 29)
  "
  (concat [2] (sieve (filter odd? (iterate inc 3)

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Lazy Sequence Results in Stack Overflow

2015-09-23 Thread Colin Yates
This might help:
http://stuartsierra.com/2015/08/25/clojure-donts-lazy-effects
On 24 Sep 2015 01:14, "Charles Reese" <charlespre...@gmail.com> wrote:

> I want to compute a lazy sequence of primes.
>
> Here is the interface:
>
> user=> (take 10 primes)
> (2 3 5 7 11 13 17 19 23 29)
>
> So far, so good.
>
> However, when I take 500 primes, this results in a stack overflow.
>
>   core.clj:  133  clojure.core/seq
>   core.clj: 2595  clojure.core/filter/fn
>   LazySeq.java:   40  clojure.lang.LazySeq/sval
>   LazySeq.java:   49  clojure.lang.LazySeq/seq
>RT.java:  484  clojure.lang.RT/seq
>   core.clj:  133  clojure.core/seq
>   core.clj: 2626  clojure.core/take/fn
>   LazySeq.java:   40  clojure.lang.LazySeq/sval
>   LazySeq.java:   49  clojure.lang.LazySeq/seq
>  Cons.java:   39  clojure.lang.Cons/next
>   LazySeq.java:   81  clojure.lang.LazySeq/next
>RT.java:  598  clojure.lang.RT/next
>   core.clj:   64  clojure.core/next
>   core.clj: 2856  clojure.core/dorun
>   core.clj: 2871  clojure.core/doall
>   core.clj: 2910  clojure.core/partition/fn
>   LazySeq.java:   40  clojure.lang.LazySeq/sval
>   LazySeq.java:   49  clojure.lang.LazySeq/seq
>RT.java:  484  clojure.lang.RT/seq
>   core.clj:  133  clojure.core/seq
>   core.clj: 2551  clojure.core/map/fn
>   LazySeq.java:   40  clojure.lang.LazySeq/sval
>   LazySeq.java:   49  clojure.lang.LazySeq/seq
>RT.java:  484  clojure.lang.RT/seq
>   core.clj:  133  clojure.core/seq
>   core.clj: 3973  clojure.core/interleave/fn
>   LazySeq.java:   40  clojure.lang.LazySeq/sval
>
> I'm wondering what is the problem here and, more generally, when working
> with lazy sequences, how should I approach this class of error?
>
> Here is the code.
>
> (defn assoc-nth
>   "Returns a lazy seq of coll, replacing every nth element by val
>
>   Ex:
>   user=> (assoc-nth [3 4 5 6 7 8 9 10] 2 nil)
>   (3 nil 5 nil 7 nil 9 nil)
>   "
>   [coll n val]
>   (apply concat
>  (interleave
>   (map #(take (dec n) %) (partition n coll)) (repeat [val]
>
> (defn sieve
>   "Returns a lazy seq of primes by Eratosthenes' method
>
>   Ex:
>   user=> (take 4 (sieve (iterate inc 2)))
>   (2 3 5 7)
>
>   user=> (take 10 (sieve (iterate inc 2)))
>   (2 3 5 7 11 13 17 19 23 29)
>   "
>   [s]
>   (lazy-seq
>(if (seq s)
>  (cons (first s) (sieve
>   (drop-while nil? (assoc-nth (rest s) (first s)
> nil
>  [])))
>
> (def primes
>   "Returns a lazy seq of primes
>
>   Ex:
>   user=> (take 10 primes)
>   (2 3 5 7 11 13 17 19 23 29)
>   "
>   (concat [2] (sieve (filter odd? (iterate inc 3)
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Stack overflow while compiling...?

2015-04-14 Thread Simon Brooke
I'm persistently getting this. Annoyingly, it happens a long way through a 
very big computation:

CompilerException java.lang.StackOverflowError, 
compiling:(/tmp/form-init8817362891013362767.clj:1:1)

The content of file /tmp/form-init8817362891013362767.clj being compiled is 
this:

(.deleteOnExit (java.io.File. /tmp/form-init8817362891013362767.clj)) (do 
(set! *warn-on-reflection* nil) (require (quote gorilla-repl.core)) 
(gorilla-repl.core/run-gorilla-server {:ip 127.0.0.1, :port 0, 
:nrepl-port 0, :project mw-explore, :gorilla-options nil, :version 
0.3.4}))

I get the same error (although, obviously, not quite the same tmp file) 
when I run at the repl rather than with Gorilla. The stacktrace does not 
touch any file of mine.

The actual file of my own I'm evaluating is this:

https://github.com/simon-brooke/mw-explore/blob/master/src/mw_explore/mw_explore.clj

And it's calling into this library:

https://github.com/simon-brooke/mw-engine

And specifically, it's mainly exercising drainage:

https://github.com/simon-brooke/mw-engine/blob/master/src/mw_engine/drainage.clj

I acknowledge that this is a deep and nasty bit of algorithm, but the only 
thing I can think of that would cause a stack overflow while compiling 
would be an accidentally-recursive macro - and I'm not getting any of my 
own macros.

This problem started after I introduced three new functions:

(defn is-hollow
  Detects point hollows - that is, individual cells all of whose 
neighbours 
   are higher. Return true if this `cell` has an altitude lower than any of 
   its neighbours in this `world` 
  [world cell]
  ;; quicker to count the elements of the list and compare equality of 
numbers
  ;; than recursive equality check on members, I think. But worth 
benchmarking.
  (let [neighbours (get-neighbours world cell)
altitude (or (:altitude cell) 0)]
(= (count neighbours)
   (count (get-neighbours-with-property-value 
world (:x cell) (:y cell) 1 :altitude )

(defn flood-hollow
  Raise the altitude of a copy of this `cell` of this `world` to the 
altitude  
   of the lowest of its `neighbours`.
  ([world cell neighbours]
(let [lowest (get-least-cell neighbours :altitude)]
  (merge cell {:state :water :altitude (:altitude lowest)})))
  ([world cell]
(flood-hollow world cell (get-neighbours world cell

(defn flood-hollows 
  Flood all local hollows in this `world`. At this stage only floods single
   cell hollows.
  [world]
  (map-world world 
 #(if (is-hollow %1 %2) (flood-hollow %1 %2) %2)))

However at the stage the problem occurs, these functions have evaluated 
successfully, and am into the flow-world stage, which previously worked 
reliably.

Has anyone seen anything analogous? Any pointers as to what I might be 
doing wrong?


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Looking for help with a Stack Overflow error

2014-05-18 Thread Leif
Hi, Brad (and Karsten).

I solved the problem with core.logic, to try out its CLP(FD) features.  It 
took about 220-230ms to find a solution.  It took about 400ms to find all 
solutions.

Here it is for you to peek at after you try it:
https://gist.github.com/leifp/b4af5f4cd7289c38b55a

The code looked very similar to the problem statement, no careful 
hand-crafting required.  The one minor irritation is that there is no way 
to easily specify equations involving vectors of logic vars.  I think I 
could've done it in this case with macros, but I wouldn't want to do that 
if I had hundreds or thousands of variables.  Maybe I'm just not 
experienced enough with core.logic, experts chime in if so.

--Leif

On Friday, May 16, 2014 3:31:26 PM UTC-4, Brad Kurtz wrote:

 I'm pretty new to Clojure so I'm trying out simple examples to see if I 
 can get myself in the functional programming/Lisp mindset. My team lead 
 sends out puzzles from his Mensa calendar, and every once in a while I find 
 one that seems fun to solve as a Clojure program.

 With this particular puzzle, I've tried a couple of different ways of 
 solving the puzzle, and I decided to try a recursive function. I'm fairly 
 certain that what I've done here is not anywhere near ideal, and I'm 
 looking for insight into how to better write this solution.

 Also, with my latest attempt I seem to be getting a stack overflow error, 
 and I'm not quite sure why. I'm pretty sure it has to do with the 
 permutation sequence (it's basically 10 factorial, or around 3 million 
 sequences), but I don't really know how to better represent this problem in 
 Clojure. Can anyone help? Thanks!

 https://github.com/bradkurtz/clojure-puzzles/tree/master/billiards


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Looking for help with a Stack Overflow error

2014-05-18 Thread Brad Kurtz
I've seen David Nolen talk a bit about core.logic and I admit it seems 
interesting. Since I'm new to Clojure I didn't think to look into it. I'll 
take a look at your solution Leif. Thanks for the suggestions everyone.

On Sunday, May 18, 2014 6:28:15 PM UTC-5, Leif wrote:

 Hi, Brad (and Karsten).

 I solved the problem with core.logic, to try out its CLP(FD) features.  It 
 took about 220-230ms to find a solution.  It took about 400ms to find all 
 solutions.

 Here it is for you to peek at after you try it:
 https://gist.github.com/leifp/b4af5f4cd7289c38b55a

 The code looked very similar to the problem statement, no careful 
 hand-crafting required.  The one minor irritation is that there is no way 
 to easily specify equations involving vectors of logic vars.  I think I 
 could've done it in this case with macros, but I wouldn't want to do that 
 if I had hundreds or thousands of variables.  Maybe I'm just not 
 experienced enough with core.logic, experts chime in if so.

 --Leif

 On Friday, May 16, 2014 3:31:26 PM UTC-4, Brad Kurtz wrote:

 I'm pretty new to Clojure so I'm trying out simple examples to see if I 
 can get myself in the functional programming/Lisp mindset. My team lead 
 sends out puzzles from his Mensa calendar, and every once in a while I find 
 one that seems fun to solve as a Clojure program.

 With this particular puzzle, I've tried a couple of different ways of 
 solving the puzzle, and I decided to try a recursive function. I'm fairly 
 certain that what I've done here is not anywhere near ideal, and I'm 
 looking for insight into how to better write this solution.

 Also, with my latest attempt I seem to be getting a stack overflow error, 
 and I'm not quite sure why. I'm pretty sure it has to do with the 
 permutation sequence (it's basically 10 factorial, or around 3 million 
 sequences), but I don't really know how to better represent this problem in 
 Clojure. Can anyone help? Thanks!

 https://github.com/bradkurtz/clojure-puzzles/tree/master/billiards



-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Looking for help with a Stack Overflow error

2014-05-17 Thread Karsten Schmidt
Hi Brad, I can't help you with your solution, but just wanted to mention
that the core.logic library might be a great tool for this kind of problem
(plus I'd be v.interested in seeing a solution using this myself... :)

K.
On 16 May 2014 22:15, Brad Kurtz bkurtz@gmail.com wrote:

 I have since fixed the original stack overflow error I was getting, it was
 a result of not using recur. However, I'm still trying to find the best
 way to actually iterate through the permutations to find the result...

 On Friday, May 16, 2014 2:31:26 PM UTC-5, Brad Kurtz wrote:

 I'm pretty new to Clojure so I'm trying out simple examples to see if I
 can get myself in the functional programming/Lisp mindset. My team lead
 sends out puzzles from his Mensa calendar, and every once in a while I find
 one that seems fun to solve as a Clojure program.

 With this particular puzzle, I've tried a couple of different ways of
 solving the puzzle, and I decided to try a recursive function. I'm fairly
 certain that what I've done here is not anywhere near ideal, and I'm
 looking for insight into how to better write this solution.

 Also, with my latest attempt I seem to be getting a stack overflow error,
 and I'm not quite sure why. I'm pretty sure it has to do with the
 permutation sequence (it's basically 10 factorial, or around 3 million
 sequences), but I don't really know how to better represent this problem in
 Clojure. Can anyone help? Thanks!

 https://github.com/bradkurtz/clojure-puzzles/tree/master/billiards

  --
 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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Looking for help with a Stack Overflow error

2014-05-17 Thread Rob Day

A better approach might be to break it down into three groups:

* The first three numbers (rows 1 and 2), constrained by rule D
* The middle three numbers (row 3), constrained by rule A
* The last four numbers (row 4), constrained by rule E

There are only 10!/7! or 10!/6! initial possibilities for each group, so 
it's much quicker to apply the constraints, and the constraints reduce 
the problem space significantly - only 53 of the original 720 
possibilities satisfy rule D, 4 of the original 720 satisfy rule A, and 
~3000 of the initial 5040 satisfy rule E. At this point, you've run less 
than 7000 checks, but you've reduced your pool of possible solutions 
from 10! (~3,600,000) to ~600,000.


You can then combine those three groups together (to get the possible 
arrangements of all 10 balls), and run a filter to verify that no 
numbers are repeated (e.g. that you aren't combining a solution to the 
first three balls that uses 1 with a solution to the last four balls 
that uses 1 - this step takes it down to about 900 possible answers). 
Then just filter on rules B and C to get the answer. I've got this 
running in about 160ms (though admittedly in Haskell).


There's probably a name for this technique - constraint propagation? - 
but I'll leave it to the formally trained to comment. The slowest step 
is almost certainly discarding repeated solutions - that runs over 
600,000 possible permutations and discards 599,000 of them - so if 
anyone has ideas on how to not generate so many duplicate numbers, that 
would be great.


On 17/05/14 00:15, Brad Kurtz wrote:
I have since fixed the original stack overflow error I was getting, it 
was a result of not using recur. However, I'm still trying to find 
the best way to actually iterate through the permutations to find the 
result...


On Friday, May 16, 2014 2:31:26 PM UTC-5, Brad Kurtz wrote:

I'm pretty new to Clojure so I'm trying out simple examples to see
if I can get myself in the functional programming/Lisp mindset. My
team lead sends out puzzles from his Mensa calendar, and every
once in a while I find one that seems fun to solve as a Clojure
program.

With this particular puzzle, I've tried a couple of different ways
of solving the puzzle, and I decided to try a recursive
function. I'm fairly certain that what I've done here is not
anywhere near ideal, and I'm looking for insight into how to
better write this solution.

Also, with my latest attempt I seem to be getting a stack overflow
error, and I'm not quite sure why. I'm pretty sure it has to do
with the permutation sequence (it's basically 10 factorial, or
around 3 million sequences), but I don't really know how to better
represent this problem in Clojure. Can anyone help? Thanks!

https://github.com/bradkurtz/clojure-puzzles/tree/master/billiards
https://github.com/bradkurtz/clojure-puzzles/tree/master/billiards

--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com 
mailto:clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Looking for help with a Stack Overflow error

2014-05-17 Thread Gary Verhaegen
I'd suggest taking a look at the following blog post:
http://programming-puzzler.blogspot.be/2013/03/logic-programming-is-overrated.html

(The ensuing discussion between David and Mark is also worth reading.)

On 17 May 2014 14:49, Rob Day r...@rkd.me.uk wrote:
 A better approach might be to break it down into three groups:

 * The first three numbers (rows 1 and 2), constrained by rule D
 * The middle three numbers (row 3), constrained by rule A
 * The last four numbers (row 4), constrained by rule E

 There are only 10!/7! or 10!/6! initial possibilities for each group, so
 it's much quicker to apply the constraints, and the constraints reduce the
 problem space significantly - only 53 of the original 720 possibilities
 satisfy rule D, 4 of the original 720 satisfy rule A, and ~3000 of the
 initial 5040 satisfy rule E. At this point, you've run less than 7000
 checks, but you've reduced your pool of possible solutions from 10!
 (~3,600,000) to ~600,000.

 You can then combine those three groups together (to get the possible
 arrangements of all 10 balls), and run a filter to verify that no numbers
 are repeated (e.g. that you aren't combining a solution to the first three
 balls that uses 1 with a solution to the last four balls that uses 1 - this
 step takes it down to about 900 possible answers). Then just filter on rules
 B and C to get the answer. I've got this running in about 160ms (though
 admittedly in Haskell).

 There's probably a name for this technique - constraint propagation? - but
 I'll leave it to the formally trained to comment. The slowest step is almost
 certainly discarding repeated solutions - that runs over 600,000 possible
 permutations and discards 599,000 of them - so if anyone has ideas on how to
 not generate so many duplicate numbers, that would be great.

 On 17/05/14 00:15, Brad Kurtz wrote:

 I have since fixed the original stack overflow error I was getting, it was a
 result of not using recur. However, I'm still trying to find the best way
 to actually iterate through the permutations to find the result...

 On Friday, May 16, 2014 2:31:26 PM UTC-5, Brad Kurtz wrote:

 I'm pretty new to Clojure so I'm trying out simple examples to see if I
 can get myself in the functional programming/Lisp mindset. My team lead
 sends out puzzles from his Mensa calendar, and every once in a while I find
 one that seems fun to solve as a Clojure program.

 With this particular puzzle, I've tried a couple of different ways of
 solving the puzzle, and I decided to try a recursive function. I'm fairly
 certain that what I've done here is not anywhere near ideal, and I'm looking
 for insight into how to better write this solution.

 Also, with my latest attempt I seem to be getting a stack overflow error,
 and I'm not quite sure why. I'm pretty sure it has to do with the
 permutation sequence (it's basically 10 factorial, or around 3 million
 sequences), but I don't really know how to better represent this problem in
 Clojure. Can anyone help? Thanks!

 https://github.com/bradkurtz/clojure-puzzles/tree/master/billiards

 --
 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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


 --
 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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

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

Looking for help with a Stack Overflow error

2014-05-16 Thread Brad Kurtz
I'm pretty new to Clojure so I'm trying out simple examples to see if I can 
get myself in the functional programming/Lisp mindset. My team lead sends 
out puzzles from his Mensa calendar, and every once in a while I find one 
that seems fun to solve as a Clojure program.

With this particular puzzle, I've tried a couple of different ways of 
solving the puzzle, and I decided to try a recursive function. I'm fairly 
certain that what I've done here is not anywhere near ideal, and I'm 
looking for insight into how to better write this solution.

Also, with my latest attempt I seem to be getting a stack overflow error, 
and I'm not quite sure why. I'm pretty sure it has to do with the 
permutation sequence (it's basically 10 factorial, or around 3 million 
sequences), but I don't really know how to better represent this problem in 
Clojure. Can anyone help? Thanks!

https://github.com/bradkurtz/clojure-puzzles/tree/master/billiards

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Looking for help with a Stack Overflow error

2014-05-16 Thread Brad Kurtz
I have since fixed the original stack overflow error I was getting, it was 
a result of not using recur. However, I'm still trying to find the best 
way to actually iterate through the permutations to find the result...

On Friday, May 16, 2014 2:31:26 PM UTC-5, Brad Kurtz wrote:

 I'm pretty new to Clojure so I'm trying out simple examples to see if I 
 can get myself in the functional programming/Lisp mindset. My team lead 
 sends out puzzles from his Mensa calendar, and every once in a while I find 
 one that seems fun to solve as a Clojure program.

 With this particular puzzle, I've tried a couple of different ways of 
 solving the puzzle, and I decided to try a recursive function. I'm fairly 
 certain that what I've done here is not anywhere near ideal, and I'm 
 looking for insight into how to better write this solution.

 Also, with my latest attempt I seem to be getting a stack overflow error, 
 and I'm not quite sure why. I'm pretty sure it has to do with the 
 permutation sequence (it's basically 10 factorial, or around 3 million 
 sequences), but I don't really know how to better represent this problem in 
 Clojure. Can anyone help? Thanks!

 https://github.com/bradkurtz/clojure-puzzles/tree/master/billiards


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Stack overflow deep in repl printer

2013-07-12 Thread David Goldfarb
Yes, I agree with you: better to bind outside the whole repl loop. I 
misspoke when I said around the printing.

That said, I think it might still be reasonable to put much tighter bounds 
on the cotents inside the printing of # ... .

David

On Thursday, July 11, 2013 3:09:07 PM UTC+3, Meikel Brandmeyer (kotarak) 
wrote:

 David,

 I wouldn't automatically set any values around the printing. The user 
 should be free to do what he likes.

 But the repl could start out with some sane defaults, which are not 
 limiting in the usual case, but safe in general. Like 50 for the level and 
 1000 for the length. Then you are not caught by the infitinite recursion, 
 but still can override the default should the need arise.

 Meikel



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




Stack overflow deep in repl printer

2013-07-11 Thread David Goldfarb
The following pathological case triggers a confusing stack overflow error.

*$ lein repl*
*...*
*user= (def x (atom nil))*
*#'user/x*
*user= (reset! x x)*
*
*
*StackOverflowError   java.util.regex.Pattern$Curly.match 
(Pattern.java:4125)*
*
*
*;;; Of course, I can avoid the problem:*
*user= (set! *print-level* 3)*
*3*
*user= (reset! x x)*
*#Atom@4d98da: #Atom@4d98da: #Atom@4d98da: #*



Would it be reasonable for the repl to wrap a safe *print-level* and 
*print-length* around the printing?  100, or even 500, would probably never 
stack-overflow, and would be more reasonable behavior for most users.

Even if this is not reasonable in general, perhaps it would still make 
sense around the printing of any # ... entity, where the internal text 
is always just for human consumption.


-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Stack overflow deep in repl printer

2013-07-11 Thread Meikel Brandmeyer (kotarak)
David,

I wouldn't automatically set any values around the printing. The user 
should be free to do what he likes.

But the repl could start out with some sane defaults, which are not 
limiting in the usual case, but safe in general. Like 50 for the level and 
1000 for the length. Then you are not caught by the infitinite recursion, 
but still can override the default should the need arise.

Meikel

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




Will this cause stack overflow?

2012-08-29 Thread Erlis Vidal
Hi group,

Will this recursion cause stack overflow?

(defn my-flatten [x]
  (if (coll? x) (mapcat my-flatten x) [x]))

If yes, how can I do a recursive call when passing the function as a
parameter to another function, like in this case with mapcat?

Thanks,
Erlis

-- 
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: Will this cause stack overflow?

2012-08-29 Thread Ben Wolfson
Yes:

user (defn my-flatten [x]
  (if (coll? x) (mapcat my-flatten x) [x]))
#'user/my-flatten
user (my-flatten (take 4000 (iterate vector [])))

(stack overflow)

On Wed, Aug 29, 2012 at 2:03 PM, Erlis Vidal er...@erlisvidal.com wrote:
 Hi group,

 Will this recursion cause stack overflow?

 (defn my-flatten [x]
   (if (coll? x) (mapcat my-flatten x) [x]))

 If yes, how can I do a recursive call when passing the function as a
 parameter to another function, like in this case with mapcat?

 Thanks,
 Erlis

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



-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks,
which may be sweet, aromatic, fermented or spirit-based. ... Family
and social life also offer numerous other occasions to consume drinks
for pleasure. [Larousse, Drink entry]

-- 
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: Will this cause stack overflow?

2012-08-29 Thread Nate Young
On Wed, Aug 29, 2012 at 4:03 PM, Erlis Vidal er...@erlisvidal.com wrote:
 If yes, how can I do a recursive call when passing the function as a
 parameter to another function, like in this case with mapcat?
You could use `lazy-seq`. Something like this:

(defn my-flatten [x]
  (lazy-seq
(if (coll? x)
  (mapcat my-flatten x)
  [x])))

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


Iterate and stack overflow

2012-06-14 Thread vmargioulas
Can someone explain why
... iterating over a sequence cause a stack overflow
(first (drop 1000 (iterate (partial map inc) (range 10 -
java.lang.StackOverflowError

...but iterating over a vector works ok?
(first (drop 1000 (iterate (comp vec (partial map inc)) (range 10 -
 [1000 1001 1002 1003 1004 1005 1006 1007 1008 1009]

-- 
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: Iterate and stack overflow

2012-06-14 Thread Dave Sann
It doesn't overflow for me.


user= (first (drop 1000 (iterate (partial map inc) (range 10
(1000 1001 1002 1003 1004 1005 1006 1007 1008 1009)


On Thursday, 14 June 2012 22:52:33 UTC+10, vmargioulas wrote:

 Can someone explain why 
 ... iterating over a sequence cause a stack overflow 
 (first (drop 1000 (iterate (partial map inc) (range 10 - 
 java.lang.StackOverflowError 

 ...but iterating over a vector works ok? 
 (first (drop 1000 (iterate (comp vec (partial map inc)) (range 10 - 
  [1000 1001 1002 1003 1004 1005 1006 1007 1008 1009] 


-- 
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: Iterate and stack overflow

2012-06-14 Thread Dave Sann
ah...but does for 1


On Thursday, 14 June 2012 22:58:58 UTC+10, Dave Sann wrote:

 It doesn't overflow for me.


 user= (first (drop 1000 (iterate (partial map inc) (range 10
 (1000 1001 1002 1003 1004 1005 1006 1007 1008 1009)


 On Thursday, 14 June 2012 22:52:33 UTC+10, vmargioulas wrote:

 Can someone explain why 
 ... iterating over a sequence cause a stack overflow 
 (first (drop 1000 (iterate (partial map inc) (range 10 - 
 java.lang.StackOverflowError 

 ...but iterating over a vector works ok? 
 (first (drop 1000 (iterate (comp vec (partial map inc)) (range 10 - 
  [1000 1001 1002 1003 1004 1005 1006 1007 1008 1009] 



-- 
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: Iterate and stack overflow

2012-06-14 Thread Dave Sann
I suspect that the answer is the use of partial and the implementation of 
iterate

with (comp vec... you force realisation of the vector

without this I think you get (partial map (partial map (partial ) as f 
is repeatedly applied

if you do this,

(first (drop 10 (iterate #(apply list (map inc %)) (range 10

which forces the list to be realised, it wont overflow

D


On Thursday, 14 June 2012 23:00:15 UTC+10, Dave Sann wrote:

 ah...but does for 1


 On Thursday, 14 June 2012 22:58:58 UTC+10, Dave Sann wrote:

 It doesn't overflow for me.


 user= (first (drop 1000 (iterate (partial map inc) (range 10
 (1000 1001 1002 1003 1004 1005 1006 1007 1008 1009)


 On Thursday, 14 June 2012 22:52:33 UTC+10, vmargioulas wrote:

 Can someone explain why 
 ... iterating over a sequence cause a stack overflow 
 (first (drop 1000 (iterate (partial map inc) (range 10 - 
 java.lang.StackOverflowError 

 ...but iterating over a vector works ok? 
 (first (drop 1000 (iterate (comp vec (partial map inc)) (range 10 - 
  [1000 1001 1002 1003 1004 1005 1006 1007 1008 1009] 



-- 
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: Iterate and stack overflow

2012-06-14 Thread Dave Sann
also

 (first (drop 10 (iterate #(doall (map inc %)) (range 10

so the better answer is probably - because map is lazy


On Thursday, 14 June 2012 23:06:27 UTC+10, Dave Sann wrote:

 I suspect that the answer is the use of partial and the implementation of 
 iterate

 with (comp vec... you force realisation of the vector

 without this I think you get (partial map (partial map (partial ) as f 
 is repeatedly applied

 if you do this,

 (first (drop 10 (iterate #(apply list (map inc %)) (range 10

 which forces the list to be realised, it wont overflow

 D


 On Thursday, 14 June 2012 23:00:15 UTC+10, Dave Sann wrote:

 ah...but does for 1


 On Thursday, 14 June 2012 22:58:58 UTC+10, Dave Sann wrote:

 It doesn't overflow for me.


 user= (first (drop 1000 (iterate (partial map inc) (range 10
 (1000 1001 1002 1003 1004 1005 1006 1007 1008 1009)


 On Thursday, 14 June 2012 22:52:33 UTC+10, vmargioulas wrote:

 Can someone explain why 
 ... iterating over a sequence cause a stack overflow 
 (first (drop 1000 (iterate (partial map inc) (range 10 - 
 java.lang.StackOverflowError 

 ...but iterating over a vector works ok? 
 (first (drop 1000 (iterate (comp vec (partial map inc)) (range 10 - 
  [1000 1001 1002 1003 1004 1005 1006 1007 1008 1009] 



-- 
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: Iterate and stack overflow

2012-06-14 Thread vmargioulas
Thanks, this explains the stack overflow

On Thursday, June 14, 2012 4:12:28 PM UTC+3, Dave Sann wrote:

 also

  (first (drop 10 (iterate #(doall (map inc %)) (range 10

 so the better answer is probably - because map is lazy


 On Thursday, 14 June 2012 23:06:27 UTC+10, Dave Sann wrote:

 I suspect that the answer is the use of partial and the implementation of 
 iterate

 with (comp vec... you force realisation of the vector

 without this I think you get (partial map (partial map (partial ) as 
 f is repeatedly applied

 if you do this,

 (first (drop 10 (iterate #(apply list (map inc %)) (range 10

 which forces the list to be realised, it wont overflow

 D


 On Thursday, 14 June 2012 23:00:15 UTC+10, Dave Sann wrote:

 ah...but does for 1


 On Thursday, 14 June 2012 22:58:58 UTC+10, Dave Sann wrote:

 It doesn't overflow for me.


 user= (first (drop 1000 (iterate (partial map inc) (range 10
 (1000 1001 1002 1003 1004 1005 1006 1007 1008 1009)


 On Thursday, 14 June 2012 22:52:33 UTC+10, vmargioulas wrote:

 Can someone explain why 
 ... iterating over a sequence cause a stack overflow 
 (first (drop 1000 (iterate (partial map inc) (range 10 - 
 java.lang.StackOverflowError 

 ...but iterating over a vector works ok? 
 (first (drop 1000 (iterate (comp vec (partial map inc)) (range 10 
 - 
  [1000 1001 1002 1003 1004 1005 1006 1007 1008 1009] 



-- 
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: stack overflow vs scheme

2011-12-02 Thread Nils Bertschinger
Hi,

the Scheme version of quicksort is not tail-recursive since append is
called on the return value of the recursive calls. Thus, also in
Scheme this eats up your stack. That your Scheme code can sort larger
sequences simple means that your Scheme implementation has a larger
stack than the JVM with standard settings.
Basically, the only difference between Scheme and Clojure with respect
to tail-recursion is that Scheme automatically optimizes the recursive
call when it appears in a tail-call position whereas in Clojure you
have to explicitly call recur (or trampoline for mutual recursion) if
you want tail-call optimization.

Since quicksort requires two recursive calls which then have to be
combined it is not completely trivial to implement it in a tail-
recursive, i.e. iterative, fashion. There is a general method which
can be applied, namely continuation passing style (CPS), but it might
look a little odd if you haven't seen it before. Basically, you use a
variable holding a chain of closures which resemble the stack. I found
a rather nice exposition in this blog post:
http://www.enrico-franchi.org/2011/09/clojure-quicksort-in-continuation.html

Cheers,

Nils

On Dec 1, 6:09 pm, john.holland jbholl...@gmail.com wrote:
 I was studying clojure for a while, and took a break to work on SICP in
 scheme. I found that they do numerous things that are against advice in
 Clojure having to do with the tail recursion.
 I got to thinking about that Clojure recur/loop stuff and wondered how you
 would do a quicksort with it. So I went to rosetta code and looked at what
 they had for scheme and for clojure.

 In scheme I can do a quicksort which makes two calls to itself and it can
 scale pretty high before running out of RAM.  I went up to 1 sorting
 from worst (reversed) order to forward order. I do get
 stack overflows beyond that though.

 In clojure, the same algorithm produces the dreaded StackOverflow after
 1000 values.
 I tried giving the JVM a gig of RAM, no help.

 Below are the (trvial) procedures.

 I understand that the advice in clojure is to use loop/recur etc, however,
 a big part of the charm for me of something like scheme is that I can write
 code that is a straightforward statement of a mathematical approach to the
 problem.

 Although quicksort is really simple, the idea of doing it with loop/recur
 baffles me.

 After a while with the scheme stuff clojure seems very complex and this,
 which seems like a fundamental issue, is not going well for it.

 Can anyone post a quicksort that doesn't give stack overflows in clojure?

 John

 scheme quicksort

  (define (quicksort l)
 (if (null? l)
     '()
     (append (quicksort (filter (lambda (x) ( (car l) x)) (cdr l)) )
             (list (car l))
             (quicksort (filter (lambda (x) ( (car l) x)) (cdr l)) 

 =scheme utility to make data sets
 (define (nums x) (if ( x 0) '() (cons x (nums (- x 1)

 ==scheme call=
 (quicksort  (nums 1))

 ===clojure quicksort
  (defn qsort [[pivot  xs]]
   (when pivot
  (let [smaller #( % pivot)]
  (lazy-cat (qsort (filter smaller xs))
   [pivot]
     (qsort (remove smaller xs))

 =clojure utility to make data sets
 (def nums (fn [lim] (loop [limx lim acc []] (if ( limx 0) acc (recur (-
 limx 1) (cons limx acc)) 

 clojure call==
 (quicksort  (nums 1))

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


Re: stack overflow vs scheme

2011-12-02 Thread john.holland
Thanks for all the replies. It seems to me that as  general solutions to 
stack overflow, trampoline and recur are
very valuable. I had gotten the mistaken idea that Scheme was somehow 
immune to the problem.
 My experiments in Scheme seemed to get to higher amounts of recursion 
before blowing up than my Clojure did,
but they are both susceptible to it. Are there things like trampoline and 
recur in Scheme? In Lisp?

John Holland

-- 
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: stack overflow vs scheme

2011-12-02 Thread Nils Bertschinger


On Dec 2, 8:13 pm, john.holland jbholl...@gmail.com wrote:
 Thanks for all the replies. It seems to me that as  general solutions to
 stack overflow, trampoline and recur are
 very valuable. I had gotten the mistaken idea that Scheme was somehow
 immune to the problem.
  My experiments in Scheme seemed to get to higher amounts of recursion
 before blowing up than my Clojure did,
 but they are both susceptible to it. Are there things like trampoline and
 recur in Scheme? In Lisp?
Well yes, but they are not explicitly specified since Scheme
automatically optimizes tail calls. Consider this example:
(define (fact n)
   (if ( n 2)
  1
  (* n (fact (- n 1)
This is not tail recursive and eventually blows the stack ... in
Scheme and in Clojure.
(define (fact-accu n res)
   (if ( n 2)
  res
  (fact-accu (- n 1) (* n res
Here, the recursive call is in tail position and gets optimized by the
Scheme compiler. In Clojure you would have to call recur instead,
otherwise your stack grows. In Scheme this is not necessary since the
optimization is always done if possible. Thus, there is no special
syntactic marker, i.e. reserved word, for this. (Same holds for mutual
recursion - trampoline).
In Common Lisp the situation is somewhat unfortunate, since tail call
optimization is implementation dependent. So, you cannot rely on it
and therefore loop/tagbody etc are your friends there.

Hope this helps,

Nils

 John Holland

-- 
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: stack overflow vs scheme

2011-12-02 Thread Peter Danenberg
Quoth john.holland on Sweetmorn, the 44th of The Aftermath:
 It seems to me that as general solutions to stack overflow,
 trampoline and recur are very valuable. I had gotten the mistaken
 idea that Scheme was somehow immune to the problem.

Trampoline and recur are a poor man's tail-call-optimization; and, if
by the problem, you mean that a call-stack grows linearly with its
recursive depth: yeah, even Scheme is susceptible to stack-growth if
your calls aren't properly tail-recursive.

See R5RS s. 3.5 [1], Proper tail recursion:

  A tail call is a procedure call that occurs in a tail context;
  e.g. the last expression within the body of a lambda expression.

William Clinger wrote a paper that formalizes proper tail recursion in
more depth [2].

Suffice to say, the naïve recursive implementation of quick sort
contains at least one non-tail-call; and, just for kicks, here's an
implementation of quicksort in Joy (a so-called concatenative
language):

  [small] [] [uncons [] split] [swapd cons concat] binrec

Joy, too, implements recursion (through `binrec') without growing the
call-stack.

Footnotes: 
[1]  
http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-6.html#%_sec_3.5
[2]  ftp://ftp.ccs.neu.edu/pub/people/will/tail.pdf

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


stack overflow vs scheme

2011-12-01 Thread john.holland
I was studying clojure for a while, and took a break to work on SICP in 
scheme. I found that they do numerous things that are against advice in 
Clojure having to do with the tail recursion.
I got to thinking about that Clojure recur/loop stuff and wondered how you 
would do a quicksort with it. So I went to rosetta code and looked at what 
they had for scheme and for clojure.


In scheme I can do a quicksort which makes two calls to itself and it can 
scale pretty high before running out of RAM.  I went up to 1 sorting 
from worst (reversed) order to forward order. I do get 
stack overflows beyond that though.

In clojure, the same algorithm produces the dreaded StackOverflow after 
1000 values.
I tried giving the JVM a gig of RAM, no help. 

Below are the (trvial) procedures.

I understand that the advice in clojure is to use loop/recur etc, however, 
a big part of the charm for me of something like scheme is that I can write 
code that is a straightforward statement of a mathematical approach to the 
problem.


Although quicksort is really simple, the idea of doing it with loop/recur 
baffles me.  

After a while with the scheme stuff clojure seems very complex and this, 
which seems like a fundamental issue, is not going well for it.

Can anyone post a quicksort that doesn't give stack overflows in clojure?

John

scheme quicksort

 (define (quicksort l)
(if (null? l)
'()
(append (quicksort (filter (lambda (x) ( (car l) x)) (cdr l)) )
(list (car l))
(quicksort (filter (lambda (x) ( (car l) x)) (cdr l)) 

=scheme utility to make data sets
(define (nums x) (if ( x 0) '() (cons x (nums (- x 1)

==scheme call=
(quicksort  (nums 1))

===clojure quicksort
 (defn qsort [[pivot  xs]]
  (when pivot
 (let [smaller #( % pivot)]
 (lazy-cat (qsort (filter smaller xs))
  [pivot]
(qsort (remove smaller xs))

=clojure utility to make data sets
(def nums (fn [lim] (loop [limx lim acc []] (if ( limx 0) acc (recur (- 
limx 1) (cons limx acc)) 

clojure call==
(quicksort  (nums 1))

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

Re: stack overflow vs scheme

2011-12-01 Thread David Nolen
If you run out stack in Scheme the code is not properly tail recursive. Who
care when it blows?

On Thu, Dec 1, 2011 at 12:09 PM, john.holland jbholl...@gmail.com wrote:

 I was studying clojure for a while, and took a break to work on SICP in
 scheme. I found that they do numerous things that are against advice in
 Clojure having to do with the tail recursion.
 I got to thinking about that Clojure recur/loop stuff and wondered how you
 would do a quicksort with it. So I went to rosetta code and looked at what
 they had for scheme and for clojure.


 In scheme I can do a quicksort which makes two calls to itself and it can
 scale pretty high before running out of RAM.  I went up to 1 sorting
 from worst (reversed) order to forward order. I do get
 stack overflows beyond that though.

 In clojure, the same algorithm produces the dreaded StackOverflow after
 1000 values.
 I tried giving the JVM a gig of RAM, no help.

 Below are the (trvial) procedures.

 I understand that the advice in clojure is to use loop/recur etc, however,
 a big part of the charm for me of something like scheme is that I can write
 code that is a straightforward statement of a mathematical approach to the
 problem.


 Although quicksort is really simple, the idea of doing it with loop/recur
 baffles me.

 After a while with the scheme stuff clojure seems very complex and this,
 which seems like a fundamental issue, is not going well for it.

 Can anyone post a quicksort that doesn't give stack overflows in clojure?

 John

 scheme quicksort

  (define (quicksort l)
 (if (null? l)
 '()
 (append (quicksort (filter (lambda (x) ( (car l) x)) (cdr l)) )
 (list (car l))
 (quicksort (filter (lambda (x) ( (car l) x)) (cdr l)) 

 =scheme utility to make data sets
 (define (nums x) (if ( x 0) '() (cons x (nums (- x 1)

 ==scheme call=
 (quicksort  (nums 1))

 ===clojure quicksort
  (defn qsort [[pivot  xs]]
   (when pivot
  (let [smaller #( % pivot)]
  (lazy-cat (qsort (filter smaller xs))
   [pivot]
 (qsort (remove smaller xs))

 =clojure utility to make data sets
 (def nums (fn [lim] (loop [limx lim acc []] (if ( limx 0) acc (recur (-
 limx 1) (cons limx acc)) 

 clojure call==
 (quicksort  (nums 1))

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

-- 
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: stack overflow vs scheme

2011-12-01 Thread David Nolen
I didn't mean the response to sound overly curt. You can set the stack size
on JVM.

But the point is, that quick sort is simply wrong if you do not want to
grow the stack, whether in Scheme or in Clojure.

On Thu, Dec 1, 2011 at 5:07 PM, David Nolen dnolen.li...@gmail.com wrote:

 If you run out stack in Scheme the code is not properly tail recursive.
 Who care when it blows?


 On Thu, Dec 1, 2011 at 12:09 PM, john.holland jbholl...@gmail.com wrote:

 I was studying clojure for a while, and took a break to work on SICP in
 scheme. I found that they do numerous things that are against advice in
 Clojure having to do with the tail recursion.
 I got to thinking about that Clojure recur/loop stuff and wondered how
 you would do a quicksort with it. So I went to rosetta code and looked at
 what they had for scheme and for clojure.


 In scheme I can do a quicksort which makes two calls to itself and it can
 scale pretty high before running out of RAM.  I went up to 1 sorting
 from worst (reversed) order to forward order. I do get
 stack overflows beyond that though.

 In clojure, the same algorithm produces the dreaded StackOverflow after
 1000 values.
 I tried giving the JVM a gig of RAM, no help.

 Below are the (trvial) procedures.

 I understand that the advice in clojure is to use loop/recur etc,
 however, a big part of the charm for me of something like scheme is that I
 can write code that is a straightforward statement of a mathematical
 approach to the problem.


 Although quicksort is really simple, the idea of doing it with loop/recur
 baffles me.

 After a while with the scheme stuff clojure seems very complex and this,
 which seems like a fundamental issue, is not going well for it.

 Can anyone post a quicksort that doesn't give stack overflows in clojure?

 John

 scheme quicksort

  (define (quicksort l)
 (if (null? l)
 '()
 (append (quicksort (filter (lambda (x) ( (car l) x)) (cdr l)) )
 (list (car l))
 (quicksort (filter (lambda (x) ( (car l) x)) (cdr l)) 

 =scheme utility to make data sets
 (define (nums x) (if ( x 0) '() (cons x (nums (- x 1)

 ==scheme call=
 (quicksort  (nums 1))

 ===clojure quicksort
  (defn qsort [[pivot  xs]]
   (when pivot
  (let [smaller #( % pivot)]
  (lazy-cat (qsort (filter smaller xs))
   [pivot]
 (qsort (remove smaller xs))

 =clojure utility to make data sets
 (def nums (fn [lim] (loop [limx lim acc []] (if ( limx 0) acc (recur (-
 limx 1) (cons limx acc)) 

 clojure call==
 (quicksort  (nums 1))

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




-- 
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: stack overflow vs scheme

2011-12-01 Thread Michael Gardner
Try increasing the JVM's stack size with -Xss.

-- 
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: stack overflow vs scheme

2011-12-01 Thread Stuart Sierra
There are versions of Quicksort that don't use recursive function calls. 
Instead they simulate recursion by maintaining a stack of indices. (Search 
the web for quicksort without recursion.) You could do that in Clojure 
with loop/recur. 

-S

-- 
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: stack overflow vs scheme

2011-12-01 Thread Mark Engelberg
Here's the simplest way to adapt your code so that it won't blow the
stack.  Just shuffle the input list first:

(defn quicksort [l]
  (letfn [(qsort [[pivot  xs]]
 (when pivot
   (let [smaller #( % pivot)]
 (lazy-cat (qsort (filter smaller xs))
   [pivot]
   (qsort (remove smaller xs))]
 (qsort (shuffle l

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


Recursive sieve of eratosthenes, stack overflow

2011-05-18 Thread Szymon Ząbkiewicz
Hello,
I'm trying to learn Clojure so I'm making some simple programs. One of
them is prime sieve which looks like this:

(defn filter-primes [nums]
  Leave only numbers not divisable by the first element in the list
  (filter (fn [x] (not= 0 (mod x (first nums (rest nums)))

(defn sieve [max-num]
  Calculate all primes between 1 and max-num inclusive
  (loop [nums (range 2 (inc max-num))
 primes (list)]
(if (empty? nums)
  (reverse primes)
  (recur (filter-primes nums) (conj primes (first nums))

The problem is that calling for example (sieve 1) already twrows
StackOverflowError, which is kind of suprising to me, because I use
the loop...recure. I'm not looking for an anwser with a totally
different approach, but how to make this recursive approach work.


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


Aw: Recursive sieve of eratosthenes, stack overflow

2011-05-18 Thread Meikel Brandmeyer
Hi,

you pile lazy seq on lazy seq on lazy seq on lazy seq ... Realizing this 
causes the stackoverflow. One possible remedy would be to wrap the filter in 
filter-primes in a doall.

Sincerely
Meikel

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

Re: Recursive sieve of eratosthenes, stack overflow

2011-05-18 Thread Alan Malloy
This is a pretty common question.
http://stackoverflow.com/questions/2946764/recursive-function-causing-a-stack-overflow
is one instance that's been answered fairly thoroughly; does it help
you?

On May 18, 3:10 am, Szymon Ząbkiewicz sz.zabkiew...@gmail.com wrote:
 Hello,
 I'm trying to learn Clojure so I'm making some simple programs. One of
 them is prime sieve which looks like this:

 (defn filter-primes [nums]
   Leave only numbers not divisable by the first element in the list
   (filter (fn [x] (not= 0 (mod x (first nums (rest nums)))

 (defn sieve [max-num]
   Calculate all primes between 1 and max-num inclusive
   (loop [nums (range 2 (inc max-num))
          primes (list)]
     (if (empty? nums)
       (reverse primes)
       (recur (filter-primes nums) (conj primes (first nums))

 The problem is that calling for example (sieve 1) already twrows
 StackOverflowError, which is kind of suprising to me, because I use
 the loop...recure. I'm not looking for an anwser with a totally
 different approach, but how to make this recursive approach work.

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


loop/recur stack overflow

2010-08-28 Thread neveu
I implemented the Flavius Josephus algorithm from Programming Praxis
in Clojure using loop/recur. My first version looked like this:

(defn rotate-left
  ([ln n m]
 (take n (drop (dec m) (cycle ln
  ([ln m] (rotate-left ln (count ln) m)))

(defn josephus3 [N M] ;; execute every mth soldier
  (loop [soldiers (range N)
 m M
 deceased '()]
(let [n (count soldiers)]
  (cond
 (zero? n) deceased
 true (let [r (rotate-left soldiers n m)
dead (cons (first r) deceased)
survivors (rest r)]
(recur survivors m dead))

This works fine, but I don't really need to count the soldiers every
pass, it always decreases by 1. So I wrote this version in which n is
one of the loop parameters:

(defn josephus4 [N M] ;; execute every mth soldier
  (loop [soldiers (range N)
 n N
 m M
 deceased '()]
(cond
 (zero? n) deceased
 true (let [r (rotate-left soldiers n m)
dead (cons (first r) deceased)
survivors (rest r)]
(recur survivors (dec n)  m dead)

Both work for small N (e.g. 41) but the second one fails for large
(41000) N with a stack overflow.
What am I missing here?

Thanks,
Charles

-- 
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 tag wiki on Stack Overflow

2010-07-22 Thread Michał Marczyk
Hi All,

Stack Overflow has recently introduced a new concept of tag wikis.
Here's the one for Clojure:

http://stackoverflow.com/questions/tagged?sort=infotagnames=clojure

I thought it would be useful to put a general notice about what
Clojure is and which resources might be most helpful to beginners up
there, so I've just edited a basic summary and some links. I'm sure
this can be improved upon, so -- any suggestions? :-)

There is a 100 upvotes on non-community wiki answers in the tag
requirement for editing the tag wiki; I will happily edit in any good
suggestions from interested parties who do not meet this criterion.
Better yet, let's reach a consensus on the ideal shape of our SO tag
wiki first, then someone with enough Clojure answer rep can edit it
in.

As an example, so far the only really fleshed out tag wiki that I've
seen is Python's [1].

All the best,
Michał


[1] 
http://stackoverflow.com/questions/tagged?tagnames=pythonsort=infopagesize=15

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


Stack overflow while processing XML

2009-11-18 Thread mkrajnak
I am processing a very large xml file, 13MB, using clojure.xml.parse
and clojure.contrib.zip-filter.xml with clojure 1.0.0.

The xml file contains information on 13000 japanese characters and I'm
extracting about 200 or so.

At its core it extracts a very small subset of elements using:

(xml- kdic :character [:literal #(contains? kcset (text %))] node)

Where kcset is a set of desired characters.

My understanding of this is that it returns a lazy-seq which if I
count-ed the length of the sequence it would return 200 (not
13000).  But in practice it actually generates a stack overflow.

At the end of this post I have a relatively short version of the
program which throws the stack overflow.  In this case it has a
(count ...) call which causes the stack overflow.  In the full program
I tried a few variations like so:

(dorun (for [knode knodes] (print-kinfo knode

To try to get the information to print, but before it also reaches the
end of list it also throws a stack overflow.

I also have the stack trace at the end as well.

Thanks!


Here's the short version of the program:

(ns kanji.prkanji
(:use clojure.xml )
(:use [clojure.zip :only (xml-zip node)])
(:use clojure.contrib.zip-filter.xml)
(:import java.lang.Character$UnicodeBlock)
(:import java.io.File))

(def CJK Character$UnicodeBlock/CJK_UNIFIED_IDEOGRAPHS)

(defn filter-for-kanji
[chars]
(filter #(= CJK (Character$UnicodeBlock/of %)) chars))

(defn get-unique-kanji
[chars]
(let [kchars (filter-for-kanji chars)]
 (set kchars)))

(defn print-kinfos
[knodes]
(count knodes))
;; this is what I would normally do: (dorun (for [knode knodes] (print-
kinfo knode

(defn get-kdic-info
[kdic kchars]
(let [kcset (set (map str kchars))]
(xml- kdic :character [:literal #(contains? kcset (text %))]
node)))

(defn load-kdic
[fname]
(xml-zip (parse (File. fname

(defn process-file
[file]
(let [kchars (get-unique-kanji (slurp file))]
(print-kinfos
(get-kdic-info
(load-kdic kanji/kdic-data.xml) kchars

(process-file (second *command-line-args*))

And here's the top of the stack trace:

Exception in thread main java.lang.StackOverflowError (prkanji.clj:
0)
at clojure.lang.Compiler.eval(Compiler.java:4543)
at clojure.lang.Compiler.load(Compiler.java:4857)
at clojure.lang.Compiler.loadFile(Compiler.java:4824)
at clojure.main$load_script__5833.invoke(main.clj:206)
at clojure.main$init_opt__5836.invoke(main.clj:211)
at clojure.main$initialize__5846.invoke(main.clj:239)
at clojure.main$null_opt__5868.invoke(main.clj:264)
at clojure.main$legacy_script__5883.invoke(main.clj:295)
at clojure.lang.Var.invoke(Var.java:346)
at clojure.main.legacy_script(main.java:34)
at clojure.lang.Script.main(Script.java:20)
Caused by: java.lang.StackOverflowError
at clojure.lang.Cons.next(Cons.java:37)
at clojure.lang.RT.boundedLength(RT.java:1117)
at clojure.lang.AFn.applyToHelper(AFn.java:168)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply__3243.doInvoke(core.clj:390)
at clojure.lang.RestFn.invoke(RestFn.java:443)
at clojure.core$mapcat__3842.doInvoke(core.clj:1528)
at clojure.lang.RestFn.invoke(RestFn.java:428)
at clojure.contrib.zip_filter$descendants__48$fn__50.invoke
(zip_filter.clj:63)
at clojure.lang.LazySeq.seq(LazySeq.java:41)
at clojure.lang.RT.seq(RT.java:436)
at clojure.lang.LazySeq.seq(LazySeq.java:41)
at clojure.lang.RT.seq(RT.java:436)
at clojure.core$seq__3133.invoke(core.clj:103)
at clojure.core$map__3815$fn__3817.invoke(core.clj:1502)
at clojure.lang.LazySeq.seq(LazySeq.java:41)
at clojure.lang.Cons.next(Cons.java:37)
at clojure.lang.RT.boundedLength(RT.java:1117)
at clojure.lang.RestFn.applyTo(RestFn.java:135)
at clojure.core$apply__3243.doInvoke(core.clj:390)
at clojure.lang.RestFn.invoke(RestFn.java:428)
at clojure.core$mapcat__3842.doInvoke(core.clj:1528)
at clojure.lang.RestFn.invoke(RestFn.java:428)
at clojure.contrib.zip_filter$mapcat_chain__65$fn__67.invoke
(zip_filter.clj:88)
at clojure.lang.ArraySeq.reduce(ArraySeq.java:116)
at clojure.core$reduce__3319.invoke(core.clj:536)
at clojure.contrib.zip_filter$mapcat_chain__65.invoke(zip_filter.clj:
89)
at clojure.contrib.zip_filter.xml$xml__GT___119.doInvoke(xml.clj:75)
at clojure.lang.RestFn.invoke(RestFn.java:460)
at clojure.contrib.zip_filter.xml$text__102.invoke(xml.clj:43)
at kanji.prkanji$get_kdic_info__147$fn__149.invoke(prkanji.clj:36)
at clojure.contrib.zip_filter$fixup_apply__60.invoke(zip_filter.clj:
76)
at clojure.contrib.zip_filter$mapcat_chain__65$fn__67$fn__69.invoke
(zip_filter.clj:88

Re: Stack overflow while processing XML

2009-11-18 Thread Alex Osborne
mkrajnak wrote:
 I am processing a very large xml file, 13MB, using clojure.xml.parse
 and clojure.contrib.zip-filter.xml with clojure 1.0.0.

clojure.xml.parse loads the whole document into memory at once so it's 
only really suitable for small (at most a megabyte or two) XML 
documents.  Have a look at something like Xom instead:

http://www.xom.nu/

If you're looking for an example of usage from Clojure, Mark Triggs has 
a nifty wrapper for Xom that efficiently turns an XML document into a 
lazy-seq (using a queue) which he routinely uses on multi-gigabyte XML 
files:

http://github.com/marktriggs/xml-picker-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


Re: Stack Overflow problem with Maps

2009-04-28 Thread Christophe Grand
  (rest inner-array)
   (cons (.split (first 
 inner-array) ,) inner-list)
   )
   )
   )
 )

 (defn process-row-data-file [inp-key-names-list]
   (with-open [rdr (reader my-row-data-file)]
   (loop [inner-row-data (line-seq rdr) my-inner-map {}]
   (cond
   (= (count inner-row-data) 0) my-inner-map
   :else
   (recur  (rest inner-row-data)
   
 (update-map-list my-inner-map
   
 (produce-date-rn-array 
 (process-row-str (first inner-
 row-data)))
   
 (process-row-str (first 
 inner-row-data))
   
 inp-key-names-list
   )
   )
   )
   )
   )
 )





 On Apr 27, 9:34 pm, Dimiter \malkia\ Stanev mal...@gmail.com
 wrote:
   
 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:http://groups.google.com/group/clojure/browse_frm/thread/43f9a716f1f9...

 Also check whether you don't have recursive functions (replace them
 with loop/recur), or mutually recursive ones (for them, you would have
 to use mutual exclusion). But I doubt that was the problem, more
 likely the default lazy mode of clojure, and what Cristophe was
 talking about is probably connected to your problem.

 On Apr 27, 1: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 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 corresponding
 actual value.
   
 I define a headingnamelist which is a list of headings to be used to
 generate the keys.
   
 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 from the Actual Info List and use this as part of my key.
 With the key i write the Row Number to the map. If the key is already
 there i just cons it to the exiting map value.
   
 As i said it is quite a large list and i keep getting a stack
 overflow. For comparison purposes i ran a similar program in python
 and it ran in a matter of seconds.
   
 Has anybody any ideas why this is happening?
   
 tks,
 PJ
   
 

   


-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (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
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
-~--~~~~--~~--~--~---



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 corresponding
actual value.

I define a headingnamelist which is a list of headings to be used to
generate the keys.

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 from the Actual Info List and use this as part of my key.
With the key i write the Row Number to the map. If the key is already
there i just cons it to the exiting map value.

As i said it is quite a large list and i keep getting a stack
overflow. For comparison purposes i ran a similar program in python
and it ran in a matter of seconds.

Has anybody any ideas why this is happening?

tks,
PJ
--~--~-~--~~~---~--~~
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
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: 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 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 corresponding
 actual value.

 I define a headingnamelist which is a list of headings to be used to
 generate the keys.

 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 from the Actual Info List and use this as part of my key.
 With the key i write the Row Number to the map. If the key is already
 there i just cons it to the exiting map value.

 As i said it is quite a large list and i keep getting a stack
 overflow. For comparison purposes i ran a similar program in python
 and it ran in a matter of seconds.

 Has anybody any ideas why this is happening?

 tks,
 PJ
 


--~--~-~--~~~---~--~~
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
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: 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:
http://groups.google.com/group/clojure/browse_frm/thread/43f9a716f1f91f5d#

Also check whether you don't have recursive functions (replace them
with loop/recur), or mutually recursive ones (for them, you would have
to use mutual exclusion). But I doubt that was the problem, more
likely the default lazy mode of clojure, and what Cristophe was
talking about is probably connected to your problem.


On Apr 27, 1: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 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 corresponding
 actual value.

 I define a headingnamelist which is a list of headings to be used to
 generate the keys.

 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 from the Actual Info List and use this as part of my key.
 With the key i write the Row Number to the map. If the key is already
 there i just cons it to the exiting map value.

 As i said it is quite a large list and i keep getting a stack
 overflow. For comparison purposes i ran a similar program in python
 and it ran in a matter of seconds.

 Has anybody any ideas why this is happening?

 tks,
 PJ
--~--~-~--~~~---~--~~
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
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: Stack Overflow problem with Maps

2009-04-27 Thread pjfitz
/browse_frm/thread/43f9a716f1f9...

 Also check whether you don't have recursive functions (replace them
 with loop/recur), or mutually recursive ones (for them, you would have
 to use mutual exclusion). But I doubt that was the problem, more
 likely the default lazy mode of clojure, and what Cristophe was
 talking about is probably connected to your problem.

 On Apr 27, 1: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 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 corresponding
  actual value.

  I define a headingnamelist which is a list of headings to be used to
  generate the keys.

  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 from the Actual Info List and use this as part of my key.
  With the key i write the Row Number to the map. If the key is already
  there i just cons it to the exiting map value.

  As i said it is quite a large list and i keep getting a stack
  overflow. For comparison purposes i ran a similar program in python
  and it ran in a matter of seconds.

  Has anybody any ideas why this is happening?

  tks,
  PJ
--~--~-~--~~~---~--~~
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
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: 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 from the Actual Info List and use this as part of my key.
 With the key i write the Row Number to the map. If the key is already
 there i just cons it to the exiting map value.
   

Code smell: indexes. Most of the time, if you are using indexes there's 
something wrong in your code.
To work with two parallel lists (heading-info-list and 
actual-info-list), you can either build a map (if your keys are distinct):
  (- (zipmap heading-info-list actual-info-list) (select-keys 
headingnamelist) vals)
or turn the pair of lists into a list of pairs before further processing:
  (map vector heading-info-list actual-info-list)
or directly work in parallel on both lists:
  (map some-fn heading-info-list actual-info-list)

hth,

Christophe


-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (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
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: 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 correctly,
on its first time through have an x of '(1 2 3) and a fin of '()
then it will have an x of '(2 3) and a fin of (concat '() '(1)) (I'm
using concat to indicate a lazy sequence)
then it will have an x of '(3) and a fin of (concat (concat '() '(1))
'(3)).
Why doesn't clojure reduce this to (concat '() '(1) '(3))?  It seems
like if the compiler kept track of whether the first argument to
concat was already a lazy sequence, and kept an eye on where it ended,
the stack overflow thing could be avoided.


Ooh, also, what's that source command you're using?  When I type
(source concat) into my REPL it says it can't evaluate the symbol.

Thanks for all the help; laziness is still decidedly non-intuitive to
me.

On Mar 2, 12:07 am, Jason Wolfe jawo...@berkeley.edu wrote:
 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
               (recur (rest seqs)

 user (my-concat '(1 2 3) [4 5] '(6 7))
 (1 2 3 4 5 6 7)

 This is not proper lazy programming style, but it should give you the  
 basic idea.

 The actual definition of concat is significantly more complicated:

 user (source concat)
 (defn concat
    Returns a lazy seq representing the concatenation of the elements  
 in the supplied colls.
    ([] (lazy-seq nil))
    ([x] (lazy-seq x))
    ([x y]
       (lazy-seq
        (let [s (seq x)]
          (if s
            (cons (first s) (concat (rest s) y))
            y
    ([x y  zs]
       (let [cat (fn cat [xys zs]
                   (lazy-seq
                    (let [xys (seq xys)]
                      (if xys
                        (cons (first xys) (cat (rest xys) zs))
                        (when zs
                          (cat (first zs) (next zs)))]
             (cat (concat x y) zs

 -Jason

 On Mar 1, 2009, at 9:47 PM, Zededarian wrote:



  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 make this quick?

  On Mar 1, 9:07 pm, Jason Wolfe jawo...@berkeley.edu wrote:
  Hi,

  The problem is that you end up with the front of your worklist being
  wrapped in n-lines 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 want.  Some possibilities (untested):

  ; probably the shortest, most idiomatic solution?

  (defn getstrlist [file]
    (apply concat
      (take-while identity
        (repeatedly #(getline file)

  ;or, using vectors, and written more like your solution:

  (defn getstrlist [file]
    (loop [worklst []]
     (if-let [x (getline file)]
        (recur (into worklst x))
       worklst)))

  Cheers,
  Jason

  On Mar 1, 4:53 pm, Zededarian zededar...@gmail.com wrote:

  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 a perfect world I'd like to scale much
  higher.

  I started off just using concat.  Basically my code looks like:
  (defn getstrlist
    ([file]
       (loop [x (getline file) worklst '()]
         (if x
           (recur (getline file) (concat worklst (splitstr x)))
           worklst

  Then in the REPL, if I type (def a (getstrlist FILE)), it works  
  fine.
  But if I try to output a or take (first a), I get a stack overflow
  error.  I don't know why this is.  I remember hearing somewhere that
  Clojure had lazy sequences, so my best guess is that it isn't  
  actually
  concatenating anything, but is storing pointers to the start of all
  the lists on a stack that overflows when I try to evaluate one of
  these pointers.

  I know in Scheme I would write this using metalists that keep  
  track of
  the location of their last element:
  (define (concat metalst1 metalst2)
    (set-cdr! (car metalst1) (cdr metalst2))
    (set-car! metalst1 (car metalst2))
    metalst1)

  (define (make-metalst lst)
    (cons (get-end lst) lst))

  (define (get-end lst)
    (if (null? lst)
        '()
        (if (null? (cdr lst

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)))
fin))
 Will, at least if I'm interpreting your responses correctly,
 on its first time through have an x of '(1 2 3) and a fin of '()
 then it will have an x of '(2 3) and a fin of (concat '() '(1)) (I'm
 using concat to indicate a lazy sequence)
 then it will have an x of '(3) and a fin of (concat (concat '() '(1))
 '(3)).

lazy-seq is (more or less) just a macro that stuffs its body into a  
closure, and stuffs that into a LazySeq object.  The first time  
someone calls seq on the LazySeq (or asks for its count, or  
first, etc.), this closure will be executed to yield the body.

In your example, after two steps x will be '(3) and fin will be the  
result of executing this:

(let [fin (lazy-seq
   (let [s (seq '())]
 (if s
   (cons (first s) (concat (rest s) '(1)))
   y)))]
   (lazy-seq
 (let [s (seq fin)]
   (if s
 (cons (first s) (concat (rest s) '(2)))
  y

In particular, the body of neither lazy-seq call will have executed yet.

 Why doesn't clojure reduce this to (concat '() '(1) '(3))?  It seems
 like if the compiler kept track of whether the first argument to
 concat was already a lazy sequence, and kept an eye on where it ended,
 the stack overflow thing could be avoided.

Well, I can't speak for Rich, but I doubt this will happen.  To do  
this, the compiler must know something specific about concat, namely  
that (concat (concat a b) c) is equivalent to (concat a b c).  This  
not readily apparent to me when just glancing at the source below, and  
I doubt it would be readily apparent to a program analyzer.

I guess this is one of the cases where you are just supposed to know  
and do the right thing (e.g., use a vector).  Even if your original  
solution didn't cause a stack overflow, it would still be O(n^2).

 Ooh, also, what's that source command you're using?  When I type
 (source concat) into my REPL it says it can't evaluate the symbol.

It's in clojure.contrib, in the repl-utils namespace (?)

http://code.google.com/p/clojure-contrib/


 Thanks for all the help; laziness is still decidedly non-intuitive to
 me.

You're welcome.  Also, maybe see the wikibook, in particular

http://en.wikibooks.org/wiki/Clojure_Programming/Concepts#Lazy_Evaluation_of_Sequences

-Jason




 On Mar 2, 12:07 am, Jason Wolfe jawo...@berkeley.edu wrote:
 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
   (recur (rest seqs)

 user (my-concat '(1 2 3) [4 5] '(6 7))
 (1 2 3 4 5 6 7)

 This is not proper lazy programming style, but it should give you the
 basic idea.

 The actual definition of concat is significantly more complicated:

 user (source concat)
 (defn concat
Returns a lazy seq representing the concatenation of the elements
 in the supplied colls.
([] (lazy-seq nil))
([x] (lazy-seq x))
([x y]
   (lazy-seq
(let [s (seq x)]
  (if s
(cons (first s) (concat (rest s) y))
y
([x y  zs]
   (let [cat (fn cat [xys zs]
   (lazy-seq
(let [xys (seq xys)]
  (if xys
(cons (first xys) (cat (rest xys) zs))
(when zs
  (cat (first zs) (next zs)))]
 (cat (concat x y) zs

 -Jason

 On Mar 1, 2009, at 9:47 PM, Zededarian wrote:



 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 make this quick?

 On Mar 1, 9:07 pm, Jason Wolfe jawo...@berkeley.edu wrote:
 Hi,

 The problem is that you end up with the front of your worklist  
 being
 wrapped in n-lines 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 want.  Some possibilities (untested):

 ; probably the shortest, most idiomatic solution?

 (defn getstrlist [file]
   (apply concat
 (take-while identity
   (repeatedly #(getline file)

 ;or, using vectors, and written more like your solution:

 (defn getstrlist [file]
   (loop [worklst []]
(if-let [x (getline file)]
   (recur (into worklst x

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 a perfect world I'd like to scale much
higher.

I started off just using concat.  Basically my code looks like:
(defn getstrlist
  ([file]
 (loop [x (getline file) worklst '()]
   (if x
 (recur (getline file) (concat worklst (splitstr x)))
 worklst

Then in the REPL, if I type (def a (getstrlist FILE)), it works fine.
But if I try to output a or take (first a), I get a stack overflow
error.  I don't know why this is.  I remember hearing somewhere that
Clojure had lazy sequences, so my best guess is that it isn't actually
concatenating anything, but is storing pointers to the start of all
the lists on a stack that overflows when I try to evaluate one of
these pointers.

I know in Scheme I would write this using metalists that keep track of
the location of their last element:
(define (concat metalst1 metalst2)
  (set-cdr! (car metalst1) (cdr metalst2))
  (set-car! metalst1 (car metalst2))
  metalst1)

(define (make-metalst lst)
  (cons (get-end lst) lst))

(define (get-end lst)
  (if (null? lst)
  '()
  (if (null? (cdr lst))
  lst
  (get-end (cdr lst)

Which would be fairly efficient.  But since Clojure doesn't seem to
have real lists, I'm not quite sure how I could port this over.  I
suppose I could implement my own cons pairs like an idiot and do all
of this manually, but I figure I'm just not understanding the Clojure
solution to this problem.

--~--~-~--~~~---~--~~
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
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: 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 n-lines 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 want.  Some possibilities (untested):

; probably the shortest, most idiomatic solution?

(defn getstrlist [file]
  (apply concat
(take-while identity
  (repeatedly #(getline file)

;or, using vectors, and written more like your solution:

(defn getstrlist [file]
  (loop [worklst []]
   (if-let [x (getline file)]
  (recur (into worklst x))
 worklst)))

Cheers,
Jason


On Mar 1, 4:53 pm, Zededarian zededar...@gmail.com wrote:
 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 a perfect world I'd like to scale much
 higher.

 I started off just using concat.  Basically my code looks like:
 (defn getstrlist
   ([file]
      (loop [x (getline file) worklst '()]
        (if x
          (recur (getline file) (concat worklst (splitstr x)))
          worklst

 Then in the REPL, if I type (def a (getstrlist FILE)), it works fine.
 But if I try to output a or take (first a), I get a stack overflow
 error.  I don't know why this is.  I remember hearing somewhere that
 Clojure had lazy sequences, so my best guess is that it isn't actually
 concatenating anything, but is storing pointers to the start of all
 the lists on a stack that overflows when I try to evaluate one of
 these pointers.

 I know in Scheme I would write this using metalists that keep track of
 the location of their last element:
 (define (concat metalst1 metalst2)
   (set-cdr! (car metalst1) (cdr metalst2))
   (set-car! metalst1 (car metalst2))
   metalst1)

 (define (make-metalst lst)
   (cons (get-end lst) lst))

 (define (get-end lst)
   (if (null? lst)
       '()
       (if (null? (cdr lst))
           lst
           (get-end (cdr lst)

 Which would be fairly efficient.  But since Clojure doesn't seem to
 have real lists, I'm not quite sure how I could port this over.  I
 suppose I could implement my own cons pairs like an idiot and do all
 of this manually, but I figure I'm just not understanding the Clojure
 solution to this problem.
--~--~-~--~~~---~--~~
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
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: 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 make this quick?

On Mar 1, 9:07 pm, Jason Wolfe jawo...@berkeley.edu wrote:
 Hi,

 The problem is that you end up with the front of your worklist being
 wrapped in n-lines 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 want.  Some possibilities (untested):

 ; probably the shortest, most idiomatic solution?

 (defn getstrlist [file]
   (apply concat
     (take-while identity
       (repeatedly #(getline file)

 ;or, using vectors, and written more like your solution:

 (defn getstrlist [file]
   (loop [worklst []]
    (if-let [x (getline file)]
       (recur (into worklst x))
      worklst)))

 Cheers,
 Jason

 On Mar 1, 4:53 pm, Zededarian zededar...@gmail.com wrote:

  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 a perfect world I'd like to scale much
  higher.

  I started off just using concat.  Basically my code looks like:
  (defn getstrlist
    ([file]
       (loop [x (getline file) worklst '()]
         (if x
           (recur (getline file) (concat worklst (splitstr x)))
           worklst

  Then in the REPL, if I type (def a (getstrlist FILE)), it works fine.
  But if I try to output a or take (first a), I get a stack overflow
  error.  I don't know why this is.  I remember hearing somewhere that
  Clojure had lazy sequences, so my best guess is that it isn't actually
  concatenating anything, but is storing pointers to the start of all
  the lists on a stack that overflows when I try to evaluate one of
  these pointers.

  I know in Scheme I would write this using metalists that keep track of
  the location of their last element:
  (define (concat metalst1 metalst2)
    (set-cdr! (car metalst1) (cdr metalst2))
    (set-car! metalst1 (car metalst2))
    metalst1)

  (define (make-metalst lst)
    (cons (get-end lst) lst))

  (define (get-end lst)
    (if (null? lst)
        '()
        (if (null? (cdr lst))
            lst
            (get-end (cdr lst)

  Which would be fairly efficient.  But since Clojure doesn't seem to
  have real lists, I'm not quite sure how I could port this over.  I
  suppose I could implement my own cons pairs like an idiot and do all
  of this manually, but I figure I'm just not understanding the Clojure
  solution to this problem.
--~--~-~--~~~---~--~~
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
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: 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
  (recur (rest seqs)

user (my-concat '(1 2 3) [4 5] '(6 7))
(1 2 3 4 5 6 7)

This is not proper lazy programming style, but it should give you the  
basic idea.

The actual definition of concat is significantly more complicated:

user (source concat)
(defn concat
   Returns a lazy seq representing the concatenation of the elements  
in the supplied colls.
   ([] (lazy-seq nil))
   ([x] (lazy-seq x))
   ([x y]
  (lazy-seq
   (let [s (seq x)]
 (if s
   (cons (first s) (concat (rest s) y))
   y
   ([x y  zs]
  (let [cat (fn cat [xys zs]
  (lazy-seq
   (let [xys (seq xys)]
 (if xys
   (cons (first xys) (cat (rest xys) zs))
   (when zs
 (cat (first zs) (next zs)))]
(cat (concat x y) zs

-Jason



On Mar 1, 2009, at 9:47 PM, Zededarian wrote:


 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 make this quick?

 On Mar 1, 9:07 pm, Jason Wolfe jawo...@berkeley.edu wrote:
 Hi,

 The problem is that you end up with the front of your worklist being
 wrapped in n-lines 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 want.  Some possibilities (untested):

 ; probably the shortest, most idiomatic solution?

 (defn getstrlist [file]
   (apply concat
 (take-while identity
   (repeatedly #(getline file)

 ;or, using vectors, and written more like your solution:

 (defn getstrlist [file]
   (loop [worklst []]
(if-let [x (getline file)]
   (recur (into worklst x))
  worklst)))

 Cheers,
 Jason

 On Mar 1, 4:53 pm, Zededarian zededar...@gmail.com wrote:

 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 a perfect world I'd like to scale much
 higher.

 I started off just using concat.  Basically my code looks like:
 (defn getstrlist
   ([file]
  (loop [x (getline file) worklst '()]
(if x
  (recur (getline file) (concat worklst (splitstr x)))
  worklst

 Then in the REPL, if I type (def a (getstrlist FILE)), it works  
 fine.
 But if I try to output a or take (first a), I get a stack overflow
 error.  I don't know why this is.  I remember hearing somewhere that
 Clojure had lazy sequences, so my best guess is that it isn't  
 actually
 concatenating anything, but is storing pointers to the start of all
 the lists on a stack that overflows when I try to evaluate one of
 these pointers.

 I know in Scheme I would write this using metalists that keep  
 track of
 the location of their last element:
 (define (concat metalst1 metalst2)
   (set-cdr! (car metalst1) (cdr metalst2))
   (set-car! metalst1 (car metalst2))
   metalst1)

 (define (make-metalst lst)
   (cons (get-end lst) lst))

 (define (get-end lst)
   (if (null? lst)
   '()
   (if (null? (cdr lst))
   lst
   (get-end (cdr lst)

 Which would be fairly efficient.  But since Clojure doesn't seem to
 have real lists, I'm not quite sure how I could port this over.  I
 suppose I could implement my own cons pairs like an idiot and do all
 of this manually, but I figure I'm just not understanding the  
 Clojure
 solution to this problem.
 


--~--~-~--~~~---~--~~
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
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: 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)]
(cond
 (= searchtype :breadth-first) (doall (concat s c))
 (= searchtype :depth-first) (doall (concat c s)


 The doall forces the lists then and there.


 On Sun, Feb 8, 2009 at 7:56 PM, Jeffrey Straszheim 
 straszheimjeff...@gmail.com wrote:

 Perhaps you are forcing a very long lazy list?

 Try (.printStackTrace *e)


 On Sun, Feb 8, 2009 at 9:41 AM, jodocus rjek...@gmail.com 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 http://en.wikipedia.org/wiki/%0A8_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 it begins taking a lot of time).

 But when I use breadth-first search it gives a stack overflow error at
 boardsize 7. All recursive calls in the code are done using recur at
 tail positions, and it is not clear to me what could otherwise cause
 this. Does anyone have a suggestion how to track down the cause of
 this stack overflow?

 - code 
 (def dim 6)
 (def numsqrs (* dim dim))
 (def queen \*)
 (def empty-sqr \.)

 ;; a state in this program is nothing more
 ;; than a list of positions on the board

 ;; returns true when placing a queen on both p1 and p2 is disallowed
 (defn conflict? [p1 p2]
  (let [x1 (rem p1 dim)
x2 (rem p2 dim)
y1 (quot p1 dim)
y2 (quot p2 dim)]
(or
 (== x1 x2)
 (== y1 y2)
 ;; diagonals
 (let [dx (- x2 x1)
   dy (- y2 y1)]
   (or (== dx dy)
   (== (- dx) dy))

 (defn remove-conflicted [p ps]
  (remove #(conflict? p %) ps))

 ;; returns a list of all squares where a queen can be placed in given
 state
 (defn get-safe-squares [state]
  (loop [safe (range (inc (first state)) numsqrs), s state]
(when-not (empty? safe)
  (if-not (empty? s)
(recur (remove-conflicted (first s) safe) (rest s))
safe

 ;; given a state with n queens, returns all possible states with n+1
 queens
 (defn children [state]
  (if (empty? state)
(map #(list %) (range numsqrs))
(when ( (count state) dim)
  (map #(conj state %) (get-safe-squares state)

 (defn add-children [searchtype statelist]
  (let [c (children (first statelist))
s (rest statelist)]
(cond
 (= searchtype :breadth-first) (concat s c)
 (= searchtype :depth-first) (concat c s

 (defn search
  ([searchtype] (search searchtype (children ()) 0 0))
  ([searchtype statelist n found]
 (if-not (empty? statelist)
 (let [s (first statelist)
   is-solution (= (count s) dim)
   fnd (if is-solution (inc found) found)]
   (when is-solution
 (println (format Solution: %d, queens
 at: %s, searched: %d fnd
 s (inc n
 ;(print-state s))
   (recur searchtype (add-children searchtype
 statelist) (inc n)
 fnd))
 {:searched n :found found})))

 (search :breadth-first)

 




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



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 it begins taking a lot of time).

But when I use breadth-first search it gives a stack overflow error at
boardsize 7. All recursive calls in the code are done using recur at
tail positions, and it is not clear to me what could otherwise cause
this. Does anyone have a suggestion how to track down the cause of
this stack overflow?

- code 
(def dim 6)
(def numsqrs (* dim dim))
(def queen \*)
(def empty-sqr \.)

;; a state in this program is nothing more
;; than a list of positions on the board

;; returns true when placing a queen on both p1 and p2 is disallowed
(defn conflict? [p1 p2]
  (let [x1 (rem p1 dim)
x2 (rem p2 dim)
y1 (quot p1 dim)
y2 (quot p2 dim)]
(or
 (== x1 x2)
 (== y1 y2)
 ;; diagonals
 (let [dx (- x2 x1)
   dy (- y2 y1)]
   (or (== dx dy)
   (== (- dx) dy))

(defn remove-conflicted [p ps]
  (remove #(conflict? p %) ps))

;; returns a list of all squares where a queen can be placed in given
state
(defn get-safe-squares [state]
  (loop [safe (range (inc (first state)) numsqrs), s state]
(when-not (empty? safe)
  (if-not (empty? s)
(recur (remove-conflicted (first s) safe) (rest s))
safe

;; given a state with n queens, returns all possible states with n+1
queens
(defn children [state]
  (if (empty? state)
(map #(list %) (range numsqrs))
(when ( (count state) dim)
  (map #(conj state %) (get-safe-squares state)

(defn add-children [searchtype statelist]
  (let [c (children (first statelist))
s (rest statelist)]
(cond
 (= searchtype :breadth-first) (concat s c)
 (= searchtype :depth-first) (concat c s

(defn search
  ([searchtype] (search searchtype (children ()) 0 0))
  ([searchtype statelist n found]
 (if-not (empty? statelist)
 (let [s (first statelist)
   is-solution (= (count s) dim)
   fnd (if is-solution (inc found) found)]
   (when is-solution
 (println (format Solution: %d, queens at: %s, 
searched: %d fnd
s (inc n
;(print-state s))
   (recur searchtype (add-children searchtype 
statelist) (inc n)
fnd))
 {:searched n :found found})))

(search :breadth-first)

--~--~-~--~~~---~--~~
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
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: 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 rjek...@gmail.com 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 http://en.wikipedia.org/wiki/%0A8_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 it begins taking a lot of time).

 But when I use breadth-first search it gives a stack overflow error at
 boardsize 7. All recursive calls in the code are done using recur at
 tail positions, and it is not clear to me what could otherwise cause
 this. Does anyone have a suggestion how to track down the cause of
 this stack overflow?

 - code 
 (def dim 6)
 (def numsqrs (* dim dim))
 (def queen \*)
 (def empty-sqr \.)

 ;; a state in this program is nothing more
 ;; than a list of positions on the board

 ;; returns true when placing a queen on both p1 and p2 is disallowed
 (defn conflict? [p1 p2]
  (let [x1 (rem p1 dim)
x2 (rem p2 dim)
y1 (quot p1 dim)
y2 (quot p2 dim)]
(or
 (== x1 x2)
 (== y1 y2)
 ;; diagonals
 (let [dx (- x2 x1)
   dy (- y2 y1)]
   (or (== dx dy)
   (== (- dx) dy))

 (defn remove-conflicted [p ps]
  (remove #(conflict? p %) ps))

 ;; returns a list of all squares where a queen can be placed in given
 state
 (defn get-safe-squares [state]
  (loop [safe (range (inc (first state)) numsqrs), s state]
(when-not (empty? safe)
  (if-not (empty? s)
(recur (remove-conflicted (first s) safe) (rest s))
safe

 ;; given a state with n queens, returns all possible states with n+1
 queens
 (defn children [state]
  (if (empty? state)
(map #(list %) (range numsqrs))
(when ( (count state) dim)
  (map #(conj state %) (get-safe-squares state)

 (defn add-children [searchtype statelist]
  (let [c (children (first statelist))
s (rest statelist)]
(cond
 (= searchtype :breadth-first) (concat s c)
 (= searchtype :depth-first) (concat c s

 (defn search
  ([searchtype] (search searchtype (children ()) 0 0))
  ([searchtype statelist n found]
 (if-not (empty? statelist)
 (let [s (first statelist)
   is-solution (= (count s) dim)
   fnd (if is-solution (inc found) found)]
   (when is-solution
 (println (format Solution: %d, queens at:
 %s, searched: %d fnd
 s (inc n
 ;(print-state s))
   (recur searchtype (add-children searchtype
 statelist) (inc n)
 fnd))
 {:searched n :found found})))

 (search :breadth-first)

 


--~--~-~--~~~---~--~~
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
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: 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 then and there.

On Sun, Feb 8, 2009 at 7:56 PM, Jeffrey Straszheim 
straszheimjeff...@gmail.com wrote:

 Perhaps you are forcing a very long lazy list?

 Try (.printStackTrace *e)


 On Sun, Feb 8, 2009 at 9:41 AM, jodocus rjek...@gmail.com 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 http://en.wikipedia.org/wiki/%0A8_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 it begins taking a lot of time).

 But when I use breadth-first search it gives a stack overflow error at
 boardsize 7. All recursive calls in the code are done using recur at
 tail positions, and it is not clear to me what could otherwise cause
 this. Does anyone have a suggestion how to track down the cause of
 this stack overflow?

 - code 
 (def dim 6)
 (def numsqrs (* dim dim))
 (def queen \*)
 (def empty-sqr \.)

 ;; a state in this program is nothing more
 ;; than a list of positions on the board

 ;; returns true when placing a queen on both p1 and p2 is disallowed
 (defn conflict? [p1 p2]
  (let [x1 (rem p1 dim)
x2 (rem p2 dim)
y1 (quot p1 dim)
y2 (quot p2 dim)]
(or
 (== x1 x2)
 (== y1 y2)
 ;; diagonals
 (let [dx (- x2 x1)
   dy (- y2 y1)]
   (or (== dx dy)
   (== (- dx) dy))

 (defn remove-conflicted [p ps]
  (remove #(conflict? p %) ps))

 ;; returns a list of all squares where a queen can be placed in given
 state
 (defn get-safe-squares [state]
  (loop [safe (range (inc (first state)) numsqrs), s state]
(when-not (empty? safe)
  (if-not (empty? s)
(recur (remove-conflicted (first s) safe) (rest s))
safe

 ;; given a state with n queens, returns all possible states with n+1
 queens
 (defn children [state]
  (if (empty? state)
(map #(list %) (range numsqrs))
(when ( (count state) dim)
  (map #(conj state %) (get-safe-squares state)

 (defn add-children [searchtype statelist]
  (let [c (children (first statelist))
s (rest statelist)]
(cond
 (= searchtype :breadth-first) (concat s c)
 (= searchtype :depth-first) (concat c s

 (defn search
  ([searchtype] (search searchtype (children ()) 0 0))
  ([searchtype statelist n found]
 (if-not (empty? statelist)
 (let [s (first statelist)
   is-solution (= (count s) dim)
   fnd (if is-solution (inc found) found)]
   (when is-solution
 (println (format Solution: %d, queens at:
 %s, searched: %d fnd
 s (inc n
 ;(print-state s))
   (recur searchtype (add-children searchtype
 statelist) (inc n)
 fnd))
 {:searched n :found found})))

 (search :breadth-first)

 



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



stack overflow in for

2008-10-03 Thread Chouser
prunedtree in IRC reported a stack overflow with this code:
http://paste.lisp.org/display/67882

I was able to trim this down and still reproduce the error:

(dorun (for [i (range 1) j nil] 1))

It turns out that for and lazy-cat interact badly in this
degenerate case.  Having for use recur instead of lazy-cat in
such cases seems to fix the problem.  Patch is attached.

--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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---

diff --git a/src/clj/clojure/boot.clj b/src/clj/clojure/boot.clj
index 68cb448..30c8d68 100644
--- a/src/clj/clojure/boot.clj
+++ b/src/clj/clojure/boot.clj
@@ -2274,9 +2274,11 @@
 			 (when-first ~b ~gxs
(if ~f
 			~(if rses
-			   `(let [iterys# ~(emit rses)]
-  (lazy-cat (iterys# ~ys)
-	(~giter (rest ~gxs
+			   `(let [iterys# ~(emit rses)
+  fs# (iterys# ~ys)]
+  (if fs#
+(lazy-cat fs# (~giter (rest ~gxs)))
+(recur (rest ~gxs
 			   `(lazy-cons ~expr (~giter (rest ~gxs
 ~(if (= w :when)
`(recur (rest ~gxs))


Re: Bug: self require - stack overflow

2008-09-10 Thread ntupel

On Wed, 2008-09-10 at 16:47 +1100, Brett Morgan wrote:
 On Wed, Sep 10, 2008 at 4:38 PM, ntupel [EMAIL PROTECTED] wrote:
 
  On Tue, 2008-09-09 at 23:57 +1000, Brett Morgan wrote:
  On Tue, Sep 9, 2008 at 10:31 PM, [EMAIL PROTECTED]
  [EMAIL PROTECTED] wrote:
  
   On Sep 9, 11:26 am, Brett Morgan [EMAIL PROTECTED] wrote:
   For C, protection against circular dependencies is on the head of the
   programmer, in the form of #ifdef guards.
  
   There is #import as a GCC extension (also used in Objective-C).
  
 
  Which expand out to #ifdef guards, if memory serves.
 
  So what? It just shows you another effective way to tackle the cycle
  problem. As a programmer I don't care if I use include or import or
  require to load my dependencies. But I do care if I need to make extra
  steps to not include stuff twice. I really can not believe that we have
  to discuss this age old problem which has been solved so many times
  already again and again. This is just plain stupid.
 
 
 Well, you could code your own include macro to achieve the affect you
 are after. It is an open source project, after all.

I know and in fact I had my own version of require long before
clojure-contrib was started. But I was glad that it was no longer needed
when clojure-contrib.lib was included because something as basic as this
needs to be part of the standard distribution. And now despite of these
promising developments it seems that I must again come up with a
homegrown solution as I can not convince the Clojure community that it
should be part of Clojure itself. I am delighted!



--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Bug: self require - stack overflow

2008-09-10 Thread ntupel

On Tue, 2008-09-09 at 07:26 -0700, Rich Hickey wrote:
 Certainly there are areas where there could be more explicit messages,
 but the detection and reporting of errors has a cost (in time,
 sometimes runtime, effort, code size and complexity) and I don't want
 to incur that cost unless it is solving a real, common problem, not
 just a theoretical one.

Just to make myself clear - I clearly said in my first reply to your
post:

One can argue whether this should result in an error message or
whether the semantics of require are satisfied if the namespaces
are loaded once each.

So I would be glad if the bug is fixed by silently stopping the load if
the namespace is already found in *loaded-libs*. After all the
infrastructure is in place and all that is needed is recording the lib
before the actual load in *loaded-libs* and if the load fails to remove
it again which slightly complicates load-one and/or load-all but still
it seems to be a small price to pay for correctness.



--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Bug: self require - stack overflow

2008-09-10 Thread Rich Hickey



On Sep 10, 1:38 am, ntupel [EMAIL PROTECTED] wrote:
 On Tue, 2008-09-09 at 23:57 +1000, Brett Morgan wrote:
  On Tue, Sep 9, 2008 at 10:31 PM, [EMAIL PROTECTED]
  [EMAIL PROTECTED] wrote:

   On Sep 9, 11:26 am, Brett Morgan [EMAIL PROTECTED] wrote:
   For C, protection against circular dependencies is on the head of the
   programmer, in the form of #ifdef guards.

   There is #import as a GCC extension (also used in Objective-C).

  Which expand out to #ifdef guards, if memory serves.

 So what? It just shows you another effective way to tackle the cycle
 problem.

First off, let me say that there's nothing wrong in your asking for
this feature, and I'd like to get this dialogue back on a productive
track.

 As a programmer I don't care if I use include or import or
 require to load my dependencies. But I do care if I need to make extra
 steps to not include stuff twice.

If you don't write any cyclic dependencies there are no extra steps.
This is not about multiple includes, that is already handled.

If you do write cyclic dependencies, there is a bug in your program
logic.

You don't like the way the bug is manifested/reported, point taken.

So far, for me, this seems highly theoretical. If it becomes a common
problem for people, I'll be happy to make an enhancement in this area.

If you don't want to wait, submit a patch (and a CA if you haven't
already), and I'll look at it. I will say that the silent ignore
path is not an option - cyclic dependencies are an error you can't
leave in place. There will be other tools that need the dependencies
to be acyclic.

Rich
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Bug: self require - stack overflow

2008-09-09 Thread Brett Morgan

On Tue, Sep 9, 2008 at 7:29 PM, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:

 On Sep 9, 8:48 am, Brett Morgan [EMAIL PROTECTED] wrote:
 You seem to be asking for the
 compiler to be able to prove that your computation finishes, and if it
 doesn't then give you a sane response.

 No.

Would you kindly educate me in how you believe that Clojure would go
about trapping your error and giving you an error message instead of
running out of stack space, given that you had given it a
non-terminating dependency list?

-- 

Brett Morgan http://brett.morgan.googlepages.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Bug: self require - stack overflow

2008-09-09 Thread [EMAIL PROTECTED]

On Sep 9, 10:51 am, Brett Morgan [EMAIL PROTECTED] wrote:
 Would you kindly educate me in how you believe that Clojure would go
 about trapping your error and giving you an error message instead of
 running out of stack space, given that you had given it a
 non-terminating dependency list?

First please note that circular includes are nothing specific to
Clojure and other compilers have solved this problem multiple times
already.
Second I am not insisting on a error message. As I said, the precise
semantics of require can be debated. For instance the ns macro can
always check a set of declared ns symbols before processing the ns
declaration further, putting a new ns symbol into this set as soon as
it is encountered. Wheather it silently stops then or issues an error
message is up to discussion. Also note that this is not a concrete
suggestion how to implement the ns macro, it should just illustrate
that this is not an instance of the halting problem.

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Bug: self require - stack overflow

2008-09-09 Thread Mike Hinchey

It doesn't seem *impossible* for require and use to keep a var set of
namespaces it's loading and check if the current is already in the set
then give an error.

However, I don't think clojure supports circular dependency since
loading is sequential.  I know there's a trick for functions to be
circularly dependent, and I suppose that could be done with files, but
you'd have to load the files manually, not with (ns).

Unless I'm missing something, this is probably something people will
expect to work, so a friendly error message would be good.

-Mike

On Sep 9, 1:29 am, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 On Sep 9, 8:48 am, Brett Morgan [EMAIL PROTECTED] wrote:

  You seem to be asking for the
  compiler to be able to prove that your computation finishes, and if it
  doesn't then give you a sane response.

 No.
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Bug: self require - stack overflow

2008-09-09 Thread Brett Morgan

On Tue, Sep 9, 2008 at 11:58 PM, Randall R Schulz [EMAIL PROTECTED] wrote:

 On Tuesday 09 September 2008 01:51, Brett Morgan wrote:
 ...

 Would you kindly educate me in how you believe that Clojure would go
 about trapping your error and giving you an error message instead of
 running out of stack space, given that you had given it a
 non-terminating dependency list?

 In this case the matter is nothing other than cycle detection in a
 graph. It's eminently decidable.


So what do you do about the macros that change the semantics of the
included code between the two inclusions of said code?


 Randall Schulz

 




-- 

Brett Morgan http://brett.morgan.googlepages.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Bug: self require - stack overflow

2008-09-09 Thread Dmitri P

Whatever you do, don't kill Clojure while trying to save us from
ourselves.

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Bug: self require - stack overflow

2008-09-09 Thread ntupel

On Tue, 2008-09-09 at 23:57 +1000, Brett Morgan wrote:
 On Tue, Sep 9, 2008 at 10:31 PM, [EMAIL PROTECTED]
 [EMAIL PROTECTED] wrote:
 
  On Sep 9, 11:26 am, Brett Morgan [EMAIL PROTECTED] wrote:
  For C, protection against circular dependencies is on the head of the
  programmer, in the form of #ifdef guards.
 
  There is #import as a GCC extension (also used in Objective-C).
 
 
 Which expand out to #ifdef guards, if memory serves.

So what? It just shows you another effective way to tackle the cycle
problem. As a programmer I don't care if I use include or import or
require to load my dependencies. But I do care if I need to make extra
steps to not include stuff twice. I really can not believe that we have
to discuss this age old problem which has been solved so many times
already again and again. This is just plain stupid.


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Bug: self require - stack overflow

2008-09-09 Thread Brett Morgan

On Wed, Sep 10, 2008 at 4:38 PM, ntupel [EMAIL PROTECTED] wrote:

 On Tue, 2008-09-09 at 23:57 +1000, Brett Morgan wrote:
 On Tue, Sep 9, 2008 at 10:31 PM, [EMAIL PROTECTED]
 [EMAIL PROTECTED] wrote:
 
  On Sep 9, 11:26 am, Brett Morgan [EMAIL PROTECTED] wrote:
  For C, protection against circular dependencies is on the head of the
  programmer, in the form of #ifdef guards.
 
  There is #import as a GCC extension (also used in Objective-C).
 

 Which expand out to #ifdef guards, if memory serves.

 So what? It just shows you another effective way to tackle the cycle
 problem. As a programmer I don't care if I use include or import or
 require to load my dependencies. But I do care if I need to make extra
 steps to not include stuff twice. I really can not believe that we have
 to discuss this age old problem which has been solved so many times
 already again and again. This is just plain stupid.


Well, you could code your own include macro to achieve the affect you
are after. It is an open source project, after all.


-- 

Brett Morgan http://brett.morgan.googlepages.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---