* Using append to create a list from a line of text
@ 2013-04-16 9:58 acomber
2013-04-16 10:05 ` Christopher Schmidt
2013-04-16 13:10 ` Drew Adams
0 siblings, 2 replies; 6+ messages in thread
From: acomber @ 2013-04-16 9:58 UTC (permalink / raw)
To: Help-gnu-emacs
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
)
)
)
)
How do I get my function to return the list, mylist?
--
View this message in context: http://emacs.1067599.n5.nabble.com/Using-append-to-create-a-list-from-a-line-of-text-tp283808.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Using append to create a list from a line of text
2013-04-16 9:58 Using append to create a list from a line of text acomber
@ 2013-04-16 10:05 ` Christopher Schmidt
2013-04-16 13:10 ` Drew Adams
1 sibling, 0 replies; 6+ messages in thread
From: Christopher Schmidt @ 2013-04-16 10:05 UTC (permalink / raw)
To: help-gnu-emacs
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.
(save-restriction
(narrow-to-region (line-beginning-position) (line-end-position))
(split-string (buffer-string) "\t+"))
> The code below is sort of pseudocode but is this the best approach to
> do this type of thing?
[...]
> How do I get my function to return the list, mylist?
M-: (info "(eintr)Top") RET
Christopher
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Using append to create a list from a line of text
2013-04-16 9:58 Using append to create a list from a line of text acomber
2013-04-16 10:05 ` Christopher Schmidt
@ 2013-04-16 13:10 ` Drew Adams
1 sibling, 0 replies; 6+ messages in thread
From: Drew Adams @ 2013-04-16 13:10 UTC (permalink / raw)
To: 'acomber', Help-gnu-emacs
> 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.
C-h f split-string
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Using append to create a list from a line of text
[not found] <mailman.24205.1366106299.855.help-gnu-emacs@gnu.org>
@ 2013-04-16 20:51 ` Pascal J. Bourguignon
2013-04-17 16:27 ` Barry Margolin
0 siblings, 1 reply; 6+ messages in thread
From: Pascal J. Bourguignon @ 2013-04-16 20:51 UTC (permalink / raw)
To: help-gnu-emacs
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!
3- "[A-Za-z]+[^\t\n]" is not a symbol naming an operator, nor is it a
lambda expression, therefore the sexp ("[A-Za-z]+[^\t\n]" nil t) is
not a lisp form.
4- undefined avariable named `append'.
5- while re-search-forward takes optionally up to four arguments, I
doubt that mylist is bound to the count of searches to do, or that
(match-string 1) returns whether you want or not to signal errors if
no match is found.
> How do I get my function to return the list, mylist?
Try to read a lisp tutorial again. On the first chapter, the basic
syntactic elements are always presented. You should have no problem
understanding them and correcting your code.
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Using append to create a list from a line of text
2013-04-16 20:51 ` Pascal J. Bourguignon
@ 2013-04-17 16:27 ` Barry Margolin
2013-04-17 18:23 ` Pascal J. Bourguignon
0 siblings, 1 reply; 6+ messages in thread
From: Barry Margolin @ 2013-04-17 16:27 UTC (permalink / raw)
To: help-gnu-emacs
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 ***
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Using append to create a list from a line of text
2013-04-17 16:27 ` Barry Margolin
@ 2013-04-17 18:23 ` Pascal J. Bourguignon
0 siblings, 0 replies; 6+ messages in thread
From: Pascal J. Bourguignon @ 2013-04-17 18:23 UTC (permalink / raw)
To: help-gnu-emacs
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 {}.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-04-17 18:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-16 9:58 Using append to create a list from a line of text acomber
2013-04-16 10:05 ` Christopher Schmidt
2013-04-16 13:10 ` Drew Adams
[not found] <mailman.24205.1366106299.855.help-gnu-emacs@gnu.org>
2013-04-16 20:51 ` Pascal J. Bourguignon
2013-04-17 16:27 ` Barry Margolin
2013-04-17 18:23 ` Pascal J. Bourguignon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).