Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

But why would you care about those trailing parentheses?


Readability. By properly indenting the parentheses and putting them on lines you will at a glance see which contexts you just closed, that is how people format code in every mainstream language.


None of these 'mainstream' languages use a data structure for writing and manipulating code like Lisp. The use of Lisp is thus very different and Lisp programmers find a more compact notation more useful.

> you will at a glance see which contexts you just closed

the text editor does that for me

> how people format code in every mainstream language

Python code formatting looks different from Java code formatting.

Python code:

  for h in range(0, height):
      for w in range(0, width):
          v = bw_image.getpixel((w, h))
  
          if v >= avg:
              bm_image.putpixel((w, h), white)
          else:
              bm_image.putpixel((w, h), black)
Lisp code just looks like that. Only with added parentheses (because Lisp expressions are written as nested lists) and prefix notation:

  (dotimes (h height)
    (dotimes (w width)
      (setf v (get-pixel bw-image w h))

      (if (>= v avg)
          (put-pixel bm-image w h while)
          (put-pixel bm-image w h black))))


Python also formats their parentheses the non lisp way. You typically format things like this:

  data = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9, [10, 11, 12]]
  ]
Any language that uses closing symbols formats them that way, in Pyhton in Java, in C etc. Lisp is the only example where they don't properly indent closing symbols and instead just put them all together at the last statement.


Yet most Python code is written in the compact form I've showed you, where code indentation is significant. Lisp has the same model: the code indentation is significant. But Lisp has the structure encoded in nested lists. These nested lists are automatically formatted in the same space saving way as Python code. Due to the significant indentation, Python usually can avoid to have grouping characters/symbols.

I see also lots of Python code where data isn't written like you claim...

https://www.programiz.com/python-programming/matrix


With lisp is it not more common to use paredit or similar? I.e. you don’t edit code like in other languages.

As you barf and slurp, you’re interested in the “shape” of code but you ignore the parens.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: