Merry Christmas everyone!
I'm using Lisp in a Box (emacs + GC Lisp)
And i tried making a function which takes a number as argument, adds 1 to it if it's negative, and substracts 1 from it if it's positive.
(look)

(defun enlarge(x)
           (if (< x 0) (- x 1) nil)
           (if (> x 0) (+ x 1) nil)
           )

Yes, i know, should have made everythin in one IF, but i wanted to have 2 separate IF's for strictly positive and strictly negative numbers (too see what happens if the user enters 0)
Nevertheless:

CL-USER> (enlarge 5)
6
CL-USER> (enlarge -3)
NIL

This is what i get. Why??
Thank you.
;;;Btw, is it worth learning LISP? I've started learning little bits from a book, and i've already found it to be absolutely charming !!!
(Even though i've been 'growing up' with C/C++ syntax)

Edited 6 Years Ago by TotoTitus: n/a

Never mind, someone helped me figure out the problem - it seems the second IF was never evaluated, and i should have instead used the ELSE part of the first IF.

I would have suggested the following:

(defun enlarge ( x ) 
  (cond
    ( (< x 0) (- x 1) )
    ( (> x 0) (+ x 1) )
    ( T nil )
  )
)

Edited 6 Years Ago by Ghost_Buster: n/a

Never mind, someone helped me figure out the problem - it seems the second IF was never evaluated, and i should have instead used the ELSE part of the first IF.

No, both IFs were evaluated. The result of the first was discarded.

I would have suggested the following:

(defun enlarge ( x ) 
  (cond
    ( (< x 0) (- x 1) )
    ( (> x 0) (+ x 1) )
    ( T nil )
  )
)

You should stop being a special snowflake and put your parentheses where everybody else puts them.

(defun enlarge (x)
  (cond
    ((< x 0) (- x 1))
    ((> x 0) (+ x 1))
    (t nil)))

First I'm not everybody
Then I don't like the way you put your parentheses because one cannot match opening and closing parentheses at a glance
Finally, you do as you wish and I'll do as I wish!

First I'm not everybody
Then I don't like the way you put your parentheses because one cannot match opening and closing parentheses at a glance
Finally, you do as you wish and I'll do as I wish!

It doesn't matter. After using Lisp for a while you'll end up changing your mind and deciding that the way everybody else does it is better.

Just for your information, I've been using LISP for 26 years now and I'm still convinced that I prefer my method.... Lisp is one of the oldest programming language available in AutoCAD and I'm a CAD programmer ... full time (using LISP that is)!

I'm even worst (to your stand point) than that!
I put comments after every close parentheses....

Edited 6 Years Ago by Ghost_Buster: n/a

This question has already been answered. Start a new discussion instead.