Advertisement
PonaFly

format (№1 19)

Apr 13th, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.79 KB | None | 0 0
  1. (define (format namein nameout . str)
  2.   (define in (open-input-file namein))
  3.   (define out (open-output-file nameout #:exists 'replace))
  4.   (define (iter)
  5.     (define n (read-line in  ))
  6.     (if (equal? n eof) (close-output-port out) (help (string-split n) )))
  7.  
  8.  (define (help lst)
  9.    (if (empty? lst) (iter)
  10.      
  11.         (let ((s (string->list (car lst))))
  12.    
  13.      
  14.     (cond ( (equal? #\% (car s)) (display (list-ref str (-(char->integer(cadr s)) 48)) out) (display " " out) (help (cdr lst)))
  15.           (else (let ((a (reverse s)))
  16.               (if (equal? (car a) #\%) (begin (display (list->string (reverse (cdr a))) out) (display " " out) (help (cdr lst)))
  17.                                        (begin (display (car lst) out) (display " " out) (help (cdr lst))))))))))
  18.   (iter))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement