我已经创建了piglatin翻译器,它可以将单词转换为对应的piglatin。
按照下面的步骤,
(translate '("ark" "gold"))给出
"arkway golday"然而,我想简单地输入(翻译“方舟黄金”),并得到"arkway golday“
我想我应该使用string-split和string-join,但是我似乎犯了一个错误,添加了:
(define (piglatin phrase)
(string-split translate phrase))和跑步(piglatin‘(方舟金色))
给了我一个错误:
string-split: contract violation
expected: (or/c string? regexp?)
given: '("ark gold")代码:
#lang racket
(define (piglatin phrase)
(string-split translate phrase))
(define (translate sentence)
(string-join (map breakSentence sentence)))
; break down sentance string split into a list
(define (breakSentence word)
(list->string (listWord (string->list word))))
; break down word for vowel testing
(define (listWord word)
(cond
((foundVowel (car word))
(startsVowel word))
(else(noVowel word '()))))
; letters that are vowels, their prensence indicates way should be added to end
(define (foundVowel letter)
(member letter '(#\a #\e #\i #\o #\u #\y)))
; allow adding way to end of word
(define (startsVowel word)
(append word '(#\w #\a #\y)))发布于 2017-02-27 01:18:28
在翻译之前,您需要将字符串拆分成单词。
(define (piglatin phrase)
(translate (string-split phrase)))https://stackoverflow.com/questions/42431430
复制相似问题