anonymous
  • anonymous
Some English words can be played on the keys of a piano, such as “face” or “baggage”. A piano has keys named a, b, c, d, e, f, g. Write a Scheme function can-play-word? that consumes a word (a non-empty string) and produces true or false depending on whether the word can be played on a piano or not. The only characters that can be played on a piano are lower case letters. Some English words can be played on the keys of a piano, such as “face” or “baggage”. A piano has keys named a, b, c, d, e, f, g. Write a Scheme function can-play-word? that consumes a word (a non-empty string) and produces true or false depending on whether the word can be played on a piano or not. The only characters that can be played on a piano are lower case letters. @Computer Science
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
o sweet.... we are askin the same question... feel like we should use remove-all definition but i have no clue how to operate it..
anonymous
  • anonymous
yeah... I have no idea how to do this... not that great in cs.. lol :/
anonymous
  • anonymous
...it's only about an hour till the deadline of this assignment.... i'm dying..

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
Yeah... I only got the first question. LOL. I'm screwed..
anonymous
  • anonymous
........i cant even say i got the first question cuz i didn't pass the test..... are u in cs 115..?
anonymous
  • anonymous
do i know u....?
anonymous
  • anonymous
yeah.. CS 115. In Lori Case class.... I don't think you know me.. I don't know that many people. LOL
anonymous
  • anonymous
i mean d i know u in person? nm we have different profs.... omg what to do...
anonymous
  • anonymous
No, I don't think you know me in person.. haha.. I just wrote all the design recipe stuff down hoping to get part marks.. I didn't get any of the actual functions itself...
anonymous
  • anonymous
o brilliant idea...... i'll do that immediately.... yeah muz get a 25%+ or it's too bad..
anonymous
  • anonymous
what program r u in?
anonymous
  • anonymous
haha.. yeah.. I just hope to get over 25% in the assignments to get that extra mark. LOL... and I'm in honours math.. hbu?
anonymous
  • anonymous
i already chose my program to be actsci....... and i now regret it a lot.... but i want to stay tho..
anonymous
  • anonymous
ooo actsci... a lot of people are taking that actually.. I'm actually taking MTHEL 131(intro to actuarial practice?) as my elective.. and I don't find it that interesting.. LOL
anonymous
  • anonymous
o i dont even know what that is...... my cousin 's in actsci 3rd yr and i juz wanted to get help from her so i chose the same program.. how i realize how tough it is.....><
anonymous
  • anonymous
now==
anonymous
  • anonymous
haha.. that's why you choose a program that you like and enjoy.. I have to go drop off my algebra assignment due in 30 minutes.. LOL i'll be back soon. xD work on those design recipes! xD
anonymous
  • anonymous
o m g... i didn't even do my algebra assignment......
anonymous
  • anonymous
i was workin on cs all the time..
anonymous
  • anonymous
.... are you serious? ... wow.. Dx I did algebra first cause I find it easier and much more useful than CS... I hate CS ... don't even know why I have to take it...
anonymous
  • anonymous
...more useful....i much better in algebra than in cs so it doesn't matter if i miss one assignment.... thats why i gave it up..
anonymous
  • anonymous
yeah i don't see the point of taking cs.........i'm terrible at it...........
anonymous
  • anonymous
haha.. me too... I don't understand a thing in CS.. everything the prof says is just alien language to me.. LOL.. gonna go drop off algebra now.. i'll be back soon xD
anonymous
  • anonymous
oo~~ see u soon...... btw i cannot log in to my markus no matter which browser i use now...
anonymous
  • anonymous
o.O ur right... some authorization thing... :s
anonymous
  • anonymous
。。。 what should we do..........
anonymous
  • anonymous
I have no idea... I submitted some of mine already... It's probably cause a lot of people are using it or something.. Just keep trying I guess? :S
anonymous
  • anonymous
。。。 i emailed the ta.
anonymous
  • anonymous
