Funkcionálne programovanie cvičenie 8

Created: 2009-11-25 - 11:21

;port? zistuje ci je to predikat vstupu/vystupu
(port? (current-input-port))

;(read) zobrazi vstupne pole kde mozno zadavat nejaky vstup
;(if (read) 4 5) - podmienka ak je read true vrati 4

;mocna to vec - nacitanie vstupu do premennej v
;(define v (read))
;(display v)

;citanie zo suboru
(define i (open-input-file "8.scm"))
(define j (read-char i))
j
(close-input-port i)

;zapis do suboru
(define o (open-output-file "vystup.txt"))
(display "good" o)
(write-char #\space o)
(display 'morning o)
(newline o)
(close-output-port o)

(call-with-input-file "8.scm"
                 (lambda (i)
                   (list (read-char i)
                         (read-char i)
                         (read-char i)
                         (read-char i)
                         (read-char i))))
(define (citaj i)
  (define (c x)
    (let ((a (read-char i)))
      (if (eof/object? a)
          x
          (c (cons a x)))))
  (c ()))

(call-with-input-file "8.scm" citaj)

(call-with-output-file "vystup.txt"
  (lambda (o)
    (write (call-with-input-file "vstup.txt" read-line) o)))

;citanie zo stringu
(define i (open-input-string "dobre rano"))
(define o (open-input-string))
(write (read i) o)
(get-output-string o)
(file-position i)
(file-position o)
(file-position o 20)
(get-output-string o)

;ramcove modely
(define (f x y)
  (define (g x)
    (+ x 5))
  (* (g x) (g y)))
(f 3 2)
;nakreslit graf

;na du nakreslit ramcovy model zo skript ulohy 7.9.1 prvych sest prikladov (ten siesty je hardcore, takze ked to nebudete mat sa mozete vyhovorit, ze to bolo tazke) :)