Math papers usually use neither the first nor the second.
they use:
(a + b)(c + d)
in the example you propose, and, reversing the operators so that the first style would have: (+ (* a b) (* b c))
and the second: (a * b) + (c * d)
math papers would usually have: ab + cd
So, I'm not sure "math papers do it differently" is the argument you want to use to advance your second syntax over the first.Of course, since in lisp + and * are variadic rather than binary operators, they are a lot more like the pi and sigma operators applied to sets in mathematics than binary operators. Which are prefix, not infix. So, there's that.
(* (+ a b)
(+ c d))
Which is readable, though not necessarily compact.Also, * and + in the former, aren't strictly the same as in the latter. * and + take an arbitrary number of parameters in CL. From [0], `(* )` => `1`. I can't test, but I believe `(* 2)` => `2` (the spec doesn't describe the case of a single parameter, unless I'm missing it). `+` is the same, but `(+)` => `0` instead, it's identity value.
Order of operations is made more explicit, and, I've found, it's more useful to think of `+` and `*` as `sum` and `product` rather than `plus` and `times`.
[0] http://www.lispworks.com/documentation/HyperSpec/Body/f_st.h...
[1] http://www.lispworks.com/documentation/HyperSpec/Body/f_pl.h...
I would venture to say that the reason infix notation is naturally preferred is related to our psychology, the same way most human languages are SVO (Subject Verb Object) or SOV. VSO languages (Lisp like) are less prevalent.
In general my opinion is that when a majority vastly prefers one alternative, there is usually a strong reason for it (even if it may be irrational) and it's foolish to go against the grain.
Java is SVO.
C is VOO too.
$ sbcl
This is SBCL 1.2.4.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
> (ql:quickload 'infix)
; Loading package
(INFIX)
> #i(1 + 1) ; addition
2
> #i(2^^128) ; exponentiation
340282366920938463463374607431768211456
> (defun factorial (x)
#i(if x == 0 then
1
else
x * factorial(x-1))) ; infix function call
FACTORIAL
> (factorial 5)
120
> #i(factorial(5) / factorial(6))
1/6
> '#i((a + b) * (c + d)) ; Put a ' before the #i() to see what code is generated
(* (+ A B)
(+ C D))
--[1] - https://www.quicklisp.org/beta/ [2] - Don't know if there is a similar package for Scheme.
I have to agree with others in the thread that infix in Lisp/Scheme is not the convention, and IMO an awkward fit. Don't recall encountering infix in any published/shared code I've seen, it may exist, but to learn Scheme becoming comfortable with s-expr notation is definitely necessary.
However, there is SRFI 105[0] which describes "curly infix expressions". It's implemented in Guile 2.x, possibly available in a few others but evidently not had a lot of uptake among Schemes.
[0] http://srfi.schemers.org/srfi-105/srfi-105.html
Edit: added URL
Pretty much the whole language is based on Polish notation. The sooner you realise that + - * / are just function names like any other, the better you'll do.
For example:
(+ 1 2 3)
in plain symbols is just:
(function parameter parameter parameter)
But if I were to write my own addition function:
(addition 1 2 3)
it would also be:
(function parameter parameter parameter)
and so is:
(http-request "http://www.google.com")
(function parameter)
If you use infix notation, you're writing half your code in a competely different semantic to the other half. I can't imagine it helping people really get a proper grasp of how Common Lisp works.The Lisp syntax is so incredibly controversial, and that fact itself is incredibly strange to me. I see it as a pragmatic engineering decision: let's represent source code as syntax trees, and then sophisticated editing modes become straightforward, macros become straightforward, and the syntax becomes very uniform.
This big thread indicates another reason Lisp isn't popular: because people keep arguing back and forth about the textual syntax, rather than discussing actual experiences with using it.
Symbols and lists behave differently depending on the context:
Examples for Lisp snippets:
(foo bar baz) ; it could be a macro, function or special operator form
(quote (foo bar baz)) ; here it is data
(defun do-something (foo bar baz) (a b c)) ; here it is an arglist
(defun do-something (a b c) (foo bar baz)) ; one element later it is a form
These context need to be learned and actual visual clues are a) the symbol in front and b) the structure of the expression.This is puzzling for a lot of people. A few never really take that hurdle.
(+ x y z a) instead of (x + y + z + a)
Also, there are no order of operations problems with the lisp syntax like there are with traditional mathematical notation (unless you use parens, which makes it look even more lispy).Therefore I would say the answer is simply familiarity and concern for the audience.
(+) 4 2
vs.
(+) <$> Just 4 <*> Just 2
I usually prefer the applicative style above to liftA2 (+) (Just 4) (Just 2)
because it preserves the "form" of the original expression and generalizes to more arguments. ie. it doesn't require liftAn for whatever n number of arguments my function takes.Indeed, most math syntax (in my experience) has a very explicit reason why it's used: historical circumstance, convention and common tradition.
As a mathematician I'd love to use it in my papers, but no reviewer would accept such a paper.
But I'd like to point out that in your second example the parentheses are needed because infix notation is inherently more complicated.
In the first example however, the notation is far simpler: a simple list of function plus zero or more arguments.