I'm rusty at Scheme, but you should do something like this. (define (can-play-word? word) (cond ((empty? word) #t) ((char= (car word) 'a) (can-play-word (cdr word))) ((char= (car word) 'b) (can-play-word (cdr word))) ((char= (car word) 'c) (can-play-word (cdr word))) ((char= (car word) 'd) (can-play-word (cdr word))) ((char= (car word) 'e) (can-play-word (cdr word))) ((char= (car word) 'f) (can-play-word (cdr word))) ((char= (car word) 'g) (can-play-word (cdr word))) (else #f))) As I said, it might not be exactly like this. I have no way to test it at the moment, but it should follow this general structure: Make a cond, ask if the word still has elements, if its empty, it's automatically true. If the letter you recieve is a, b, c, d, e, f or g, you call the function again and keep trying. If you recieve anything else, it's automatically false.
anonymous
  • anonymous
Hey... thanks for the reply... an error message appeared when I ran the program.. char=: this function is not defined
anonymous
  • anonymous
yeah i have no clue what does char means.... i know car is first and cdr is rest...
anonymous
  • anonymous
hmm, there should be a function that does what char= is supposed to do, anything you remember that is used to compare two values? Lemme look up online char means a single character like a, b or c
anonymous
  • anonymous
Oh my bad, it's supposed to be char=? not char=
anonymous
  • anonymous
I wrote a helper function can-play-letter? that determines if a single letter is playable. Then for can-play-word? I said it's either that the string is empty (base case), or the first letter is playable (do a little work) and the rest of the word is playable (recursively reduce it to a smaller problem).
anonymous
  • anonymous
;;wordlist: string -> list-of-symbols ;;Purpose: transform a string to a list ;;Examples:(define (wordlist maryh) => (cons #\m (cons #\a (cons #\r (cons #\y (cons #\h empty))))) (define (wordlist word) (string->list word)) ;;data analysis: ;; if the word contains only a,b,c,d,e,f,g then produces boolean value true ;; if the word contains letters other than a,b,c,d,e,f,g then produces boolean value false ;;wordtest: string->boolean ;;Purpose: produce boolean value of a word whether it contains only a,b,c,d,e,f,g ;;or it contains letters that are not on the piano keyboard by consuming a string ;;Examples: ;;(check-word "dad") => true ;;(check-word "play") => false (define (check-word word) (cond [(equal? (list->string(cons (first (wordlist word)) empty))"a") true] [(equal? (list->string(cons (first (wordlist word)) empty))"b") true] [(equal? (list->string(cons (first (wordlist word)) empty))"c") true] [(equal? (list->string(cons (first (wordlist word)) empty))"d") true] [(equal? (list->string(cons (first (wordlist word)) empty))"e") true] [(equal? (list->string(cons (first (wordlist word)) empty))"f") true] [(equal? (list->string(cons (first (wordlist word)) empty))"g") true] [else false])) ;;tests (check-expect (check-word "face") true) (check-expect (check-word "False") false) ;;data analysis: ;;a wordlist is a helper function that ;;help to convert a sting into a list of word ;;can-play-word?: string -> boolean ;;Purpose: produce boolean value depending on whether or not a word can be played on a piano ;;by consuming a string ;;Examples: ;;(can-play-word? "face") => true ;;(can-play-word? "Dad") => false ;;(can-play-word? "apple") => false ;; (can-play-word? "lee-chin") => false (define (can-play-word? word) (cond [(empty? (wordlist word)) true] [(check-word word) (can-play-word? (list->string (rest (wordlist word))))] [else false]))
anonymous
  • anonymous
Sorry, my Scheme is ancient (R5RS, circa 1997). (define (can-play-letter? letter) (and (char>=? letter #\a) (char<=? letter #\g))) (define (can-play-word? word) (or (= (string-length word) 0) (and (can-play-letter? (string-ref word 0)) (can-play-word? (substring word 1 (string-length word))))))

Looking for something else?

Not the answer you are looking for? Search for more explanations.