1

我把字母倒过来了。p我似乎d做不到的是让一串单词颠倒过来。像house倒过来一样ǝsnoɥ。任何帮助,将不胜感激。我快完成了。我正在使用带有列表缩写的初学者。

#;(first (first l2))
#;(first (rest l2))
#;(first (rest (first l2)))

(define (helper character list)
  (cond [(string=? character (first (first list))) (first (rest (first list)))]
        [else (helper character (rest list))]))

(check-expect (helper "p" table-1) "d")
(check-expect (helper "t" table-1) "ʇ")

;;_______________________________________________________________________________

(define (upside-down string)


(upside-down "cat")
4

1 回答 1

1

关于您的helper程序的一些评论:

  • character您应该为不在列表中的情况添加一个额外的条件- 如果发生这种情况,只需返回相同的character. 否则会出现错误
  • 参数不应命名list,这是一个内置过程,覆盖它是一种不好的做法
  • 在继续之前对其进行彻底测试。

整理好之后,下面是你如何实现upside-down,填空:

(define (upside-down str)
  (<???>                       ; finally, do the opposite of explode on the list
   (map (lambda (c)            ; map over each of the characters
          (<???> <???> <???>)) ; call helper on the character
        (<???> (<???> str))))) ; reverse the exploded string

如果您不允许使用mapor lambda,则实现一个convert过程,该过程遍历字符串中的每个字符并应用于helper每个字符,返回一个带有应用结果的列表 - 基本上,实现您自己map的始终适用helper于每个字符输入列表中的元素:

(define (convert lst)
  <???>)

(convert '("c" "a" "t"))
=> '("ɔ" "ɐ" "ʇ")

现在我们可以upside-down使用convert

(define (upside-down str)
  (<???>                   ; finally, do the opposite of explode on the list
   (convert                ; use our shiny new procedure
    (<???> (<???> str))))) ; reverse the exploded string
于 2013-02-18T00:48:46.020 回答