It's obvious to anyone who is familiar with both.
(f x y)
vs f(x, y);
Note the extra comma and semicolon. The only place this breaks down is for simple arithmetic expressions like (+ a b) vs a + b, which is trivial enough to ignore (and also goes back in favor of Lisp when you start having more operands).
As someone who likes lisps, visual separation is helpful. I tend to find complicated Lisp code just blends together into syntax soup
How would you write this in Lisp without introducing a bunch of parens? `if (0 <= x + m && x + m <= n) {…}`
I’m not a Lisp hater, but there’s a reason people make this criticism. I think most people find the infix version easier to read.
I unwittingly chose an example that allowed you to write fewer s-expressions in Lisp… touché.
I've been working on this for TXR Lisp. The next, release 300, will support infix.
The core expression in your example expression will parse as you have written it. Except we have to add ifx:
Though it doesn't work since it's not a complete example with defined variables, we can quote it and expand it to see what the expansion looks like, which answers your question of how you write it one underlying Lisp: The ifx macro deosn't have to be used for every expression. Inside ifx, infix expressions are detected at any nesting depth. You can put it around an entire file: Autodetection of infix add some complexity and overhead to the code walking process that expands macros (not to mention that it's newly introduced) so we wouldn't want to have it globally enabled everywhere, all the time.It's a compromise; infix syntax in the context of Lisp is just something we can support for a specific benefit in specific use case scenarios. It's mainly for our colleagues who find it a barrier not to be able to use infix.
In this particular infix implementation, a full infix expression not contained inside another infix expression is still parenthesized (because it is a compound form, represented as a list). You can see from the following large exmaple that it still looks like LIsp; it is a compromise.
I took an example FFT routine from the book Numerical Recipes in C and transliterated it, to get a feel for what it's like to write a realistic numerical routine that contains imperative programming "warts" like using assignments to initialize variables and such:
It was very easy to transliterate the C code into the above, because of the infix. The remaining outer parentheses are trivial.A smaller example is a quadratic roots calculation, from the test suite. This one has the ifx outside the defun:
sqrt is a function, but treated as a prefix operator with a low precedence so parentheses are not required.It is only function calling that needs (,); in C and () in Lisp. Which is half as many characters, but much much much noisy since:
Look at the example on the Janet page transcribed to Python syntax [0]. Several differences: Also in theory you could manipulate Python AST the same way you do in Lisps both in your editor and both at program-level. In practice you can't do that.[0] : https://news.ycombinator.com/item?id=34846516
Ok, let's compare looping
vs C has the same number of parentheses and also has curly brackets. C additionally has a bunch of semicolons and a comma not present in the Lisp version. The C version is also omitting the required function encapsulation to actually run this, while the Lisp version can be run as a top level expression.The comparison really isn't even close. If you really want, you can always put the trailing )) on new lines like people do with the trailing }}}} for their nested if in a for in a method in a class in C-like languages. The Lisp community has just decided that putting single characters on new lines like that is needlessly noisy and emphasizes characters that are easily ignored by humans and instead manipulated using structural editing.
> The comparison really isn't even close.
IMO it's close. Lisp isn't much worse than other languages. Tho it needs special syntax for some common constructs. It helps the human.
Regarding the for loop, if you only loop one statement, you do
If you loop several statements, you do again, lisp lacks the syntax to group several statements together. In C it ends with );} , indicating a function call inside a control flow or a block. In lisp ))) can be anything from function definition to assigning variables or arrays/collections or anything.