Sujet : Re: Which code style do you prefer the most?
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 05. Mar 2025, 20:12:16
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250305105755.685@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-03-05, Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> wrote:
On 05.03.2025 09:39, Richard Heathfield wrote:
On 05/03/2025 08:35, Janis Papanagnou wrote:
There's a reason why I dislike languages whose syntax is cluttered
with parentheses
(I (bet ((you ((jutht) love) Lithp).)))
>
With my first glimpse of lithp code I immediately felt repelled, erm..,
wrong word - I meant: felt deep and long lasting _respect_ for it. :-)
>
But I know there are folks who really love it. - That's fine by me.
>
(It's always good if you have options to choose from.)
Lisp offers ways to break long expressions in multiple ways,
all falling under the same general algorithm that is easy supported
in your editor.
That's why I posted that example:
(when (or (and (/= a b)
(/= c d)
(/= e f))
(and (= g (* (h)
(i)))
(= j k)))
(foo))
You just don't have these stylistic issues about where to put
the operator relative to the operand. Is it:
a ||
b
or
a
|| b
or
a
||
b
etc.
Using a few keystrokes, I can turn it into
(when
(or
(and
(/= a b)
(/= c d)
(/= e f))
(and
(= g
(* (h)
(i)))
(= j k)))
(foo))
Or
(when (or (and (/= a b) (/= c d) (/= e f))
(and (= g (* (h) (i))) (= j k)))
(foo))
The editor reindents everything. I mean right here. I'm in Vim typing
a .followup file. I just went into :set lisp mode, and there it is.
The Lisp code gives us a tree view where we can clearly see that there is a
main (or ...) node which has two (and ...) children. It has the
same shape as a tree control in a GUI:
or +-- and +-- (/= a b)
| |
| +-- (/= c d)
|
+-- and +-- = +-- g
|
+-- * +-- (h)
|
+-- (i)
If we draw it using logic symbols (and gates, or gates), it will look similar
also, (with the signals going right to left).
In recent years (well nearly a decade ago now), there has been a new
development in Lisp editing: the "parinfer" algorithm by Shaun LeBron. Parinfer
operates in two modes: you can control the indentation and it automatically
supplies the parentheses, on the fly. Or you can control parentheses and it
reindents as you type.
The original home page is here, featuring animations:
https://shaunlebron.github.io/parinfer/It has been implemented in many editors. I use a somewhat shabby Vim
implementation of it nowadays which only works reliably in the
indent -> parens mode.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca