Scheme 将弦上下颠倒拍子

Scheme 将弦上下颠倒拍子,scheme,racket,Scheme,Racket,我把信弄翻了ptod我似乎无法让一串单词颠倒过来。像房子上下颠倒成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)

我把信弄翻了
p
to
d
我似乎无法让一串单词颠倒过来。像
房子
上下颠倒成
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")

关于您的
助手
过程的几点评论:

  • 字符
    不在列表中时,您应该添加一个额外的条件-如果发生这种情况,只需返回相同的
    字符
    。否则,将发生错误
  • 该参数不应命名为
    list
    ,这是一个内置过程,覆盖它是一种不好的做法
  • 在继续之前彻底测试它
一旦解决了这个问题,下面是如何实现倒置的
,请填写以下空白:

(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
现在,我们可以使用
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
(定义(上下颠倒)
(;最后,在列表上执行与爆炸相反的操作
(转换;使用我们全新的程序
((str()()));;把爆炸的绳子倒过来

关于您的
帮助程序的几点评论:

  • 字符
    不在列表中时,您应该添加一个额外的条件-如果发生这种情况,只需返回相同的
    字符
    。否则,将发生错误
  • 该参数不应命名为
    list
    ,这是一个内置过程,覆盖它是一种不好的做法
  • 在继续之前彻底测试它
一旦解决了这个问题,下面是如何实现倒置的
,请填写以下空白:

(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
现在,我们可以使用
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
(定义(上下颠倒)
(;最后,在列表上执行与爆炸相反的操作
(转换;使用我们全新的程序
((str()()));;把爆炸的绳子倒过来

不过,我找到了另一种(更简单的)方法,使用beginng学生语言。别以为我已经复习过了,我想出了另一个(更简单的)方法,用初学者的语言。别以为我看过兰姆达汉克斯。但是兰姆达呢?你用什么语言?我正在使用带删节的初学者。@JerryLynch查看我的更新答案,以获得没有
map
lambda
的解决方案,我不太确定。这不应该是类似于我的助手功能吗?哇哦。我知道了!谢谢。@JerryLynch好极了!我真的很高兴:)谢谢。但是兰姆达呢?你用什么语言?我正在使用带删节的初学者。@JerryLynch查看我的更新答案,以获得没有
map
lambda
的解决方案,我不太确定。这不应该是类似于我的助手功能吗?哇哦。我知道了!谢谢。@JerryLynch好极了!我真的很高兴:)