mit-scheme-devel
[Top][All Lists]
Advanced

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

Re: [MIT-Scheme-devel] Re ading files in mit-scheme


From: Marijn
Subject: Re: [MIT-Scheme-devel] Re ading files in mit-scheme
Date: Mon, 23 Jan 2012 09:29:05 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20120110 Thunderbird/9.0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 20-01-12 00:43, Broseph wrote:
> 
> Hello, I am an undergrad math student at Whittier college, and I
> have been trying to figure out how to read lines from a text file
> into a list of characters in scheme. I plan on using a list of
> prime numbers output from a python script i wrote, but i am having
> trouble getting the text from the file into a list. Could someone
> show me how this could be done? The file I am using has each prime
> number on a new line like this: 2 3 5 7 11 13 etc. I want to put it
> into a list like this: ((#\2) (#\3) (#\5) (#\7) (#\1 #\1) (#\1
> #\3)) or ("2" "3" "5" "7" "11" "13") I am thinking this would be
> the easiest way to get the information into a list, since i have
> written functions for turning lists of characters or strings into
> an integer.

Something like:


(with-input-from-file "primes"
  (lambda ()
    (let loop ()
      (let ((token (read)))
        (if (eof-object? token)
            'done
            (begin
              (displayln token)
              (loop)))))))


should get you started,

Marijn
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8dGlEACgkQp/VmCx0OL2wHLQCeOF1+GKSLsbje5ZIB13K4LDro
IPYAoKXL16eDYzYPalm4cl3tl6R323pF
=/QBx
-----END PGP SIGNATURE-----



reply via email to

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