1

我正在尝试在 Clojure 中填充 ArrayList,但收到以下错误消息

java.util.ArrayList 不能转换为 clojure.lang.IFn

这是我的代码:

(ns blackhole-v1.core
  (:import [java.util ArrayList])
  (:import [toxi.geom Vec2D])
  (:use [quil.core]))


(def particles (new ArrayList))


(defn add-particle []
;  (particles (.add (new Vec2D (random (width)) (random (height)))))
  (doto (particles)
    (.add (new Vec2D (random (width)) (random (height))))))


(defn setup []
  (smooth)
  (background 0)
  (add-particle))


(defn draw []
  (background 0)
  (dotimes [i (.size particles)]
    (ellipse (.x (.get particles i)) (.y (.get particles i)) 20 20)))


(defsketch blackhole-v1
  :title "black hole v1"
  :setup setup
  :draw draw
  :size [640 480])

任何想法我做错了什么?

4

1 回答 1

4

您正在尝试(particles)作为函数调用,但它只是简单的 var。而不是(particles)使用particles

(defn add-particle []
;  (particles (.add (new Vec2D (random (width)) (random (height)))))
  (doto particles
    (.add (new Vec2D (random (width)) (random (height))))))
于 2013-03-13T07:36:47.437 回答