mendy
mendy

Reputation: 191

Lisp - Check if input is Decimal or String

I am printing a triangle of numbers in Lisp and I want to make sure that the input upon calling the function is an integer. If it's a string or a decimal, it should return a message not accepting the input. This is my code for the numbers.

(defun nested-loop (n)
  (loop for i from 1 to n doing
  (loop for j from 1 to i collecting
    (progn
      (prin1 j)))
   (format t "~%")))

(nested-loop 5)

Upvotes: 1

Views: 1571

Answers (1)

Rainer Joswig
Rainer Joswig

Reputation: 139321

Use the macro CHECK-TYPE:

CL-USER 9 > (let ((n "10"))
              (check-type n integer))

Error: The value "10" of N is not of type INTEGER.

Upvotes: 8

Related Questions