Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

LISP Code Style

Name: Anonymous 2009-11-03 1:50

Hi.  I'm sortof new to LISP, so I'm not that good at it, but i wrote a program that converts decimal numbers into Roman numerals.  It's not that exciting of a programming, but I like making unique little programs that I can use at the oddest times.  LISP is an awesome language, but I think it's harder to read (i made a game in C before this so i'm a C programmer).  I decided to use the C style to make the code look more organized.  I think it makes it easier to read.  It's not GNU style, but I was wondering if the GNU has a format guideline for LISP.  I was thinking of submitting something like this, because it makes LISP code easier to read.

(
    defun roman1
    (
    )
      "Roman numeral conversion with an unordered P.S."
      (
        let
        (
            (
            x nil
            )
        )
            (
            loop
                  (
                cond
                        (
                    (
                        null x
                    )
                    (
                        format t "Enter number:"
                    )
                    (
                        setf x
                        (
                            read
                        )
                    )
                )
                        (
                    (
                        and
                        (
                            not
                            (
                                null x
                            )
                        )
                        (
                            > x 39
                        )
                    )
                             (
                        format t "too big~%"
                    )
                    (
                        setf x nil
                    )
                )
                        (
                    (
                        and
                        (
                            not
                            (
                                null x
                            )
                        )
                        (
                            < x 40
                        )
                        (
                            > x 9
                        )
                    )
                             (
                        prin1 'x
                    )
                    (
                    setf x
                        (
                            - x 10
                        )
                    )
                )
                        (
                    (
                        and
                        (
                            not
                            (
                                null x
                            )
                        )
                        (
                            = x 9
                        )
                    )
                             (
                        prin1 'ix
                    )
                    (
                        setf x 0
                    )
                )
                        (
                    (
                        and
                        (
                            not
                            (
                                null x
                            )
                        )
                        (
                            < x 9
                        )
                        (
                            > x 4
                        )
                    )
                             (
                        prin1 'v
                    )
                    (
                        setf x
                        (
                            - x 5
                        )
                    )
                )
                        (
                    (
                        and
                        (
                            not
                            (
                                null x
                            )
                        )
                        (
                            = x 4
                        )
                    )
                             (
                        prin1 'iv
                    )
                    (
                        setf x 0
                    )
                )
                        (
                    (
                        and
                        (
                            not
                            (
                                null x
                            )
                        )
                         (
                            < x 4
                        )
                        (
                            > x 0
                        )
                    )
                             (
                        prin1 'i
                    )
                    (
                        setf x
                        (
                            1- x
                        )
                    )
                )
                        (
                    (
                        zerop x
                    )
                    (
                        setf x nil
                    )
                    (
                        terpri
                    )
                )
                     )
        )
    )
)

Name: Anonymous 2009-11-03 22:33

>>19
OP here.  I don't get it.  Are you guys saying this is good or bad?  have you guys ever programmed in C? I think its a lot easier to read for a C programming because it is layed out in C style.  Sometimes when I read other people's LISP programs they have 10 statements on one line.  its like trying to read:

while {if ((x > 20) && (x < 40)) { printf("a"); x++; } else { return 0; } }

I knwo there are other standards, but what Im saying is mine is better.

I find the Lisp code easier to read than that C code (which isn't even correct, look at the syntax for the while loop in your example is wrong - I'm assuming while(true) or while(x > 20) && (x < 40)):

(loop
   (cond
     ((< 20 x 40) (princ "a") (incf x))
     (t (return 0))))

(loop
   (if (and (< 20 x)
        (< x 40))
       (progn (format t "a") (incf x))
       0))

(let ((x 21))
  (loop while (< 20 x 40)
     do (progn (format t "a") (incf x)))
  0)

You also stated that you're forced to put everything on the same line, which is just wrong, because if you had a good editor like Emacs, formatting something like:
(+ (* 5 6) (/ 9 8) (- 10 (+ 11 12 13 (1- 16))))
into something more readable, like:

(+
 (* 5 6)
 (/ 9 8)
 (- 10
    (+ 11 12
       13 (1- 16))))

can be done only with a few key presses: moving the cursor around, and pressing enter, that's all.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List