Jump to content

Common Lisp Help...

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
totonex

totonex

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
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 it,
and i've already found it to be absolutely charming !!!

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I think LISP is a remarkably elegant language, so go for it.

With that said, your second if statement never gets "executed". If the first if statement fails, it simply returns NIL and you are done. Your second if statement needs to take the place of NIL in the first.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
totonex

totonex

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
Thank you for the help...really need a little time to get acquainted with the new if/else logic. (...having 'grown up' in the C-family languages).
Let me rephrase my question, can you feed your wife and children with LISP? As you can with PHP/C#?

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
If you do freelance work, you can often code in whatever language lets you get the job done. If you're looking for a 9-5 job working for someone else, it will still give you some interesting ways to think about problems and help you think outside the box.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog