[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: How to PICK the CTRL-u argument from the file

William James

8/14/2015 6:45:00 AM

Alan Crowe wrote:

> > Now I must convert it to a file with 5 line1's and 6 line2's and so on.
> > It is a long file.
>
> M-x run-lisp
>
> to fire up your Common Lisp.
> Then
>
> (defun multiply-lines (in-file out-file)
> (with-open-file (in in-file :direction :input)
> (with-open-file (out out-file
> :direction :output
> :if-exists :supersede)
> (loop for count = (read in nil nil)
> while (integerp count)
> do (let ((buffer (read-line in)))
> (loop repeat count
> do (princ buffer out)
> (terpri out)))))))
>
> (multiply-lines "temp-count-lines" "temp-dup-lines-1")

Gauche Scheme:

(define (multiply-lines in-file out-file)
(with-input-from-file in-file (lambda ()
(with-output-to-file out-file (lambda ()
(generator-for-each
(lambda (count)
(read-line)
(let1 line (read-line) (dotimes (count) (print line))))
read))))))

--
I know it would be frightening for you to step outside the ever narrower
confines of what we are permitted to say about race.... Today, the most
dangerous ideas are the historical, biological, and moral truths that men such
as Washington, Jefferson, Teddy Roosevelt, Mark Twain, Walt Whitman, and your
grandparents took for granted. --- Jared Taylor