我是方案新手,在创建一个相对简单的 piglatin 翻译器时遇到了麻烦((单词以元音开头添加“方式”到末尾,以辅音开头,在第一个元音之前添加所有字母 + ay 到结尾鸭 -> uckday。)
(翻译'(棍棒和石头))->(ickstay andway onestay)
我相信我应该有正确的解决方案,但是在将短语处理为带有 string->list 和 list->string 的列表时无法正确翻译每个单词。
#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")))))