如何从嵌套层级的列表中提取所需信息

原数据结构:

(
 (
  (noteId . 1675318046934)
  (tags)
  (fields
   (transcription
    (value . "We can't! The containment field is failing. The portal is gonna tear itself apart!
我们关不掉的!遏制场正在失效。传送门会自己销毁!")
    (order . 0))
   (pronunciation
    (value . "")
    (order . 1))
   (meaning
    (value . "")
    (order . 2))
   (notes
    (value . "")
    (order . 3))
   (sound
    (value . "[sound:eudic_2_07_PM_containment.mp3]")
    (order . 4))
   (image
    (value . "")
    (order . 5)))
  (modelName . "Audio note (English)")
  (cards 1675318046934)
 )
 (
  (noteId . 1675318213063)
  (tags)
  (fields
   (transcription
    (value . "It was really about a portal to knowledge, different environments and adapting.
更是让我收获了知识,应对不同环境时学会了适应。")
    (order . 0))
   (pronunciation
    (value . "/'pɔrtl/")
    (order . 1))
   (meaning
    (value . "")
    (order . 2))
   (notes
    (value . "")
    (order . 3))
   (sound
    (value . "[sound:eudic_2_10_PM_portal.mp3]")
    (order . 4))
   (image
    (value . "")
    (order . 5)))
  (modelName . "Audio note (English)")
  (cards 1675318213063)
 )
)

希望达到效果:

(
 [:noteId 1675318046934 :transcription "We can't! The containment field is failing. The portal is gonna tear itself apart! 我们关不掉的!遏制场正在失效。传送门会自己销毁!" :sound "[sound:eudic_2_07_PM_containment.mp3]"]
 [:noteId 1675318213063 :transcription "It was really about a portal to knowledge, different environments and adapting. 更是让我收获了知识,应对不同环境时学会了适应。" :sound "[sound:eudic_2_10_PM_portal.mp3]" ]
)

和这个话题类似:如何将嵌套树状列表压平为alist(包含层级信息)

该话题的解决方案超出了我现有 elisp 的认知水平,看不懂如何实现,无从下手进行修改借鉴。

感谢哪位大佬指点。

了解一下“递归”就知道了

复习或者学习一下《数据结构》中关于如何遍历树形数据结构。

你这是anki-connect的返回结果吧。

(defun test (notesinfo)
  (mapcar
   (lambda (x)
     (let* ((noteid (cdr (assq 'noteId x)))
            (fields (cdr (assq 'fields x)))
            (transcription (cdar (cdr (assq 'transcription fields))))
            (sound (cdar (cdr (assq 'sound fields)))))
       (vector
        :noteId noteid
        :transcription transcription
        :sound sound)))
   notesinfo))
2 个赞

完美运行,谢谢大佬。

是在写 anki-editor 的函数返回结果使用的。

不用不用,只是正好我最近也在写跟anki有关的包,稍微熟悉一点而已。