subseq(LISP)的简单问题

Jus*_*cle 6 lisp string common-lisp

我刚开始使用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>")
Run Code Online (Sandbox Code Playgroud)

我希望最后一行能够返回

"<stdio.h>"
Run Code Online (Sandbox Code Playgroud)

但实际结果是

"#include <stdio.h>"
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

Rai*_*wig 6

(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))))
Run Code Online (Sandbox Code Playgroud)