[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using append to create a list from a line of text
From: |
Barry Margolin |
Subject: |
Re: Using append to create a list from a line of text |
Date: |
Wed, 17 Apr 2013 12:27:58 -0400 |
User-agent: |
MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) |
In article <87ip3m6vyj.fsf@kuiper.lan.informatimago.com>,
"Pascal J. Bourguignon" <pjb@informatimago.com> wrote:
> acomber <deedexy@gmail.com> writes:
>
> > I want to create a list of words from a line of text delimitted by tabs. I
> > want to basically split the line into atoms, split by tab.
> >
> > The code below is sort of pseudocode but is this the best approach to do
> > this type of thing?
> >
> > Here is my first attempt:-
> >
> > (defun get-hdr()
> > ;obviously point must be positioned on correct line
> > (let (mylist)
> > while(not (end-of-line)
> > while(re-search-forward ("[A-Za-z]+[^\t\n]" nil t)
> > append (match-string 1) mylist
> > )
> > )
> > )
> > )
>
> Nice, but it's not formatted correctly. I'd avise you to use
> paredit-mode.
>
> Adding and removing newlines where one should, and letting emacs indent
> the sexp, we get this text:
>
>
> (defun get-hdr()
> ;; obviously point must be positioned on correct line
> (let (mylist)
> while
> (not (end-of-line)
> while
> (re-search-forward ("[A-Za-z]+[^\t\n]" nil t)
> append
> (match-string 1)
> mylist))))
>
> Now, two obvious things:
>
> 1- undefined variable named `while'. Where does that variable come
> from?
>
> 2- the function `not' is passed three arguments, when it expects only
> one!
I think you missed that he said this was pseudo-code, not valid Lisp
code.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***