#lang racket ; TODO 1 (define (suffixes L) (map (curry drop L) (range (length L)))) ; TODO 2 (define (interleave L1 L2) (if (or (null? L1) (null? L2)) '() (cons (car L1) (cons (car L2) (interleave (cdr L1) (cdr L2)))))) ; TODO 3 (define (trim L to-remove) (cons (filter (λ (x) (not (member x to-remove))) L) (map (λ (x) (cons x (length (filter (curry equal? x) L)))) to-remove))) ; TODO 4 (define (words L separator) (let loop ((L L) (word '()) (res '())) (cond ((null? L) (reverse (if (null? word) res (cons (reverse word) res)))) ((equal? (car L) separator) (loop (cdr L) '() (if (null? word) res (cons (reverse word) res)))) (else (loop (cdr L) (cons (car L) word) res))))) ; TODO 5 (define (subsequence-stream L) (define suffs (suffixes L)) (let loop ((len 1) (ss suffs)) (if (null? ss) empty-stream (stream-cons (map (λ (suff) (take suff len)) ss) (loop (+ len 1) (drop-right ss 1)))))) ; TODO 6 (define (convert-stream s) (cond ((stream-empty? s) empty-stream) ((null? (stream-first s)) (convert-stream (stream-rest s))) (else (stream-cons (car (stream-first s)) (convert-stream (stream-cons (cdr (stream-first s)) (stream-rest s)))))))