Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 使用列表在单词转换器中设置字符串_List_Scheme_Racket_List Processing - Fatal编程技术网

List 使用列表在单词转换器中设置字符串

List 使用列表在单词转换器中设置字符串,list,scheme,racket,list-processing,List,Scheme,Racket,List Processing,我是scheme新手,在创建一个相对简单的piglatin翻译器时遇到了困难(单词以元音开头,结尾加上“way”,以辅音开头,在第一个元音+ay之前加上所有字母,最后加上duck->uckday。) (翻译“棍棒和石头”)->(ickstay和Way onestay) 我相信我应该有正确的解决方案,但我有麻烦处理作为一个字符串->列表和列表->字符串列表的短语,以便正确地翻译每个单词 #lang racket (define translate (lambda (sentance)

我是scheme新手,在创建一个相对简单的piglatin翻译器时遇到了困难(单词以元音开头,结尾加上“way”,以辅音开头,在第一个元音+ay之前加上所有字母,最后加上duck->uckday。)

(翻译“棍棒和石头”)->(ickstay和Way onestay)

我相信我应该有正确的解决方案,但我有麻烦处理作为一个字符串->列表和列表->字符串列表的短语,以便正确地翻译每个单词

#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")))))

您混淆了程序中的符号和字符串。其中没有一个字符串(字符串用双引号写:
“这是一个字符串”
)。相反,您有符号或符号列表,如
”(ay)
。您应该了解这两种数据类型之间的差异,然后重写程序。@Renzo但是为什么我有“字符串->列表:合同冲突预期:字符串?”在breakSentance中?因为
string->list
对一个字符串进行操作,并且您必须向它传递一个字符串。例如,如果您调用
(translate)(sticks and stones))
,然后将使用符号
棍子
石头
@Renzo-Ah-wow我明白了,谢谢。这是个愚蠢的错误。