Hacker News new | ask | show | jobs
by fexl 5764 days ago
If you use Vim and have "showmatch" enabled, then when you move your cursor onto a left or right parenthesis, it shows that character with a charcoal background, and the matching parenthesis with a teal background. Your mind immediately perceives the extent of the expression. Then if you press "%", your cursor moves to the matching parenthesis. You can toggle back and forth by pressing "%" repeatedly. This also works for braces and square brackets. Also you can delete, change, and yank whole expressions with the usual idioms "d%", "c%", and "y%".

I'm not arguing Vim over Emacs here, I just wanted to point out that Vim has excellent support for parenthesized expressions.

Interestingly, when I write procedural code such as C or Perl, I put a single brace on each line. For example:

  if (condition)
      {
      ...
      }
That makes it easier for me to move whole blocks around.

However, when I write functional code such as Lisp or Fexl, I tend not to do that. For example:

  # Collect any matching entries at the front of the list.

  \collect = (\match\list list end \head\tail
      match head (item head (collect match tail)) end)
I think that's because I tend to keep all my Fexl expressions very short, building them up step by step.

Also, Fexl uses ";" as a "right-pivot" operator. For example:

  \collect = (\match\list list end \head\tail
      match head (item head; collect match tail) end)
So in many cases I can avoid multiple right parentheses. The Clojure example in the article would become:

  \myfn-a = (\a\b zero? b a;
      recur (afn (bfn (...)) a) (dec b))