working with list to string in a word translator

75 views Asked by At

I am new to scheme and am having trouble creating a relatively simple piglatin translator ((word begins with vowel add "way" to the end, begins with consonant, add all letters before first vowel + ay to the end duck -> uckday.)

(translate '(sticks and stones)) -> (ickstay andway onestay)

I believe I should have the correct solution however am having trouble processing the phrase as a list with string->list and list->string in order to properly translate each word.

#lang racket

(define translate
  (lambda (sentance)
    (map breakSentance sentance)))


; break down sentance string split
(define (breakSentance word)
  (string->list (listWord (string->list word))))

; break down word for vowel testing
(define (listWord word)
    (cond
      ((foundVowel (car word)) (noVowel word))
      (else (noVowel word))))

; letters that are vowels, their presence indicates how the word should be latinized
(define (foundVowel)
  (lambda (letter)
    (member letter '("aeiouy"))))


(define (startsVowel)
  (lambda (word)
    (append word '("way"))))


(define (noVowel)
  (lambda (word lets)
    (cond
      (foundVowel (car word)) (noVowel word))
    (string-join word (string-join lets '("ay")))))
0

There are 0 answers