[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Adding wc to Bournish
From: |
Efraim Flashner |
Subject: |
Re: Adding wc to Bournish |
Date: |
Tue, 14 Jun 2016 13:20:29 +0300 |
User-agent: |
Mutt/1.6.1 (2016-04-27) |
On Tue, Jun 14, 2016 at 11:57:26AM +0200, Ricardo Wurmus wrote:
>
> Efraim Flashner <address@hidden> writes:
>
> > +(define wc-command-implementation
> > + (lambda files
> > + (let ((files (filter (lambda (file)
> > + (catch 'system-error
> > + (lambda ()
> > + (stat file))
> > + (lambda args
> > + (let ((errno (system-error-errno args)))
> > + (format (current-error-port) "~a: ~a~%"
> > + file (strerror errno))
> > + #f))))
> > + files)))
> > + (for-each
> > + (lambda (file)
> > + (let-values (((lines chars)
> > + (call-with-input-file file lines+chars)))
> > + (format #t "~a ~a ~a~%" lines chars file)))
> > + files))))
> > +
> > +(define wc-l-command-implementation
> > + (lambda files
> > + (let ((files (filter (lambda (file)
> > + (catch 'system-error
> > + (lambda ()
> > + (stat file))
> > + (lambda args
> > + (let ((errno (system-error-errno args)))
> > + (format (current-error-port) "~a: ~a~%"
> > + file (strerror errno))
> > + #f))))
> > + files)))
> > + (for-each
> > + (lambda (file)
> > + (let-values (((lines chars)
> > + (call-with-input-file file lines+chars)))
> > + (format #t "~a ~a~%" lines file)))
> > + files))))
> > +
> > +(define wc-c-command-implementation
> > + (lambda files
> > + (let ((files (filter (lambda (file)
> > + (catch 'system-error
> > + (lambda ()
> > + (stat file))
> > + (lambda args
> > + (let ((errno (system-error-errno args)))
> > + (format (current-error-port) "~a: ~a~%"
> > + file (strerror errno))
> > + #f))))
> > + files)))
> > + (for-each
> > + (lambda (file)
> > + (let-values (((lines chars)
> > + (call-with-input-file file lines+chars)))
> > + (format #t "~a ~a~%" chars file)))
> > + files))))
>
> It looks to me that the filter function is the same in all of these
> procedures. Even the actual implementation, i.e. the for-each over the
> resulting files is almost exactly the same.
>
> This could be simplified. If only the format expression differs then
> you could abstract this difference away. You could still have three
> different procedures, but they can be the result of evaluating a
> higher-order function.
>
> It also seems to me that you could use syntactic sugar to simplify
> “(define something (lambda ...))” to “(define (something ...))”.
>
> ~~ Ricardo
It's already calling `((@@ (guix build bournish)
wc-l-command-implementation) ,@(delete "-l" args)), I could try changing
the ,@(delete part to ,@((@@ (guix build bournish) only-files) ,@(delete
"-l" args)) and then the various implementation functions will be just
printing the results
--
Efraim Flashner <address@hidden> אפרים פלשנר
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
signature.asc
Description: PGP signature
- Re: Adding wc to Bournish, Efraim Flashner, 2016/06/05
- Re: Adding wc to Bournish, Ludovic Courtès, 2016/06/05
- Re: Adding wc to Bournish, Efraim Flashner, 2016/06/07
- Re: Adding wc to Bournish, Ludovic Courtès, 2016/06/08
- Re: Adding wc to Bournish, Efraim Flashner, 2016/06/14
- Re: Adding wc to Bournish, Ricardo Wurmus, 2016/06/14
- Re: Adding wc to Bournish,
Efraim Flashner <=
- Re: Adding wc to Bournish, Efraim Flashner, 2016/06/14
- Re: Adding wc to Bournish, Ricardo Wurmus, 2016/06/14
- Re: Adding wc to Bournish, Ludovic Courtès, 2016/06/15
- Re: Adding wc to Bournish, Efraim Flashner, 2016/06/15
- Re: Adding wc to Bournish, Ludovic Courtès, 2016/06/23