Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- ;; LISTA 1
- ;;* Podstawieniowy model obliczeniowy - w miejsce zmiennej podstawiamy zwianna z nia wartosc
- ;;* Racket liczy gorliwie********
- ;; '+ daje #<procedure:+>, ale (+) daje 0
- ;; formy specjalne 'or' i 'and'
- (define (power-close-to b n)
- (define (helper b n k)
- (if (> (expt b k) n)
- k
- (helper b n (+ k 1))))
- (helper b n 0))
- ;; LISTA 2 [ NIE ZROBIŁEM ZADANIE 8 i 9 ]
- ;; Rozróżniać procesy rekurencyjne i iteracyjne!****
- ;; Składniowe wiązanie zmiennych !***;;;;;;;;;;;;!!:;;;
- ;; Procedury anonimowe (to lambdy) np : (lambda (i) (+ i 1))
- ;; Cukier składniowy(lukier syntaktyczny ) - dowolna cecha skladni jezyka ktora można wyeliminować przez proste
- ; przekształcenia składniowe, istniejąca tylko dla wygody programisty
- ;; Procedury wyższego rzędu - procedury zwracające jako wynik procedure
- (define (inc i)
- (+ 1 i))
- (define (incc i)
- (+ 2 i))
- (define (square x)
- (* x x))
- ;2
- (define (compose f x)
- (lambda (i) (f (x i))))
- ;3
- (define (repeated p n)
- (if (= n 0)
- p
- (compose p (repeated p (- n 1)))))
- ;4
- (define product
- (lambda (term next s e op)
- (if (= s e)
- (term s)
- (op (term s) (product term next (next s) e op)))))
- (define product2
- (lambda (term next s e op acc)
- (if (= s e)
- acc
- (product2 term next (next s) e op (op (term s) acc)))))
- (define (dopi x)
- (/ (* x (+ x 2)) (* (+ x 1) (+ x 1))))
- (define (accumulate combiner s e null-value term next)
- (if (= s e)
- (combiner (term s) null-value)
- (accumulate combiner (next s) e (combiner (term s) null-value) term next)))
- (define (cont-frac-rec num den k)
- (if (= k 0)
- (/ (num) (den))
- (/ (num) (+ (den) (cont-frac-rec num den (- k 1))))))
- (define (pi-cont-frac num den k x)
- (if (= k 0)
- (/ (num x) (den))
- (/ (num x) (+ (den) (pi-cont-frac num den (- k 1) (+ x 2))))))
- ;;LISTA 3 [ 6 i 7, i 8 nie zrobione] - indukcja i permutacja
- ;; Selektory, konstruktory, predykaty
- ;;Potrafie opowiedzic o zaleznosci miedzy predykatami a konstruktorami np dla pair, listy? etc
- (define (reverse-rek xs)
- (if (pair? xs)
- (append (reverse-rek (cdr xs)) (cons (car xs) null))
- xs))
- (define (fold-right op nval xs) ;; spoko funkcja
- (if (null? xs)
- nval
- (op (car xs)
- (fold-right op nval (cdr xs)))))
- (define (insert xs n)
- (if (> n (car xs))
- (cons (car xs) (insert (cdr xs) n))
- (cons n xs)))
- (define (append-s . xs)
- (fold-right append null xs))
- (define (permi xs)
- (if (null? xs)
- null
- (append-s (map (lambda (zs) (insert (car zs) zs)) (permi (cdr xs))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement