[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: |
Pascal J. Bourguignon |
Subject: |
Re: Using append to create a list from a line of text |
Date: |
Wed, 17 Apr 2013 20:23:20 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
Barry Margolin <barmar@alum.mit.edu> writes:
> 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.
Indeed, I missed it. But also, if you write your pseudo code as a
possibly valid lisp form, you can easily make it executable:
http://groups.google.com/group/comp.lang.lisp/msg/a827235ce7466a92
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.