A
A
a1a22015-10-23 17:34:54
Lisp
a1a2, 2015-10-23 17:34:54

How does the "if not" construct work in scheme (IEEE)?

sicp
Exercise 1.15

(define (cube x) (* x x x))
(define (p x) (- (* 3 x) (* 4 (cube x))))
(define (sine angle)
    (if (not (> (abs angle) 0.1))
        angle
    (p (sine (/ angle 3.0)))))

(sine 12.15)

what function does "not (>" perform)
how to write the same example correctly without "not" (for it to work)
I will be glad if you explain
in human language to a person who is far from all this.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kitmanov, 2015-10-23
@a1a2

(if (<= (abs angle) 0.1)
The > function returns #t if its first operand is greater than its second. The not function returns #t if its operand is #f, and vice versa.

A
a1a2, 2015-10-23
@a1a2

each time it gave an error when replacing "not"
I already thought that this was such a special construction
now it's clear I just forgot to remove the extra bracket and instead of
(if (<= (abs angle) 0.1) I
wrote
(if (<= (abs angle) 0.1) )
..... well
the issue is resolved

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question