diff --git a/zapiski/2_g1smo.scm b/zapiski/2_g1smo.scm new file mode 100644 index 0000000..67e5bcc --- /dev/null +++ b/zapiski/2_g1smo.scm @@ -0,0 +1,24 @@ + (define (sum-rec term a next b) + (if (> a b) + 0 + (+ (term a) + (sum-rec term (next a) next b)))) + + (define (sum term a next b) + (define (iter a result) + (if (> a b) + result + (iter (next a) (+ result (term a))))) + (iter a 0)) + +(define (cube n) (* n n n)) +(define (inc n) (+ n 1)) +(define (sum-cubes a b) + (sum cube a inc b)) +(define (sum-cubes-rec a b) + (sum-rec cube a inc b)) + +(display (sum-cubes-rec 1 10)) +(display "\n") +(display (sum-cubes 1 10)) +(display "\n") diff --git a/zapiski/3_g1smo.org b/zapiski/3_g1smo.org new file mode 100644 index 0000000..cdf53ef --- /dev/null +++ b/zapiski/3_g1smo.org @@ -0,0 +1,28 @@ +#+TITLE: Zapiski #2 srečanja programerskega bralnega krožka SICP +#+AUTHOR: Jurij +#+OPTIONS: toc:nil num:nil author + +* Teme +** Funkcije višjega reda + +* Vaje +** 1.29 Simpsonovo pravilo +#+begin_src scheme +#+end_src + +** 1.30 linearen sum + +#+begin_src scheme + (define (sum term a next b) + (if (> a b) + 0 + (+ (term a) + (sum term (next a) next b)))) + + (define (sum-iter term a next b) + (define (iter a result) + (if (> a b) + result + (iter (next a) (+ result (term a))))) + (iter a 0)) +#+end_src