• Formatting LISP Code

    From Lawrence D'Oliveiro@21:1/5 to All on Tue Jan 2 01:28:49 2024
    I’m not a fan of the “parenthesis pileup” tradition of LISP code
    layout. Having used a number of different programming languages over
    the years, I have evolved a common set layout conventions that has
    worked reasonably well across them. So for example, when parentheses
    in LISP represent something resembling statement blocks, I like to put
    the openers and closers at the same indentation level, which means
    putting the closer on a line by itself. This, accompanied by a comment indicating the type of construct being closed, I think helps a lot
    with readability. Elisp example:

    (defun convert-to-region-codes (beg end)
    "converts alphabetic characters in the selection to “region indicator symbols”."
    (interactive "*r")
    (unless (use-region-p)
    (ding)
    (keyboard-quit)
    ) ; unless
    (let
    (
    deactivate-mark
    (intext (delete-and-extract-region beg end))
    c
    )
    (dotimes (i (- end beg))
    (setq c (elt intext i))
    (cond
    ((and (>= c ?A) (<= c ?Z))
    (setq c (+ (- c ?A) #x1F1E6))
    )
    ((and (>= c ?a) (<= c ?z))
    (setq c (+ (- c ?a) #x1F1E6))
    )
    ) ; cond
    (insert-char c)
    ) ; dotimes
    ) ; let
    ) ; convert-to-region-codes

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Lawrence D'Oliveiro on Tue Jan 2 06:30:40 2024
    On 2024-01-02, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
    I’m not a fan of the “parenthesis pileup” tradition of LISP code layout.

    Well, you came to the right language. Odds are high that you will be
    working alone in Lisp (not called LISP for a few decades now, by the
    way).

    So you will never run into a situation in which you're asked
    to produce normal looking code ending in ))))) pringles.

    (Unless you do something silly, like contribute a patch to someone
    else's existing project.)

    Having used a number of different programming languages over
    the years, I have evolved a common set layout conventions that has
    worked reasonably well across them. So for example, when parentheses
    in LISP represent something resembling statement blocks, I like to put
    the openers and closers at the same indentation level, which means
    putting the closer on a line by itself. This, accompanied by a comment indicating the type of construct being closed, I think helps a lot
    with readability. Elisp example:

    (defun convert-to-region-codes (beg end)
    "converts alphabetic characters in the selection to “region indicator symbols”."
    (interactive "*r")
    (unless (use-region-p)
    (ding)
    (keyboard-quit)
    ) ; unless
    (let
    (
    deactivate-mark
    (intext (delete-and-extract-region beg end))
    c
    )
    (dotimes (i (- end beg))
    (setq c (elt intext i))
    (cond
    ((and (>= c ?A) (<= c ?Z))
    (setq c (+ (- c ?A) #x1F1E6))
    )
    ((and (>= c ?a) (<= c ?z))
    (setq c (+ (- c ?a) #x1F1E6))
    )
    ) ; cond
    (insert-char c)
    ) ; dotimes
    ) ; let
    ) ; convert-to-region-codes


    You forgot a few, for instance:

    ((and (>= c
    l?A) ;; >=
    (<= c
    ?Z) ;; <=
    ) ;; and
    (setq c
    (+ (- c
    ?A
    ) ;; -
    #x1F1E6
    ) ;; +
    ) ;; setq
    ) ;; cond pair

    You go show `em how it oughtta be formatted!

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca
    NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Kaz Kylheku on Tue Jan 2 06:43:40 2024
    On Tue, 2 Jan 2024 06:30:40 -0000 (UTC), Kaz Kylheku wrote:

    On 2024-01-02, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:

    So for example, when parentheses in LISP represent something
    resembling statement blocks, I like to put the openers and closers at
    the same indentation level, which means putting the closer on a line
    by itself.

    You forgot a few, for instance:

    Would you say those were “resembling statement blocks”?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)