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 7897975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:18:30+00:00 2026-06-03T08:18:30+00:00

enter code here Just need to know the basics of peeking in scheme. I

  • 0

enter code hereJust need to know the basics of peeking in scheme. I tried looking at the racket site for help but it didn’t have much on it. Or maybe I was looking in the wrong section. Anyways, the point of this is the following.

if I have
(#\x #\b #\o #\x #\space #\3 #\6 #\0)

I want to be able to identify x as a char and then continue peeking until space is reached and redefine this as a word. Then do the same for 360.

Any tips?
Please and thank you! : )

Here is what my code looks like in case it helps

(define (work x) 
(cond
((null? x)(write '$$))
(char-numeric? (car x))
(write 'Num)
(toke (cdr x)))
((char-alphabetic? (car x))
(write 'ID)
(work (cdr x)))
(else (write "other")))

The problem with this is that it would give me IDIDIDID for “xbox” (which makes sense cause of the code) but I want to make it output just ID once for the whole word xbox

  • 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-06-03T08:18:32+00:00Added an answer on June 3, 2026 at 8:18 am

    There are simpler ways to solve the problem, but they involve some extra knowledge of the language. For instance, using regular expressions for splitting a string at the spaces and map and filter for processing each word:

    (define line "xbox 360")
    
    (define (process line)
      (map (lambda (word)
             (cond ((string->number word) "number")
                   (else "word")))
           (filter (lambda (str)
                     (not (equal? str "")))
                   (regexp-split #px"\\s+" line))))
    

    Notice that the input received was a string containing a line in the input file (as returned by the procedure file->lines). The general idea would be: read the file line by line, and process each one in turn with the above snippet of code.

    If you’re ok with using functionality a bit more advanced in your code, the above will do the trick.

    EDIT :

    I wrote a version using only list iteration and read-char (not peek-char, which reads only the first char and doesn’t advance to the next one), but you’ll see that this is far more complex to understand than the above procedure:

    (define (process line)
      (let ((port (open-input-string line)))
        (let loop ((char (read-char port))
                   (acc  '()))
          (cond ((eof-object? char)
                 (cond ((null? acc) '())
                       ((string->number (list->string acc)) (list "number"))
                       (else (list "word"))))
                ((char-whitespace? char)
                 (cond ((null? acc)
                        (loop (read-char port) '()))
                       ((string->number (list->string acc))
                        (cons "number" (loop (read-char port) '())))
                       (else
                        (cons "word"   (loop (read-char port) '())))))
                (else
                 (loop (read-char port) (cons char acc)))))))
    

    Both solutions work as expected for the following tests:

    (process "xbox 360")
    > '("word" "number")
    
    (process "1")
    > '("number")
    
    (process "a")
    > '("word")
    
    (process " ")
    > '()
    
    (process "")
    > '()
    
    (process "  a  b  1 a   ")
    > '("word" "word" "number" "word")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

enter code here I've created a simple code for mount virtual disk into system
enter code here I have a table on SQL server 2005 with bigint primary
enter code here Hi All, I have a simple windows service application that connects
enter code here I have a ListView that have a different Layout XML for
enter code here My problem is this: in this database the junction table contains
I check like this: enter code here var point = new g.LatLng(parseFloat(lat),parseFloat(lng)); var bounds
I have <.ImageView> enter code here s(icons) in my android layout xml file, which
i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
enter code here I'm reading a stream from a device in Linux which contains
Good day to all. I have a booking site. Here I need to integrate

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.