Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

scheme ukol

(define-macro cons-stream
(lambda (a b)
(quasiquote (cons ,a (delay ,b)))))

(define list->stream
  (lambda (lst)
    (foldr (lambda (x y)
             (cons-stream x y))
           '() lst)))

(define stream
  (lambda args
    (list-stream args)))

(define stream-foldr
  (lambda (f nil . streams)
    (if (stream-null? (car streams))
      nil
       (apply f
         (quasiquote (,@(map stream-car streams)
,(delay
(apply stream-foldr f nil
(map stream-cdr streams)))))))))

(define stream->list
  (lambda (stream)
      (stream-foldr (lambda (x y)
           (cons x (force y)))
           '()
            stream)))

(define stream-null? null?)

(define stream-car car)

(define stream-cdr
(lambda (stream)
(force (cdr stream))))

(define-macro stream-append
   (lambda (s1 s2)
	(quasiquote (let proc ((s (quote s1)))
(if (stream-null? s) (quote s2)
(cons-stream (stream-car s) (proc (stream-cdr s))))))))

(define (stream-rm-duplicates stream)
  (let ((used (list)))
    (let iter ((stream stream))
      (if (stream-null? stream)
          stream
          (if (member (stream-car stream) used)
              (iter (stream-cdr stream))
              (begin (set! used (cons (stream-car stream) used))
                     (cons-stream (stream-car stream) (iter (stream-cdr stream)))))))))

Neformátovaný

Přidáno: 10.4.2014
Expirace: Neuvedeno

Avatar
Autor: hurvajs
Aktivity