Domn Werner
Domn Werner

Reputation: 602

LISP function to return the greater number

I feel like an idiot asking for help for this, but I have been stuck for hours now, and I haven't been able to find anything on the internet that can help me.

I am trying to write a function in LISP that takes in two parameters and returns the number that is greater. Here's what I have at the moment, but I keep getting errors:

(defun greater (x y)
  (if (> x y) x y))

I am calling it like this:

(greater (2 1))

Upvotes: 0

Views: 3353

Answers (1)

Amal Antony
Amal Antony

Reputation: 6797

I'm not a Common Lisp expert, but I guess the way you are calling greater is wrong. This program works for me:

(defun greater (x y) (if (> x y) x y))

(print (greater 5 12))

Upvotes: 4

Related Questions