On Friday 28 November 2008 15:54, Dmitri wrote: > First of I'd like to say that I find Clojure to be an excellent > language, however I find the lack of infix operators makes reading > equations somewhat unnatural, eg: > > (+ (- (* x x) (* y y)) a)
Try this: (+ (- (* x x) (* y y)) a) Crushing expressions into small spaces is not a virtue in either infix or prefix. > I ended up writing a simple function to handle infix notation > > (defn infix [arg1 func arg2 & args] > (let [result (func arg1 arg2)] > (if (= args nil) result (recur result (first args) (second > args) (rrest args))))) > > using that I find makes the code more readable: > > (infix (infix x * x) - (infix y * y) + a) If you're not going to parse fully arbitrary arithmetic expressions according to the usual (which may as well be arbitrary) operator precedence, then it's hardly worth it. And it seems to me that the syntactic significance of parentheses in infix notation is completely at odds with their role in prefix / S-Expression notation. Thus it seems that the two are not really compatible. Ultimately, the superiority of infix notation obtains only in a very narrow and restricted subset of expressions and this does not, in the end, justify its incorporation into a fine, elegant language based on S-Expressions. > I was wondering if there is a more elegant way to do this, and if it > could be added as a standard or contrib function. I don't think so. I would not mind being shown wrong, but I really don't think so. As an aside, I'll mention that I read a lot of papers in the domain of mathematical logic. There the operators are quantifiers (always prefix), boolean connectives (unary, nonassociative binary or associative / commutative binary operators) and named predicates and functions. The convention in such publications is to use prefix for the unary operators, infix for the nonassociative and A/C binary operators with a conventional operator precedence and prefix using fully parenthsized argument lists for named predicates and functions (with the usual gratuitous parentheses separating arguments). And I'll tell you, only the simplest such formulas are readily comprehensible. Using a KIF- or CLIF-like notation (which would appear to be Lisp-like to denizens of this list) would immensely improve the comprehensibility of these publications! Randall Schulz --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---