Re: [Chicken-users] read file into a list of lists
Hi Arthur, I need a list of lists because each line has more than one number. You first solution works for me. All I need to do is to add an extra string-split call, which returns a list. Thanks a lot! Jinsong On Tue, Jul 12, 2016 at 11:52 PM, Arthur Macielwrote: > Although I can't imagine why you'd need it, but in order to get list of > lists you could do: > > (define (read-all-lines filename) >(with-input-from-file filename > (lambda () > (map (lambda (x) >(list (string->number x))) > (read-lines) > > I'm not sure that's what you want. > > Cheers, > Arthur > > > On Wed, Jul 13, 2016 at 12:49 AM, Jinsong Liang > wrote: > >> Hi Arthur, >> >> This simplifies my code a lot! I will give it a try. >> >> Thank you! >> >> Jinsong >> >> On Tue, Jul 12, 2016 at 11:45 PM, Arthur Maciel >> wrote: >> >>> Jinsong, the closest solution I can think of is the read-lines >>> procedure, which returns a list of strings (each string a line read). >>> >>> http://api.call-cc.org/doc/extras/read-lines >>> >>> Supposing you have a number per line, you could use string->number to >>> get the result. >>> >>> An example would be: >>> >>> (define (read-all-lines filename) >>>(with-input-from-file filename >>> (lambda () >>> (map string->number (read-lines) >>> >>> Cheers, >>> Arthur >>> >>> >>> On Wed, Jul 13, 2016 at 12:07 AM, Jinsong Liang >>> wrote: >>> Hi, I need to read a file (lines of numbers) into a list of lists with each line a list. I wrote the following function to do it: (define (read-all-lines file-name) (let ([output '()]) (let ([p (open-input-file file-name)]) (let f ([x (read-line p)]) (if (eof-object? x) (close-input-port p) (begin (set! output (cons (string-split x) output)) (f (read-line p)) (reverse output))) I have a few questions regarding the above code: 1. Is there an existing API to do the same thing? 2. Using set! seems not a lispy coding style. Is it true? 3. Any improvements I can make ? I bet there are tons. Thank you! Jinsong ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users >>> >> > ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] read file into a list of lists
Although I can't imagine why you'd need it, but in order to get list of lists you could do: (define (read-all-lines filename) (with-input-from-file filename (lambda () (map (lambda (x) (list (string->number x))) (read-lines) I'm not sure that's what you want. Cheers, Arthur On Wed, Jul 13, 2016 at 12:49 AM, Jinsong Liangwrote: > Hi Arthur, > > This simplifies my code a lot! I will give it a try. > > Thank you! > > Jinsong > > On Tue, Jul 12, 2016 at 11:45 PM, Arthur Maciel > wrote: > >> Jinsong, the closest solution I can think of is the read-lines procedure, >> which returns a list of strings (each string a line read). >> >> http://api.call-cc.org/doc/extras/read-lines >> >> Supposing you have a number per line, you could use string->number to get >> the result. >> >> An example would be: >> >> (define (read-all-lines filename) >>(with-input-from-file filename >> (lambda () >> (map string->number (read-lines) >> >> Cheers, >> Arthur >> >> >> On Wed, Jul 13, 2016 at 12:07 AM, Jinsong Liang >> wrote: >> >>> Hi, >>> >>> I need to read a file (lines of numbers) into a list of lists with each >>> line a list. I wrote the following function to do it: >>> >>> (define (read-all-lines file-name) >>> (let ([output '()]) >>>(let ([p (open-input-file file-name)]) >>> (let f ([x (read-line p)]) >>>(if (eof-object? x) >>> (close-input-port p) >>> (begin >>>(set! output (cons (string-split x) output)) >>>(f (read-line p)) >>>(reverse output))) >>> >>> I have a few questions regarding the above code: >>> >>> 1. Is there an existing API to do the same thing? >>> 2. Using set! seems not a lispy coding style. Is it true? >>> 3. Any improvements I can make ? I bet there are tons. >>> >>> Thank you! >>> >>> Jinsong >>> >>> ___ >>> Chicken-users mailing list >>> Chicken-users@nongnu.org >>> https://lists.nongnu.org/mailman/listinfo/chicken-users >>> >>> >> > ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] read file into a list of lists
Hi Arthur, This simplifies my code a lot! I will give it a try. Thank you! Jinsong On Tue, Jul 12, 2016 at 11:45 PM, Arthur Macielwrote: > Jinsong, the closest solution I can think of is the read-lines procedure, > which returns a list of strings (each string a line read). > > http://api.call-cc.org/doc/extras/read-lines > > Supposing you have a number per line, you could use string->number to get > the result. > > An example would be: > > (define (read-all-lines filename) >(with-input-from-file filename > (lambda () > (map string->number (read-lines) > > Cheers, > Arthur > > > On Wed, Jul 13, 2016 at 12:07 AM, Jinsong Liang > wrote: > >> Hi, >> >> I need to read a file (lines of numbers) into a list of lists with each >> line a list. I wrote the following function to do it: >> >> (define (read-all-lines file-name) >> (let ([output '()]) >>(let ([p (open-input-file file-name)]) >> (let f ([x (read-line p)]) >>(if (eof-object? x) >> (close-input-port p) >> (begin >>(set! output (cons (string-split x) output)) >>(f (read-line p)) >>(reverse output))) >> >> I have a few questions regarding the above code: >> >> 1. Is there an existing API to do the same thing? >> 2. Using set! seems not a lispy coding style. Is it true? >> 3. Any improvements I can make ? I bet there are tons. >> >> Thank you! >> >> Jinsong >> >> ___ >> Chicken-users mailing list >> Chicken-users@nongnu.org >> https://lists.nongnu.org/mailman/listinfo/chicken-users >> >> > ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] read file into a list of lists
Jinsong, the closest solution I can think of is the read-lines procedure, which returns a list of strings (each string a line read). http://api.call-cc.org/doc/extras/read-lines Supposing you have a number per line, you could use string->number to get the result. An example would be: (define (read-all-lines filename) (with-input-from-file filename (lambda () (map string->number (read-lines) Cheers, Arthur On Wed, Jul 13, 2016 at 12:07 AM, Jinsong Liangwrote: > Hi, > > I need to read a file (lines of numbers) into a list of lists with each > line a list. I wrote the following function to do it: > > (define (read-all-lines file-name) > (let ([output '()]) >(let ([p (open-input-file file-name)]) > (let f ([x (read-line p)]) >(if (eof-object? x) > (close-input-port p) > (begin >(set! output (cons (string-split x) output)) >(f (read-line p)) >(reverse output))) > > I have a few questions regarding the above code: > > 1. Is there an existing API to do the same thing? > 2. Using set! seems not a lispy coding style. Is it true? > 3. Any improvements I can make ? I bet there are tons. > > Thank you! > > Jinsong > > ___ > Chicken-users mailing list > Chicken-users@nongnu.org > https://lists.nongnu.org/mailman/listinfo/chicken-users > > ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] read file into a list of lists
Hi, I need to read a file (lines of numbers) into a list of lists with each line a list. I wrote the following function to do it: (define (read-all-lines file-name) (let ([output '()]) (let ([p (open-input-file file-name)]) (let f ([x (read-line p)]) (if (eof-object? x) (close-input-port p) (begin (set! output (cons (string-split x) output)) (f (read-line p)) (reverse output))) I have a few questions regarding the above code: 1. Is there an existing API to do the same thing? 2. Using set! seems not a lispy coding style. Is it true? 3. Any improvements I can make ? I bet there are tons. Thank you! Jinsong ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] CHICKEN meetup reminder
Hello, I'll be in Nuremberg from Friday noon to Sunday noon. I'm fine with the cheapest accomodation which would be the A Hostel at the central station. Their best offers are for a room of four (49,40€) or six (45,60€) beds respectively. Please contact me if you're interested in sharing one with me. Cheers Vasilij ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Asynchronous I/O Egg Release
Hi Robert, On Wed, 29 Jun 2016 19:26:48 -0600 Robert Smileywrote: > I have created an asynchronous I/O egg for chicken. Would it be > possible to have it added to the egg-locations file in subversion? > > Here is the repository > > https://github.com/yarnoiser/async-io > > And here is the url for the release-info file specifically. > > https://github.com/yarnoiser/async-io/blob/master/async-io.realease-info > > Hopefully this library will make it easier to read from and write to > any file descriptor without leaving applications hanging, since all > srfi-18 threads block when i/o is performed on ports other than tcp > sockets. > > This library's readers use simple parsers to retrieve completed tokens > from input files as they become ready. It includes a parser for scheme > expressions as well as messages which consist of a single line. > > Hopefully this will be of use. Today I realized that async-io's test was making the Linux salmonella machines hang. strace shows that the test process gets stuck on an endless loop running: poll([{fd=4, events=POLLIN}], 1, 0) = 0 (Timeout) I could reproduce the problem on my system with: $ for i in `seq 100`; do csi -s run.scm && echo $i; done It eventually hangs. Do you know what could be causing this? All the best. Mario -- http://parenteses.org/mario ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] CHICKEN meetup reminder
On Tue, 12 Jul 2016 11:11:05 +0200, Christian Kellermann wrote: > > Dear CHICKEN-fans, > > this is a reminder that the CHICKEN Meetup will take place on > > September 23-25th in Nuremberg, Germany > > http://wiki.call-cc.org/event/chicken-summer-2016 > Do we try to arrange for a common hotel booking like last year? I’m still willing to share my room this year, and should be there for real. ;) ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] CHICKEN meetup reminder
Dear CHICKEN-fans, this is a reminder that the CHICKEN Meetup will take place on September 23-25th in Nuremberg, Germany http://wiki.call-cc.org/event/chicken-summer-2016 So arrange your travel today! It might be helpful if attendees add a table to the wiki when they are planning to arrive and leave. That would help me a lot finding appropriate food places. Thanks! Christian -- May you be peaceful, may you live in safety, may you be free from suffering, and may you live with ease. ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users