I need help in Dr scheme. i need to make it so that a string can be broken into the individual words ignoring punctuation. please help

You really could stand to be more specific. First of all, it's not like anybody's going to just give you the answer. Also, you need to improve your ability to think clearly. You say "ignoring punctuation" as if it's clear what you mean. You can't write clear programs if you don't specify things precisely. In this case, does "ignoring punctuation" mean you want things like "efgh-ijkl" to be treated like one word? Should "foo bar." be split up into ("foo" "bar"), or do you want ("foo" "bar.")?

Suppose you had to do this manually. Pretend you're in an empty room with a desk and some paper. Every 60 seconds, somebody comes in and gives you a slip of paper with a character written on it. It's the next character on the string. How would you split this string up into words? What information do you use to proceed every time you see a new character?

Sorry should have been more specific. What i mean is taking "Hello World!!" and returning "Hello" "World" ignoring commas, question marks etc...

The way i was thinking it could be done is turning the string into a list and then checking whether the character is like #\space or #\! etc.... Then if is equal to one of those things it jumps to the next character and tests. but if it isnt equal to punctuation then it adds that letter to a new list and once punctuation is reached it creates a new list of characters to turn into a string. The only problem is im not sure if thats the best and easiest way to do it.

That's pretty much how it's done. Though instead of checking whether the character is like #\space or #\! as you described, you should check whether the character is not alphabetic. I think that function is called 'CHAR-ALPHABETIC?'.

so far i have gotten it to

(define [extract-alphas text]
  (define [alpha-chars chars]
      [(empty? chars)
      [(char-alphabetic? (first chars))
       (string (first chars))
       (alpha-chars (rest chars)))]
       (string (empty) )
       (alpha-chars (rest chars)))]))
(alpha-chars (string->list text)))

except it comes back with an error at

       (string ([B]empty[/B]) )
       (alpha-chars (rest chars)))]))

What do i need to change to make it work. the else should start a new list after a non-alphabetic character

What is 'empty'? Is it a function? Are you calling it? I don't remember empty being in the Scheme language standard library. Looking online, it seems like empty is a name for the empty list, the same as '(). So the error would be that you're trying to do a function-call where the 'function' to be called is an empty list value.

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.