From mboxrd@z Thu Jan 1 00:00:00 1970 From: taylanbayirli@gmail.com (Taylan Ulrich =?utf-8?Q?Bay=C4=B1rl=C4=B1?= =?utf-8?Q?=2FKammer?=) Subject: Re: Adding wc to Bournish Date: Fri, 27 May 2016 17:28:04 +0200 Message-ID: <87oa7rjzaz.fsf@T420.taylan> References: <20160524184720.GA27449@debian-netbook> <20160526192755.GB28047@debian-netbook> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6JgH-0006g4-UV for guix-devel@gnu.org; Fri, 27 May 2016 11:28:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b6JgF-0007tO-FM for guix-devel@gnu.org; Fri, 27 May 2016 11:28:08 -0400 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:38059) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6JgF-0007sF-5T for guix-devel@gnu.org; Fri, 27 May 2016 11:28:07 -0400 Received: by mail-wm0-x22e.google.com with SMTP id n129so141825004wmn.1 for ; Fri, 27 May 2016 08:28:06 -0700 (PDT) In-Reply-To: (Eric Bavier's message of "Fri, 27 May 2016 08:37:49 -0500") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Eric Bavier Cc: guix-devel@gnu.org Eric Bavier 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 `#> (((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