Hey Everyone, I had typed a long post last night and it somehow was lost. Maybe I'll be more succinct today.
I'm trying to write a macro that will evaluate it's syntax tree where possible and return a tree representing all the calculations that must be performed at run-time. A calculation that could be performed at compile-time would be determining the 5000th prime number or the square of the sine of 33.2 degrees. A calculation that could only be performed at run-time might be processing user input or depend on a variable bound outside of the macro. The macro would be related to clojure.contrib.macros/const and clojure.contrib.template/template but would be automatic in terms of figuring out what can be calculated at compile-time. I understand that this isn't really the intent of macros, and that side effects cannot be permitted within this macro, but I think there are plenty of situations where it might be useful. Functions will be called when all of their arguments are known, macros will be expanded and processed, and special forms will be treated specially. I think there are two approaches: top down, where I try to eval the form and if that exceptions then recurse on the subforms and return their results as a list; and bottom up, where I try to eval the leaves of the code and when a leaf eval exceptions, just return the form. Macros and special forms are going to cause problems in either case since I don't want to necessarily want to evaluate the expressions, so my thought has been to determine if the first subform is a function and if so to recurse on the subforms (more like bottom up) while if the first subform is not a function (well, really ifn? I think) then determine if it is a special form try to do some special processing, such as performing the 'if conditional. One where I'm having trouble is 'let evaluation, which binds new variables.... I'd like to be able to perform calculations on the bound variables but I don't see how I can define them for eval (maybe a dynamic binding would work?). Finally, there's the issue of macros, which I think I should expand and then process again. The expansion could be performed by either eval or macroexpand. What thoughts does anyone have? -- Tim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. 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 -~----------~----~----~----~------~----~------~--~---
