方案 - 字符串追加两个字符串列表

标签 scheme racket

我正在尝试附加两个字符串列表

但我不知道如何在两个单词之间添加空格。

(define (string-concat lst1 lst2)
        (map string-append lst1 lst2)
)
(string-concat '("elementary") "(school))

然后结果为“小学”

合并时如何添加空间? 我尝试过使用 lambda 但它不起作用,例如

(map string-append (cdr (append* (map (lambda (x) list " " x)) lst1)) lst2)

最佳答案

使用 add- Between 在字符串之间添加空格:

> (add-between '("This" "and" "that") " ")
'("This" " " "and" " " "that")

要在列表中追加字符串,请使用string-append*

> (string-append* '("This" " " "and" " " "that"))
"This and that"

你的函数变成:

 (define (string-concat lst1 lst2)
     (string-append* (add-between (append lst1 lst2) " ")))

其中 append 用于将两个列表合并为一个。

关于方案 - 字符串追加两个字符串列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50850627/

相关文章:

recursion - 在Racket博士中,如何编写Tetration函数

namespaces - 在 Racket 中,嵌套函数定义不需要 "local"吗?

recursion - 如何从方案、 Racket 中的列表制作 HTML

list - 使用 Racket append 到列表变量

scheme - SICP 1.45 - 为什么这两个高阶函数不等价?

scheme - 程序与内置数据

macros - Racket 宏可自动定义给定列表的函数

方案缺点和长度

macros - 什么是 "3D syntax"?

forms - 在 Racket 中向 servlet 提交 HTML 表单