Doubt receive 3 numbers and tell if the first is equal to the sum of the other two in LISP

Asked

Viewed 78 times

1

I’m doing a function in Lisp that receives 3 numbers and says if the first is equal to the sum of the other two, the code I arrived was this:

(defun maior(n1 n2 n3)
  (if (=(+ n2 n3)n1)
  (format t "~D é maior que ~D e ~D!" n1 n2 n3)
)

However, it is not running I believe the problem is in the syntax, I want to show that the sum of n2 and n3 is equal to n1.

  • 1

    In the title of the question, you say you have doubt. What is? Edith your question and show what you have already done and in which part is the doubt.

  • I changed the question friend.. and I put the code that is giving error in my doubt.

  • 1

    It was mto simple, I had forgotten to close the if . -. Thanks for your attention buddy, I’m new here at the forum, I’ll try to ask more elaborate questions next, hugs.

1 answer

2

The parenthesis of the if:

(defun maior(n1 n2 n3)
  (if (=(+ n2 n3)n1)
      (format t "~D é maior que ~D e ~D!" n1 n2 n3)
  )
)

Example in the ideone.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.