4 ms·
> Here’s the same code, but with all parentheses in place: (define (fac x) (if (<= x 0) 1 (* x fac (- x 1)))) Still one pair
by tromp 3y ago
> Here’s the same code, but with all parentheses in place:
(define (fac x)
(if (<= x 0) 1
(* x
fac (- x 1))))
Still one pair missing.
Is it true that in normally formatted LISP code, every line should start with an opening parenthesis?
Btw, I prefer Haskell's syntax of
fac x = if x <= 0 then 1 else x * fac (x-1)
- mtreis86 3y agoNope, lisp doesn't care about whitespace at all, including line endings. The way lisp is read in is as if there was no whitespace, just objects in lists. (foo bar baz) (foo bar baz) (foo bar baz) All the same thing to lisp
- tsimionescu 3y agoThat's not quite right. Lisps care a lot about the presence of whitespace, just not about their type or number. (foo bar baz) is very very different from (foobarbaz). They are identical in this respect to the C family of languages, in fact (the only difference is that they allow newlines in quoted strings, which C languages normally do not).
- samatman 3y agoThe term of art is whitespace insensitive, meaning that whitespace is only necessary when needed to separate tokens, and any amount will do when it's allowed. While it may be possible to write a language in which whitespace may be inserted or left out literally anywhere, I'm unaware of any actual languages where this is true.
- tmtvl 3y agoIn Fortran the following two lines are the same: DO 10 I=1.10 DO10I = 1.10
- samatman 3y agoFortran comes closer than any other language, true. But there's a mandatory six columns of whitespace at the start of every line, so not quite! But the fact that PRO GRAM and such constructs are legal is... special.
- pklausler 3y agoYou are 34 years out of date.
- 12_throw_away 3y agoI feel like the name "Fortran 90" was a missed opportunity, since it got rid of all the old punchcard stuff that people associate with "Fortran".