List 嵌套列表inlisp

List 嵌套列表inlisp,list,lisp,List,Lisp,我有一个练习,得到一个嵌套列表,并用一个“有趣”的单词替换每个单词。我们得到了一份关于“有趣”这个词的声明 我写了这段代码 (defun funny_nestes (nested_l) (cond ((null nested_l) "") ((atom (car nested_l)) (cons (funnyw (car nested_l)) (funny_nestes (cdr nested_l)))) (t

我有一个练习,得到一个嵌套列表,并用一个“有趣”的单词替换每个单词。我们得到了一份关于“有趣”这个词的声明

我写了这段代码

(defun funny_nestes (nested_l)
  (cond ((null nested_l) "")
        ((atom (car nested_l))
         (cons (funnyw (car nested_l))
               (funny_nestes (cdr nested_l))))
        (t (cons (funny_nestes (car nested_l))
                 (funny_nestes (cdr nested_l))))))
当'funnyw'是返回“有趣”单词的函数时

如果我跑

(FUNNY_NESTES '(ata (she lamadta be JCT) oved be NDS))
我明白了

("AbATAbA " ("SHEbE " "LAbAMAbADTAbA " "BEbE " "JCT " . "")
 "ObOVEbED " "BEbE " "NDS " . "")
我想得到

(AbATAb (SHEbE LAbAMAbADTAbA  BEbE  JCT) ObOVEbED  BEbE  NDS )

我怎样才能修好它?我怎样才能用lambda做到这一点?

我怎样才能用lambda做到这一点?“用lambda做到”是什么意思

为什么代码中有空字符串


如果您想要符号而不是字符串,那么您需要将字符串转换为符号。

我将在黑暗中尝试一下,假设这是所要求的:

(defun replace-with-gibberish (modifier words)
  (cond
    ((null words) nil)
    ((consp (car words))
     (cons (replace-with-gibberish modifier (car words))
           (replace-with-gibberish modifier (cdr words))))
    (t (cons (funcall modifier (car words))
             (replace-with-gibberish modifier (cdr words))))))

(replace-with-gibberish
 #'(lambda (x)
     (intern
      (coerce
       (mapcan #'list
               (coerce (symbol-name x) 'list)
               (coerce
                (make-string
                 (length (symbol-name x))
                 :initial-element #\b) 'list)) 'string)))
 '(ata (she lamadta be JCT) oved be NDS))
我可以从你展示的结果中推断出来。但是,您应该知道,如果您想摆脱符号周围的管道,您需要使用大写字母为符号生成乱码名称。(默认情况下,符号名称为大写,如果它们需要包含小写字母,则需要转义)


你的问题是,你基本上得到了你发布的功能,但你没有发布的功能似乎是错误的(有趣的)。我继续说,假设您只想用任何函数替换它,这就是为什么这个示例。

空字符串用于递归函数的基本情况