Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple issue with subseq (LISP)

I just started using LISP, coming from a background in C. So far its been fun, although with an incredible learning curve (I'm an emacs newbie too).

Anyway, I'm having a silly issue with the following code to parse include statements from c source - if anyone can comment on this and suggest a solution, it would help a lot.

(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>")

I expect the last line to return

"<stdio.h>"

However the actual result is

"#include <stdio.h>"

Any thoughts?

like image 855
Justicle Avatar asked Sep 09 '09 07:09

Justicle


1 Answers

(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))))
like image 182
Rainer Joswig Avatar answered Nov 03 '22 15:11

Rainer Joswig