Skip to content

Instantly share code, notes, and snippets.

@gilesbowkett
Created June 29, 2013 00:03
Show Gist options
  • Save gilesbowkett/5889028 to your computer and use it in GitHub Desktop.
Save gilesbowkett/5889028 to your computer and use it in GitHub Desktop.
line 35 is a problem I'm having in Quil, the Clojure interface to Processing.
(ns circles.core
(:require [quil.core :as q]))
; "hello world" for Quil meets http://bit.ly/18luJO2
(def the-width 808)
(def the-height 500)
(defn random-x-y []
(list (int (rand the-width))
(int (rand the-height))))
(defn circle [xy]
(q/stroke 171 163 225)
(q/stroke-weight 5)
(q/fill 213 209 240)
(let [diam (+ 50 (q/random 100))
x (first xy)
y (second xy)]
(q/ellipse x y diam diam)))
(defn log-xy [a-list]
(println (str "x: " (first a-list) " "
"y: " (second a-list))))
(defn setup []
(q/smooth)
(q/frame-rate 20)
(q/background 0)
(let [xy (random-x-y)]
; this totally works
(circle (random-x-y)))
; this totally fails
(map circle (list (random-x-y) (random-x-y)))
)
(defn draw [] ())
(q/defsketch example
:title "Circles"
:setup setup
:draw draw
:size [the-width the-height])
(defn -main [] ())
@candera
Copy link

candera commented Jun 29, 2013

When you say it "fails", what do you mean? Assuming you mean, "Doesn't draw the last two circles", I'm guessing laziness if your issue: map returns a lazy seq. In this case, (dotimes [_ 2](circle %28random-x-y%29) might be more what you're after.

@gilesbowkett
Copy link
Author

That is exactly what I meant. Not getting the desired result from dotimes or doall either, but your diagnosis certainly makes sense. @fogus said basically the same thing.

@gilesbowkett
Copy link
Author

Correction: got it working. Awesome. Major problem: didn't understand map was lazy. Minor problem: parens in the wrong place.

@samaaron
Copy link

samaaron commented Jul 2, 2013

Whenever you have a problem with Clojure, pretty much first thing to investigate is laziness :-)

In this case you can wrap the call to map with dorun :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment