From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: Using append to create a list from a line of text Date: Tue, 16 Apr 2013 22:51:00 +0200 Organization: Informatimago Message-ID: <87ip3m6vyj.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1366150587 24045 80.91.229.3 (16 Apr 2013 22:16:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 16 Apr 2013 22:16:27 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Apr 17 00:16:30 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1USEAs-0008MN-5n for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Apr 2013 00:16:26 +0200 Original-Received: from localhost ([::1]:60717 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USEAr-0004YC-Mq for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Apr 2013 18:16:25 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 69 Original-X-Trace: individual.net nvA18XVBKfcYyHdazyi/8QFBBwu4k0Vspy1uUjX6zvQef6rrh6 Cancel-Lock: sha1:ODc5YmUzZmQ3NjdkZjM1MWEwZGZlYmUxM2NkODMyOGZiYTQ2MzQwYg== sha1:uyXGqdvtBBBGnO93cgenGoNbHVk= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:197932 X-Mailman-Approved-At: Tue, 16 Apr 2013 18:16:11 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:90200 Archived-At: acomber 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 {}.