Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3853394
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:27:44+00:00 2026-05-19T17:27:44+00:00

I tried to read string from an input-port in Racket, but no matter what

  • 0

I tried to read string from an input-port in Racket, but no matter what API functions I used to read (read, read-string, read-bytes etc), the return value of those functions was never equal eof-object.

(define (some_process inp)
 (begin
    (let ([c (read-string 1 inp)])
      (if (eof-object? c)
          (begin
            (display "EOF \n")
            #f)
          (if (equal? c "\n")
              (begin 
                (display "NEWLINE \n"))
              (some_process inp))))))

The c can never be an eof-object?

If you display what c is, it is always a newline.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:27:45+00:00Added an answer on May 19, 2026 at 5:27 pm

    Read reference:

    • read-char: “Reads a single character from in – which may involve reading several bytes to UTF-8-decode them into a character. If no bytes are available before an end-of-file, then eof is returned.“

    • read-string: “Returns a string containing the next amt characters from in. If no characters are available before an end-of-file, then eof is returned.“

    Examples:

    > (read-char (open-input-string "char"))
    #\c
    > (read-string 50 (open-input-string "the string"))
    "the string"
    > 
    

    But if there are no character(s) in the buffer, you’ll get eof:

    > (read-char (open-input-string ""))
    #<eof>
    > (read-string 50 (open-input-string ""))
    #<eof>
    

    I think you just want to read some amount of characters in a loop and do something with them. If so, the solution would look something along the lines of:

    (define (another-process inp)
      (let ([c (read-char inp)])
        (if (eof-object? c)
            (begin (display "==== EOF ====") (newline))
            (begin (display c) (newline)
                   (another-process inp)))))
    

    Example:

    > (another-process (open-input-string "OK"))
    O
    K
    ==== EOF ====
    > (another-process (open-input-string ""))
    ==== EOF ====
    >
    

    Notice a second call to another-process with an empty line, it detects eof immediately and exits the loop.

    EDIT:
    In case you need to check if the read character is newline:

    (define (process-moo inp)
      (let ([c (read-char inp)])
        (cond
          ((eof-object? c)
           (display "==== EOF ====") (newline))
          ((eq? c #\newline)
           (newline) (display "---- NEWLINE ----") (newline)
           (process-moo inp))
          (else
           (display c)
           (process-moo inp)))))
    

    Example:

    > (call-with-input-string "Hello\nhumans\n!" process-moo)
    Hello
    ---- NEWLINE ----
    humans
    ---- NEWLINE ----
    !==== EOF ====
    > 
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI all, When I tried to read the record of all peoples from the
I have tried searching on Google and also read the documentation but no success.
I'm struggling to read an int from the hidden field on aspx page. <input
I wanted to compare reading lines of string input from stdin using Python and
How can you set a string to be used instead of standard input? For
I am trying to read unicode string from a console in C#, for the
I read this topic, but his problem maybe different from mine Writing to both
I'm trying to read from a text file to input data to my java
I tried to read a file in a view like this: def foo(request): f
I just downloaded the Oxygene free command line compiler, and tried to read the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.