On 05.03.2009, at 02:03, Elena wrote: > I wonder if Clojure does employ the same syntax either for macros and > functions by design or it's just a remainder of Lisp. I think that a
I am sure it's by design, just as for Lisp. Remember that Lisp has been around for 50 years and has been used by some of the most talented programmers on this planet. If Lisp programmers had discovered a need to distinguish visually between macros and functions, some Lisp dialect would already have introduced such a feature. > shared syntax for both macros and functions calls is a flaw in the > syntax of Lisps, because you can't tell, just by looking at a form, For how long have you been using Lisp? I don't want to sound condescending, but this sounds like a typical newcomer's remark. If something bothers you after a year of intensive use, you can call it a flaw, and even then I'd carefully add "in my experience". > Someone says that when you are reading code you are expected to know > the documentation of each form you encounter, but I don't agree. > Usually when I read code I rely heavily on good naming, so I don't > usually need to reach for the documentation. I agree as well. There is a small core set of names for which brevity and convenience outweigh readability, and which everyone should know. Beyond that, the names should hint at their meaning. Let's look at an example: (if (and (odd? n) (> n 0)) n (inc n)) To me, all these names are clear, though inc may not be obvious immediately (but it's a frequently used function). It happens that "if" is a special form, "and" is a macro, and "odd?" and "inc" are functions, as is ">". But this is not the most relevant information about these names, what matters most, to a human reader, is their meaning. Suppose this were written as (IF (And (odd? n) (> n 0)) n (inc n)) to make special forms and macros stand out. Is this better? Not to my eyes. It emphasizes something about "if" that I don't really need to know. "If" could very well be implemented as a macro, in terms of "cond", for example. Some Lisps make that choice, Clojure makes the inverse one, implementing "cond" as a macro in terms of "if". So what? "And" is a more interesting case. To the casual reader, its meaning is pretty clear. But if the details matter... Sometimes it is important to know that "and" evaluates only as many of its arguments as it needs to reach a conclusion. In other words, it stops at the first "false" value and returns false. And that feature alone mandates an implementation as a macro or a special form, a function can't do that. But the important thing I need to know is not that "and" is a macro, it's that it evaluates as few of its arguments as it can, from left to right. Making a syntactic distinction between functions and macros would highlight implementation details and turn attention away from what really matters: the meaning of a form. > Since I'm a C/C++ programmer, my convention is that macros and only > macros are all uppercase, so I can easily spot them and be aware that > they behave differently. C and Lisp are very different languages. Macros are more powerful and more fundamental in Lisp. A lot of the names you use in a Lisp program are actually macros that expand into a small number of primitive functions and special forms. Konrad. --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---