Sujet : Re: Which code style do you prefer the most?
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 06. Mar 2025, 02:22:19
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250305170458.52@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-03-05, Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> wrote:
On 05.03.2025 20:12, Kaz Kylheku wrote:
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. [...]
>
But isn't that a property of every system specified in either
Polish Notation (like Lisp) or Reversed Polish Notation, that
require no parenthesis to evaluate expressions? Interestingly,
Sort of. If we don't have parentheses, then we just have to know
the arity of all the functions.
Lisp syntax can be semantically wrong, yet syntactically correct
and editable. (cons 1 2 3) would be wrong as a function call,
but we can write it, and it will parse. Just like calling
getchar(a,b,c) in C.
In Polish Notation we can use whitespace to show what the
operands are:
or2 and3 /= a b
/= c d
/= e f
and2 = g * h i
= j k
I had to invent or2, and3 and and2 to have a fixed arity, otherwise variadic
funtions need some symbol to look for indicating the end of their
argument list, like "dna" to indicate end of "and":
and /= a b /= c d /= e f dna
If we collapse it into one line, it becomes visually ambiguous.
It can't be automatically reformatted without the reformatter
understanding the arity of everything.
or2 and3 /= a b /= c d /= e f and2 = g * h i = j k
Lisp (employing such a in principle parenthesis-free language)
It doesn't employ an in principle parenthesis-free language.
It employs a data language in which you can write tree nodes
of any arity you want, which can be interpreted as code.
Many functions and operators in Lisp are varaidic.
It's just a function application notation f(x, y, ...)
where the commas have been deleted f(x y ...)
and then the left parenthesis has beem moved to include
the function: (f x y ...) so it's like a command language
with parentheses around commands.
We see a similar thing in the shell command substitution:
var=$(echo a b c $(cat file))
GNU Make:
$(foreach i,a b c,$(addprefix $(i)/foo))
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca