Hi Mike, thank you, I've checked out your vectorz lib in the past and am also aware of Zach's clj-tuple (which this concrete part is much closer too), but I'm looking for a pure Clojure & CLJS compatible solution (using CLJX). This alI is part of a longwinded (on/off 2+ yrs now) refactoring/total re-imagining effort of my http://toxiclibs.org/ project, which too has a comprehensive set of vector ops (and the Clojure version many more), e.g: http://hg.postspectacular.com/toxiclibs/src/tip/src.core/toxi/geom/Vec3D.java
K. On 12 September 2013 04:45, Mikera <mike.r.anderson...@gmail.com> wrote: > Hi Karsten, > > It looks to me like you're trying to define some small fixed-size numeric > double vectors and related operations? For graphics, games or physical > modelling perhaps? > > Perhaps you've already evaluated all the options and decided that a bunch of > custom deftypes is the best way go, but in case you haven't seen it already, > can I recommend considering my little library vectorz-clj? > > I designed it specifically to handle this kind of use case in Clojure, and > it includes: > - Fixed size 1-4D Vectors, with many specialised methods for high > performance > - Specialised 2D and 3D transformation matrices (rotations, scaling etc.) > - Affine transformations > - core.matrix fully supported (which gives you a lot of more general > matrix/vector features with a nice Clojure API) > > See: https://github.com/mikera/vectorz-clj > And core.matrix: https://github.com/mikera/matrix-api > > If vectorz-clj and/or core.matrix doesn't quite fit your needs, could you > let me know why? I'm keen to address all the common vector use cases that > people have in Clojure, so that people can avoid reinventing the wheel. > > > On Thursday, 12 September 2013 07:41:34 UTC+8, Karsten Schmidt wrote: >> >> Hi, I'm (once again) despairing over some issues trying to integrate >> one macro with another. Both are supposed to be used together to >> generate a bunch of deftypes. Firstly, here's the one working >> correctly (stripped out error checking for simplicity): >> >> (defmacro swizzle* >> "Takes a class name, source instance, keyword and metadata map, >> returns new instance of type with fields populated based on >> decomposed single letter key lookups. E.g. >> >> (macroexpand-1 '(swizzle* Vec3 v :zyx)) >> #_=> (new Vec3 (. v z) (. v y) (. v x) {}) >> >> (macroexpand-1 '(swizzle* Vec3 v :xxz)) >> #_=> (new Vec3 (. v x) (. v x) (. v z) {}) >> " >> [clz src k meta] >> `(new ~clz >> ~@(->> k >> (name) >> (map (comp symbol str)) >> (map (fn [f] `(. ~src ~f)))) >> ~meta)) >> >> Now, where things go wrong is when I try to use this swizzle macro >> from within the 2nd macro which generates the deftype skeleton (also >> stripped down): >> >> (defmacro defvec >> [n] >> (let [vname (symbol (str "Vec" n)) >> syms (map (fn [s] (-> s str symbol)) (take n "xyzw"))] >> `(deftype ~vname [~@syms __meta#] >> >> clojure.lang.IObj >> (meta [this#] __meta#) >> (withMeta [this# mm#] (new ~vname ~@syms mm#)) >> >> clojure.lang.ILookup >> (valAt [this# k#] (swizzle* ~vname this# k# __meta#)) ;; FIXME >> ))) >> >> (defvec 3) >> CompilerException java.lang.IllegalArgumentException: No matching ctor >> found for class compile__stub.user.Vec3, >> compiling:(NO_SOURCE_PATH:1:1) >> >> =:_( >> >> I've been trying a lot of other versions (e.g. inline swizzle*, >> defining it as local fn etc.), but honestly I don't understand why >> this fails and would really appreciate some further insights into >> these aspects of the dark art of macro voodoo. >> >> Furthermore (for the future), in that second macro how can I add type >> hints to the generated field names (they should all be doubles)... >> >> Thanks a lot! > > -- > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. -- Karsten Schmidt http://postspectacular.com | http://toxiclibs.org | http://toxi.co.uk -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.