Advertisement
Guest User

dynamic path seesaw

a guest
Nov 28th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. ;The following macro doesn't expand properly?:
  2.  
  3. (defmacro make-path [[x y]]
  4. `(path [] (move-to ~x ~y))
  5. )
  6.  
  7. ;note the nil path2206. Ideally that'd expand to (.moveTo path2206 10 10):
  8.  
  9. (macroexpand
  10. '(make-path [10 10]))
  11. (let* [path2206 (java.awt.geom.Path2D$Double.)] (.moveTo path2206 0 0) (nil path2206 10 10) path2206)
  12.  
  13.  
  14. ;Here's how the seesaw macro looks like:
  15.  
  16. ;(def ^{:private true} path-ops {
  17. ; 'line-to '.lineTo
  18. ; 'move-to '.moveTo
  19. ; 'curve-to '.curveTo
  20. ; 'quad-to 'quad-to
  21. ;})
  22. ;
  23. ;(defmacro path [opts & forms]
  24. ; (when (not (vector? opts)) (illegal-argument "path must start with vector of (possibly ;empty) options"))
  25. ; (let [p (gensym "path")]
  26. ; `(let [~p (java.awt.geom.Path2D$Double.)]
  27. ; ; Insert an initial moveTo to avoid needless exceptions
  28. ; (.moveTo ~p 0 0)
  29. ; ~@(for [f forms]
  30. ; (cons (get path-ops (first f)) (cons p (rest f))))
  31. ; ~p)))
  32. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement