Sujet : Re: Command Languages Versus Programming Languages
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.unix.shell comp.unix.programmer comp.lang.miscDate : 02. Apr 2024, 17:18:24
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240402084057.881@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 2024-04-02, Stefan Ram <
ram@zedat.fu-berlin.de> wrote:
Johanne Fairchild <jfairchild@tudado.org> wrote or quoted:
You don't seem to much of a Lisp writer. Lisp writers have no problem
reading that indentation.
>
Well, there is the expression "write-only code", which shows
that a good Lisp writer may not necessarily be a good reader.
>
This is an example of LISP code:
>
( SETQ DIFF
( LAMBDA( X )
( COND
( ( ATOMP X )
( COND
( ( = X 'X )
1 )
( T
0 )))
( T
( COND
( ( =( CAR X )'SUM )
( LIST 'SUM( DIFF( CADR X ))( DIFF( CADDR X )))))))))
>
. For someone who has not learned LISP, this is difficult to read,
/not/ because of the indentation, but because the words used have no
meaning for him. Without the indentation it would be harder to read.
I know all the words. It's still hard to read because of the weird
spaces.
This is the way of writing the code that the vast majority of the Lisp
word since gravitated toward:
(SETQ DIFF
(LAMBDA (X)
(COND
((ATOMP X)
(COND
((= X 'X) 1) ;; unnecessary line breaks shored up here
(T 0)))
(T
(COND
((= (CAR X) 'SUM)
(LIST 'SUM (DIFF (CADR X)) (DIFF (CADDR X)))))))))
The code is from just before MacCarthy invented the ternary IF, as a
shorthand for a one clause cond:
(SETQ DIFF
(LAMBDA (X)
(IF (ATOM X)
(IF (= X 'X) 1 0)
(IF (= (CAR X) 'SUM)
(LIST 'SUM (DIFF (CADR X)) (DIFF (CADDR X)))))))
Also, modern cond clauses are not strictly pairs,
which allows the T to be omitted:
(cond (this that) (else)) ;; rather than (t else)
when a cond clause consists of a single expression, then if that
expression is true, cond stops and yields that expression's value.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca