• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Recur for every item in doseq

 
Greenhorn
Posts: 4
Scala Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, coderanch users!

I'm at clojure again, and this time I was trying to do something harder, precisely: to solve a parametric variant of the 8 chess queens problem (writing a function that takes board dimensions and pieces with their numbers and returning all of the possible combinations of those).
I read a really large lot of documentation, learnt about the parallelization with pmap, state tracking using atoms, agents, refs, vars, et similia... But there is still one issue that is plagueing me.


NOTES:
  • blank-board yields an m X n array of zeroes
  • get-free-squares returns all of the squares whose value is 0
  • place yields the board it took in input, but adding a :pawn keyword in the coordinates given in argument and incrementing all of the squares that pawn hits


  • I need to recur multiple times (read: call the same function for every item in the list), because what I'm trying to do is to analyze every possible combination in order to obtain only the valid ones.
    Is such a thing possible in some way? I tried to call banally

    but, if I try to call such a function for a larger board (say, 7x7 with 6-8 chess pieces to place around) after ~1min of calculations it eats all the heap, spits out ~1100 results and dies from heap overflow. I tried to give it a larger heap, but it is clearly not a heap issue, but an algorhytmic one.
    Recur and trampoline are the only calls that implement TCO in clojure, and I'd like to take advantage from it, in some way.

    TL; DR: how do I recur for every item in doseq?
     
    Rancher
    Posts: 379
    22
    Mac OS X Monad Clojure Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    "Call the same function for each item in a list" sounds like map... Does that help?
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic