gpt4 book ai didi

string - subseq (LISP) 的简单问题

转载 作者:太空宇宙 更新时间:2023-11-03 18:36:38 25 4
gpt4 key购买 nike

我刚开始使用 LISP,具有 C 语言背景。到目前为止它很有趣,尽管学习曲线令人难以置信(我也是 emacs 新手)。

无论如何,我在解析来自 c 源代码的 include 语句时遇到了一个愚蠢的问题——如果有人可以对此发表评论并提出解决方案,那将大有帮助。

(defun include-start ( line )
(search "#include " line))

(defun get-include( line )
(let ((s (include-start line)))
(if (not (eq NIL s))
(subseq line s (length line)))))

(get-include "#include <stdio.h>")

我希望最后一行返回

"<stdio.h>"

然而实际结果却是

"#include <stdio.h>"

有什么想法吗?

最佳答案

(defun include-start (line)
"returns the string position after the '#include ' directive or nil if none"
(let ((search-string "#include "))
(when (search search-string line)
(length search-string))))

(defun get-include (line)
(let ((s (include-start line)))
(when s
(subseq line s))))

关于string - subseq (LISP) 的简单问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1398014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com