(define (p) (p))
(define (test x y)
(if (= x 0)
0
y))
(test 0 (p))
(define (a-plus-abs-b a b)
((if (> b 0) + -) a b))
When the if function is evaluated, based on the condition, the operator + or - is applied on the operands a and b. If b > 0, + operator is used, evaluating to a+b. Otherwise, - operator is issued which yields a-b. Ultimately, we evaluate a+|b|.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (sq x) (* x x)) | |
; sq | |
(define (sumsq x y) (+ (sq x) (sq y))) | |
; sumsq | |
(define (largest2sq a b c) | |
(cond ((and (<= a b) (<= a c)) (sumsq b c)) | |
((and (<= b a) (<= b c)) (sumsq a c)) | |
(else (sumsq a b)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5))))) | |
(* 3 (- 6 2) (- 2 7))) | |
; -37/150 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 | |
; 10 | |
(+ 5 3 4) | |
; 12 | |
(- 9 1) | |
; 8 | |
(/ 6 2) |
NewerOlder