help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: need help with a defun


From: Barry Margolin
Subject: Re: need help with a defun
Date: Mon, 07 Jul 2003 21:05:57 GMT

In article <3F09E01F.10207@gmx.de>, Bernd Wolter  <mathae.wolter@gmx.de> wrote:
>Hi group,
>
>I wrote a little program in elisp, to help me analyze the contents of a 
>text file. The text file has patterns of interest to me and lots of 
>cruft. In the first step I get rid of the cruft. This part works. In the 
>second step I want to get each pattern into a line of its own to in the 
>further steps sort, count and re-sort them according to number of 
>occurrence.
>
>I got it all done and it works - well, sort of and that's why I'm asking 
>here. As you can see below I really don't exactly know what I am doing.
>
>I do the second step like this:
>
>(defun clean ()
>   "Doc string"
>   (while (not (eobp))
>     (re-search-forward ";\\s-*") ;;pattern of interest delimited by "; "
>     (search-backward ";")
>     (let* ((beg (point)))
>       (while (looking-at "[; ]") ;;is there another pattern on the same 
>line?
>       (forward-char))
>       (delete-region beg (point)))
>     (if (looking-at "[\n]")  ;;are we looking at the end of a line
>       (forward-char)       ;;goto the next line
>       (insert-string "\n"))  ;;otherwise divide the line
>     (clean)))
>
>As you old hands will see presently (and I have learned in the meantime) 
>the recursive call to "clean" will quickly get me into trouble with 
>"max-specpdl-size" and "max-lisp-eval-depth". I read up on them in the 
>docs and think I understand why they are there to protect me and the 
>other unwary from ourselves.

Why are you calling it recursively at all?  You're in a while loop, which
will repeat the code until it's done.

What you're missing is that the while loop should also terminate when the
re-search-forward fails, so it should be:

(while (and (not (eobp))
            (re-search-forward ";\\s-*"))

-- 
Barry Margolin, barry.margolin@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]