I am trying to make a program that will take a list of words from a .txt file and add the alphabet to the end of each word.

the code i have just makes it read and re-read the first line. since each list will be different i cant just do

(read-line)
(read-line)
(read-line)


etc....
because each list will have different amounts of lines

the way i want to have it read is to get the first line, add a,b,c,d etc... to the end then goto the next line.


This is my code i have to get from file

(define (adder path)
     (alpha-get "test.txt"))
  
(define (alpha)
0)
 
(define (alpha-get dir)
    (set! alpha 
      (list (with-input-from-file dir
               (lambda ()
                (list
                  (read-line))))))
     (begin
     (display alpha)
    (alpha-get "readsme.txt")))

im forgetting the add suffix for the moment as i know how to do that

can someone help me please. the procedure to get the files id alpha-get.


any help with higher order procedures that might do what i need would be great

I'm not competent enough in scheme to provide much help, but it might be easier to read in the whole file, split it into lines, add the alphabet, and then print it all back to the file.

On the other hand.
If you put "dir" outside of the recursion, it might work.

Hmm... I don't have time to show you the code I'm thinking at the moment... tonight!

Anyway, if you use a letrec inside of alpha-get, so you don't use dir as part of the recursive call, each read-line should get the next line in the file.

never mind i worked it out myself. thanks for the help though

I tested the code with a file that I created but I launched the first line of this a thousand times. help!

To make the approach used in the code posted in this thread work, you'd write a recursive function that calls readline and then recurses until readline returns eof. That said, it would be much easier to just use in-lines.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.