Nekaj vaj in zapiskov iz 2 in 3

main
Jurij Podgoršek 2024-05-29 18:40:15 +02:00
parent 33e77b3439
commit 7d579b9b12
2 changed files with 52 additions and 0 deletions

View File

@ -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")

View File

@ -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