Code: Select all
Examples:
(f (f -1)) = 1
(f (f 1)) = -1
(f (f 4)) = -4
(f (f -4)) = 4
(f (f 0)) = 0
Code: Select all
Examples:
(f (f -1)) = 1
(f (f 1)) = -1
(f (f 4)) = -4
(f (f -4)) = 4
(f (f 0)) = 0
Code: Select all
(define-macro (f n)
(- (n 1)))
Code: Select all
(define (f n)
(if (= n) 0 (> n)
(if (odd? n) (inc n) (- (dec n)))
(if (odd? n) (dec n) (- (inc n)))))
Code: Select all
(define (f n)
(if (number? n)
(list n)
(- (n 0))))
Code: Select all
(define (f n)
(cond ((and (> n 0) (even? n)) (- n 1))
((and (> n 0) (odd? n)) (- (- n) 1))
((and (< n 0) (even? n)) (+ n 1))
((and (< n 0) (odd? n)) (+ (- n) 1))
(true 0)))
(f (f 1))
;-> -1
(f (f -1))
;-> 1
(f (f 3))
;-> -3
(f (f -3))
;-> 3
(f (f 0))
;-> 0