[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Adding wc to Bournish
From: |
Taylan Ulrich Bayırlı/Kammer |
Subject: |
Re: Adding wc to Bournish |
Date: |
Fri, 27 May 2016 17:28:04 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Eric Bavier <address@hidden> writes:
> On 2016-05-26 14:27, Efraim Flashner wrote:
>> Here's where I'm currently at with 'wc'. Currently I'm getting an error
>> about having the wrong number of arguments for lambda (I assume)
> [...]
>> +(define (wc-command file)
>> + ((lambda (lines words chars) ; lambda doesn't like 3 variables
>> + (format #t "~a ~a ~a ~a~%" lines words chars file))
>> + (call-with-input-file file lines+chars)))
> [...]
>>
>> ;;; /home/efraim/workspace/guix/guix/build/bournish.scm:143:2: warning:
>> wrong number of arguments to `#<tree-il (lambda () (lambda-case
>> (((lines
>> words chars) #f #f #f () (lines-24244 words-24245 chars-24246)) (apply
>> (toplevel format) (const #t) (const "~a ~a ~a ~a~%") (lexical lines
>> lines-24244) (lexical words words-24245) (lexical chars chars-24246)
>> (lexical file file-24242)))))>'
>
> I think you might just be missing a 'call-with-values':
>
> (define (wc-command file)
> (call-with-values
> (call-with-input-file file lines+chars)
> (lambda (lines words chars) ...)))
I believe this should be
(define (wc-command file)
(call-with-values
(lambda ()
(call-with-input-file file lines+chars))
(lambda (lines words chars)
...)))
since both arguments to call-with-values must be procedures.
By the way, I prefer SRFI-11 let-values (standardized in R7RS):
(define (wc-command file)
(let-values (((lines words chars)
(call-with-input-file file lines+chars)))
...))
The large number of parentheses involved are annoying at first, but as I
used it more often I grew accustomed to it and aren't bothered at all
anymore, neither in writing nor reading the code. I also had some valid
uses of let*-values occasionally; I find it neat how it allows "piping"
a number of different values through a sequence of procedures, without
having to allocate any intermediate data structures.
Taylan