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 16:28

>>25
What tutorial did you read? Your use of Lisp shows that you don't know the language too well, there's quite a few better ways to do the task, and more suitable operators for some of the things you typed.

Do you honestly think the way you're indenting it, is easier to read? Oh, and as a 'list processor', you're not really using any lists in your code. Chances are, your code is actually faster than mine (>>12), but less flexible (can only convert 1-39).

My personal experience with Lisp indentation:
The first few days when I started learning the language, it was a bit hard to get used to, but after half a week, I was able to read it fluently, and I prefer it to non-standard indentation styles like yours. I can't read your code at all without reformatting it, it's just plain unreadable to me. You don't need to learn how to indent Lisp code, Emacs and other Lisp editors do it for you. If you refuse to learn to do it, it would:
1)Make you unable to read other people's code, which means: no reading your Lisp's implementation source code or libraries or code by other people, not even code in books. This limits your sources for learning the language a lot, as well as capability to interoperate with other's code.
2)It would slow down the pace at which you write code.

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