3 ms·
You say that (doto obj (.glBegin ...) (.methods ...) (.glEnd)) > I decided I wanted to factor out the (.glBegin ...) and (.glEnd).
by jules 17y ago
You say that
(doto obj
(.glBegin ...)
(.methods ...)
(.glEnd))
> I decided I wanted to factor out the (.glBegin ...) and (.glEnd). Aha, this is a job for macros!
(gl-begin-end body) ; this should macro expand to:
(do
(.glBegin ...)
body
(.glEnd))
But why did you change `doto` to `do`?
Here's how you can do this:
(defmacro gl-begin-end [obj & body]
`(doto ~obj
(.glBegin)
~@body
(.glEnd)))
- yummyfajitas 17y agoAs I said, I know the programming mistake I made here (and that it reflects lack of knowledge of clojure on my part). But the problem I had with the doto macro could easily translate to a problem you have with my kwyjibo macro. In python, I know what this code does, regardless of what happens at higher levels of indentation (ignoring some rarely used class-level hacking): f(a,b,c) g.h(i) In lisp, I can't necessarily assume that (f a b c) (.h g i) will actually call f on a,b,c and then call the h method of g on i. The ability to modify syntax programmatically implies that syntax (i.e. the s-exp structure) may not mean what you think it means. I'm speculating that this may make collaboration more difficult.