0

I am new to LISP, is there a way of using mod with control structures, if statements.

for instance having (if (mod 4 2) (+ 2 2) (- 9 2)). What does the expression return, 0, nil, T?

sds
  • 58,617
  • 29
  • 161
  • 278
  • What do you mean by "parameter"? do you have a Lisp environment where you can test things, like CCL, SBCL, CLISP, or maybe a Scheme/Racket environment? What source of documentation do you have? – coredump Nov 07 '18 at 16:59

1 Answers1

2

In Lisp, the only false value is nil, so 0 is true. Thus (mod 4 2) returns 0 which is true which means that

(if (mod 4 2)
    (+ 2 2)
    (- 9 2))

returns 4, while

(if (/= 0 (mod 4 2))
    (+ 2 2)
    (- 9 2))

returns 7.

sds
  • 58,617
  • 29
  • 161
  • 278
  • I wrote the second if statement and it threw an error –  Nov 07 '18 at 17:40
  • @mark.b: you need to copy and paste the error and also specify your environment as coredump requested. – sds Nov 07 '18 at 17:58