From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Katalin Sinkov Newsgroups: gmane.emacs.help Subject: Re: How to cast an imperative loop into a readable recursive function ? Date: Thu, 2 Dec 2010 23:37:20 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <87ipzbpgft.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1291949676 21292 80.91.229.12 (10 Dec 2010 02:54:36 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Dec 2010 02:54:36 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 10 03:54:32 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQt7q-0003eR-3w for geh-help-gnu-emacs@m.gmane.org; Fri, 10 Dec 2010 03:54:26 +0100 Original-Received: from localhost ([127.0.0.1]:34002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQt7p-0004mI-AB for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 21:54:25 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!a17g2000yql.googlegroups.com!not-for-mail Original-Newsgroups: comp.lang.lisp,comp.emacs,gnu.emacs.help Original-Lines: 64 Original-NNTP-Posting-Host: 75.28.104.253 Original-X-Trace: posting.google.com 1291361840 9123 127.0.0.1 (3 Dec 2010 07:37:20 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 3 Dec 2010 07:37:20 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a17g2000yql.googlegroups.com; posting-host=75.28.104.253; posting-account=q8u0hAoAAAA7uZRsDFj29PQdwm_l8nyT User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6,gzip(gfe) Original-Xref: usenet.stanford.edu comp.lang.lisp:296051 comp.emacs:100895 gnu.emacs.help:182802 X-Mailman-Approved-At: Thu, 09 Dec 2010 20:08:59 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:77233 Archived-At: On Dec 2, 9:35=A0pm, "Pascal J. Bourguignon" wrote: > Katalin Sinkov writes: > > Take a look at my lisp code. it can be modified simply to run it and > > it runs in an emacs "ide". > > No it does not. =A0 > > First, it's lacking a parenthesis. > > You should get paredit.el, and activate the paredit-mode to edit lisp > sources. =A0See how lisp code is indented, and let emacs and paredit > indent it for you, and place the parentheses for you. =A0This will produc= e > lisp code that is more readable, and you will be able to copy-and-paste > sexps "structurally", with much less risk of losing parentheses. > > Then, if we add the obvious missing parenthesis, and try to evaluate > your code: > > =A0 =A0 (let ((char_skips (- n =A0s) )) > =A0 =A0 =A0 (while (not (=3D char_skips 0)) > =A0 =A0 =A0 =A0 (progn > =A0 =A0 =A0 =A0 =A0 (if (<=3D char_skips (+ l -1) ) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 (progn > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (forward-char char_skips) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (setq char_skips 0)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 (progn > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (forward-char l) > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (forward-search-regexp "(s=3D###l=3D###)"= nil nil nil) ; put in an if > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;; and else block to test if FAIL > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (setq s (match-string 0)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (setq l (match-string 0)) > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (setq char_skips (- n s) )))))) > > we get the following error: > > =A0 =A0 Debugger entered--Lisp error: (void-variable n) > =A0 =A0 =A0 (- n s) > =A0 =A0 =A0 (let ((char_skips ...)) (while (not ...) (progn ...))) > =A0 =A0 =A0 eval((let ((char_skips ...)) (while (not ...) (progn ...)))) > =A0 =A0 =A0 eval-last-sexp-1(nil) > =A0 =A0 =A0 eval-last-sexp(nil) > =A0 =A0 =A0 call-interactively(eval-last-sexp nil nil) > > If you want us to help, please provide working stand alone code, with > test data. > > (By the way, my emacs "23.2.1" doesn't have a forward-search-regexp > function). search-forward-regexp more later tomorrow > > -- > __Pascal Bourguignon__ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0http://www.= informatimago.com/ > A bad day in () is better than a good day in {}.