guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Read n bytes


From: Sam Phillips
Subject: Re: Read n bytes
Date: Fri, 21 Dec 2001 14:37:35 -0800
User-agent: Mutt/1.3.24i

On Fri, Dec 21, 2001 at 08:49:16AM +0000, Neil Jerram wrote:
> >>>>> "Sam" == Sam Phillips <address@hidden> writes:
> 
>     Sam> Hi, I'm slightly new to guile/scheme.  I've been using it
>     Sam> heavily for about the past month.
> 
> Welcome to the list!
> 

Thanks!

>     Sam> Currently I'm trying find (or write) a routine that will read
>     Sam> n bytes from a port.  My current failed attempt is
> 
>     Sam> (define (read-num-chars port len) (let ((ret "")) (do ((i len
>     Sam> (- len 1))) ((eq? 0 i) ret) (set! ret (string-append ret
>     Sam> (list->string (list (read-char port))))) ) ) )
> 
>     Sam> I'm sure there's an easier way to do this, but with my
>     Sam> current knowledge of scheme I can't uncover it.
> 
> The problem here is that, in the `do' expression, the stepper for i
> should be `(- i 1)'.  You have `(- len 1)', which will set i to the
> same value every time, so the `do' never terminates.
> 

Oh that was really dumb of me.  Just plain wrong in any language.

Thanks for all of the other tips.  I'm going to see if any of them can
be applied to any other crude scheme I've fashioned so far.

-- 
Sam Phillips <address@hidden>                http://www.dasbistro.com
Reno                                                              Nevada



reply via email to

[Prev in Thread] Current Thread [Next in Thread]