#lang scheme (define-struct account (login-name password UID GID user-name directory shell)) (define (find-char s n c) (if (>= n (string-length s)) -1 (if (equal? (string-ref s n) c) n (find-char s (+ n 1) c)))) (define (split-line s c) (let ((pos (find-char s 0 c))) (if (= pos -1) (list s) (cons (substring s 0 pos) (split-line (substring s (+ pos 1) (string-length s)) c))))) (define (parse-line line) (let ([fields (split-line line #\:)]) (make-account (first fields) (second fields) (string->number (third fields)) (string->number (fourth fields)) (fifth fields) (sixth fields) (seventh fields)))) (define (read-passwd filename) (call-with-input-file filename (lambda (f) (for/list ([line (in-lines f)]) (parse-line line))))) (define (find-account passwd name) (findf (lambda (a) (equal? (account-login-name a) name)) passwd)) (define (run) (read-passwd "/Users/loewis/tmp/passwd"))