(define f1 3 ) (define (sab a b) (+ a b) ) ;koji su tipovi podataka? ; 1. celobrojni ; 2. realni ; 3. logicke promenljive ; 4. string ; 5. simboli 1 4.5 true #t #f "Ovo je string" 'Simbol (define (maks a b) (cond ((> a b) a) (else b) ) ) ;ispituje da li je broj paran (even? 7) ; -> #f ;funkcija faktorijela (define (fakt1 n) (cond ((= n 0) 1) (else (* n (fakt1 (- n 1)))) ) ) ;(f n) -> (f n-1)....-> (f 0) ;ovo je varijanta sa linearnim stekom ;napisati efikasniju verziju faktorijela ;hocemo verziju sa konstantim stekom (define (fakt2 n a) (cond ((= n 0) a) (else (fakt2 (- n 1) (* n a)) ) ) ) ;akumulacioni parametar se menja na sl. nacin ; a -> n*a -> n*(n-1)*a....->n!*a (define (fakt3 n) (fakt2 n 1) ) (define (sum-coins k1 k2 k5 k10 k20) (+ (* k20 20) (* k10 10) (* k5 5) (* k2 2) k1) ) (define Pi 3.14159265 ) (define (area-cylinder r h) (+ (* 2 (* r r) pi) (* r pi h)) ) ;(cond ; ((uslov1) aktivnost1) ; ((uslov2) aktivnost2) ; ... ; (else (podrazumevana_aktivnost)) ;) (define (diskr a b c) (- (* b b) (* 4 a c)) ) (define (what-kind a b c) (cond ((= a 0) 'Degenerisana) ((> (diskr a b c) 0) 'Dva) ((= (diskr a b c) 0) 'Jedno) ((< (diskr a b c) 0) 'Nema) ) ) (define-struct tp (h m s)) (define tp1 (make-tp 1 2 3)) (define tp2 (make-tp 4 5 6)) (define (seconds tpx) (+ (* 3600 (tp-h tpx)) (* 60 (tp-m tpx)) (tp-s tpx)) ) (define (time-diff ts te) (- (seconds te) (seconds ts)) ) (define-struct pos (x y)) (define-struct circle (c r)) (define p1 (make-pos 1 2)) (define circle1 (make-circle p1 5)) (define circle2 (make-circle (make-pos 2 3) 6)) ;implicitni predikat koji se kreira za ;svaku od nasih struktura ;(circle? c1) ;(circle? p1)