Hi, Firstly I just want to say "Wow" I really like what you have created here.
The (.method object args) form is just fantastic! JVM direct access like this seems overpowered. Being able to call anything and everything is such a big win. Being a complete novice I was able to bang the Java3D spinning box example out (I've appended it to this post)... And then it hit me, Ogre3D has java bindings (like many popular libraries), I can really use *anything*. What really impressed me is that the (.method object args) form is so much more natural language readable than the java syntax. When dealing with objects, the functions associated with with the object modify the data in some way. This lends itself to the form "change data <input>", which is exactly the gramma that (.method object args) uses. "update world" is much more natural than "world update". Because data can't really do anything itself, verbs are less common method names than modification/operator/lookup type names. When it comes to verbs things look a little different. Star Trek characters talk like "object verb <input>", but it is easier to listen to the more common "verb <input> object". "Lassie, go home" is how most programming languages phrase. "go home Lassie" is more readable. In the (.method object args) form it would be "go Lassie, home". This isn't better or worse than the Star Trek form, but in this case its not an ideal sequencing. (.method args object) would look perfect. Then it hit me, hey this is Lisp, new forms is what its all about! I can hack together my own form which flips things around. That's really powerful. Like all good Lisp n00bs I start thinking to myself "now if I could just get rid of those parenthesis..." Ok I know enough to understand *why* parenthesis are great -> nesting structures, and why they are historically hard to avoid (syntax tree). However there are viable techniques for reducing them http://www.dwheeler.com/readable/ "Sweet expressions" and using infix notation. It seems to me that it could indeed be possible to achieve a syntax such as: "go home Lassie". In a more complex case where home is actally x=1,y=2,z=0... "go (1 2 0) Lassie" reads better to me than Lassie.go(1 2 0). The daunting part is that diverging from regular s-expressions would probabbly require preprocessing using a non-Clojure tool, which opens a can of worms. So it is not necessarly a good idea, but certainly intruiging. My point is that I'm excited about the possibilities Clojure offers in providing a truely extensible language which is ultra-ubiquitous and interoperable. In setting up the Java3D spinning box I realised that in imperative languages it is really quite convenient to be able to declare scoped variables as you go. I recognise that I have to change my thinking about programming structure to be a good Lisp programmer, but bear with me. It is quite common in Algo to see int x=5; x=x+1; int y=2; return x+y; AFAIK this takes a bit of thinking and refactoring to do it the Lisp way... I seem to end up putting a great big let at the start (as though I were writing old style C and declaring all my variables at the top of a function) and then trying to work around that. This is kind of unavoidable when using somthing like a 3D API because things have to happen in steps, and the structures and operations are predefined. I think the reliance on this "old style C LET" is unavoidable when using proper s-expressions with imperitive APIs. My understanding of why "just in time" variable declarations (aside from globals) don't exist in Lisp systems is that they are the domain of stack allocation, whereas closure doesn't work well with the stack. I'm sure there must be a way to perculate inline variables up to a top level LET at least, again this would have to be done by a pre-compiler though so yikes. The really neat things about Clojure seem to be the threading and data structures, so I'm looking forward to being further impressed as I learn more about Clojure and start using Clojure language features proper. Really great language/implementation, I applaud you. Here is the Java3D source, its not particularly interesting as it is just Clojurised Java. I'm simply amazed that using a complex library can be so seamless from inside Clojure. (import '(java.awt Frame BorderLayout GraphicsConfiguration) '(java.applet Applet) '(javax.media.j3d BranchGroup Canvas3D Transform3D TransformGroup RotationInterpolator Alpha BoundingSphere) '(javax.vecmath Vector3d) '(com.sun.j3d.utils.universe SimpleUniverse ViewingPlatform) '(com.sun.j3d.utils.geometry ColorCube) '(com.sun.j3d.utils.applet MainFrame)) (defn create-scene-graph [] (let [ rotate (Transform3D.) obj-rotate (TransformGroup.) obj-spin (TransformGroup.) obj-root (BranchGroup.) rotator (RotationInterpolator. (Alpha. -1 4000), obj-spin, (Transform3D.) 0.0 (* (.PI Math) 2))] (.setEuler rotate (Vector3d. (/ (.PI Math) 4.0) (/ (.PI Math) 5.0) 0)) (.setTransform obj-rotate rotate) (.setCapability obj-spin (.ALLOW_TRANSFORM_WRITE TransformGroup)) (.addChild obj-spin (ColorCube. 0.4)) (.addChild obj-rotate obj-spin) (.addChild obj-root obj-rotate) (.setSchedulingBounds rotator (BoundingSphere.)) (.addChild obj-spin rotator) obj-root)) (let [ canvas (Canvas3D. (.getPreferredConfiguration SimpleUniverse)) universe (SimpleUniverse. canvas) app (Applet.)] (.setLayout app (BorderLayout.)) (.add app "Center" canvas) (.setNominalViewingTransform (.getViewingPlatform universe)) (.addBranchGraph universe (create-scene-graph)) (MainFrame. app 256 256)) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---
