by kotutku · 6y ago · 0 comments
A question to fellow Lispers: is there a good reason why LISPs do not put parenthesis they way we know from math? Why `(f foo bar)` and not `f(foo bar)`?
Because the first is a list and the second isn't. The whole point of LISP is to represent code as data, and the fundamental data structure it uses is a list.
What you're describing is called in Lisp circles "m-expressions".
s-expressions were supposed to be an implementation detail, and programmers were expected to use m-expressions in the day-to-day.
No one ever got around to implementing them, though, and if you spend enough time working with Lisp, you'll most likely understand why.
Because (cons 1 (cons 2 (cons 3 nil))) is a list and f (x y) isn't. You could put parens around the latter to make it (f (x y)), but then you might as well save a pair of parens and just write (f x y).
If it's inside a list already, yes. But if it's just an expression all by itself, it's not even well-formed in LISP, since it's not a list.
For fuck's sake, these things don't mean anything by themselves. The only reason they mean different things is because the syntax is defined this way. So back to the original question, why is the syntax defined this way?
Not really.
(1 2 3) is a list in Lisp.
(cons 1 (cons 2 (cons 3 nil))) is code to produce a list.
if we have
(append '(1 2 3)
(cond 1 (cons 2 (cons 3 nil))))
The first is a literal list and the second one is code, which produces a list at some point in time - maybe at runtime.> Lisp looks strange not so much because it has a strange syntax as because it has no syntax; you express programs directly in the parse trees that get built behind the scenes when other languages are parsed, and these trees are made of lists, which are Lisp data structures.
The math notation we commonly use is mostly a legacy notation, invented before we had computers and could do (or conceive of) symbolic processing. We write `f(foo, bar)` instead of `(f foo bar)` not because the former is better, but because it's been established before we invented trees (data structures) and figured out why they're important.
def(fact(n acc)
if(=(n 0)
acc
fact(-(n 1) *(acc n))))
I'm not a fan.sweet expression .. I forgot the name, made the top level forms parens-less
define fact(n)
(if ... )
some other hacks include back-shifting any parens by one symbol to turn <fn>(...) into (<fn> ...)honestly I'm 'astonished' that the sexp debate never dies, no lisper cringes at sexp for more than a week (especially with a structural editing mode)