Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define FILE "save_test3.txt")
- (define WORD "blabla")
- (define (save-data data path)
- (with-output-to-file path
- (lambda ()
- (write data))))
- (save-data FILE WORD)
- (define (load-data path)
- (with-input-from-file path
- (lambda () (read))))
- (load-data FILE)
- (define (string-prefix? n m)
- (define (helper xs ys)
- (or (null? xs)
- (and (equal? (car xs) (car ys))
- (helper (cdr xs) (cdr ys)))))
- (helper (string->list n) (string->list m)))
- (define (string-split xs x)
- (define (helper ys ms ns)
- (if (null? ys)
- '()
- (if (string-prefix? (list->string ms) (list->string ys))
- (cons ns (helper (list-tail ys (length ms)) ms ""))
- (helper (cdr ys) ms (string-append ns (list->string (list (car ys))))))))
- (helper (string->list (string-append xs x)) (string->list x) ""))
- (define (string-counter file)
- (define file_port (open-input-file file))
- (define (helper file)
- (if (eof-object? (peek-char file))
- '()
- (cons (read-char file) (helper file))))
- (define (iter lst)
- (if (null? lst)
- '()
- (if (eq? (car lst) "")
- (iter (cdr lst))
- (cons (car lst) (iter (cdr lst))))))
- (display (length (iter (string-split (list->string (helper file_port)) "\n"))))
- (close-input-port file_port))
- (string-counter "test.txt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement