From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: "push" creating circular objects Date: Thu, 21 Aug 2008 20:41:27 +0200 Organization: Informatimago Message-ID: <87pro2ciso.fsf@hubble.informatimago.com> References: <4990de62-178c-478a-9362-cedc660f9335@j22g2000hsf.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1219344039 32252 80.91.229.12 (21 Aug 2008 18:40:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 21 Aug 2008 18:40:39 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Aug 21 20:41:31 2008 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.50) id 1KWF69-0007Q7-Ue for geh-help-gnu-emacs@m.gmane.org; Thu, 21 Aug 2008 20:41:30 +0200 Original-Received: from localhost ([127.0.0.1]:48187 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KWF5C-0005cp-Ll for geh-help-gnu-emacs@m.gmane.org; Thu, 21 Aug 2008 14:40:30 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newsfeed.esat.net!club-internet.fr!feedme-small.clubint.net!proxad.net!feeder1-1.proxad.net!cleanfeed4-a.proxad.net!nnrp7-1.free.fr!not-for-mail Original-Newsgroups: gnu.emacs.help Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:4HLguJuFLqVhh6aJSurnWG7etls= Original-Lines: 112 Original-NNTP-Posting-Date: 21 Aug 2008 20:27:21 MEST Original-NNTP-Posting-Host: 88.182.134.169 Original-X-Trace: 1219343241 news-2.free.fr 19713 88.182.134.169:40857 Original-X-Complaints-To: abuse@proxad.net Original-Xref: news.stanford.edu gnu.emacs.help:161517 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:56860 Archived-At: Charles Sebold writes: > On Aug 20, 4:50 pm, weber wrote: > >> Minor variation: >> >> (defun test2 (str) >> (let (my-list) >> (with-temp-buffer >> (insert str) >> (goto-char (point-min)) >> (while (not (eobp)) >> (cond >> ((= (char-after) ?#) >> (push "ol" my-list)) >> ((= (char-after) ?*) >> (push "ul" my-list))) >> (forward-char 1))) >> my-list)) >> >> no need to bind my-list to nil too :) > > Useful tip, thanks. > > Astoundingly I'm still having the same problem, when I run this in the > context of the larger program. Against the string "** " it returns > the circular list (#1="ul" #1#). In the scratch buffer it works (same > as with my function earlier). This is not a circular list, so whatever you may try or infer from that will be wrong. > So, I must be rebinding something else in a bad way, but heck if I > know how. I'm going to try to trim the whole problem down to a bare > minimum test case and then if I can't figure it out I'll post the > whole thing and ask people to eval and see what they can come up > with. Thanks for your time. (defun circular-length (list) "LIST must be either a proper-list or a circular-list, not a dotted-list. RETURN: the total length ; the length of the stem ; the length of the circle. " (let ((indexes (make-hash-table))) (loop for i from 0 for current on list do (let ((index (gethash current indexes))) (if index ;; found loop (return (values i index (- i index))) (setf (gethash current indexes) i))) finally (return (values i))))) (circular-length '(a b c d e)) --> (5) (circular-length '(#1=a b #1# d #1#)) --> (5) (circular-length '#1=(a b c d e . #1#)) --> (5 0 5) (circular-length '(a b . #1=(c d e . #1#))) --> (5 2 3) Since (#1="ul" #1#) is not a circular list, you can print it without print-circle: (defun print-safely (object) (let ((print-circle (rest (circular-length object)))) (print object))) (print-safely '(a b c d e)) prints: (a b c d e) (print-safely '#1=(a b c d e . #1#)) prints: #1=(a b c d e . #1#) (print-safely '(#1=a b #1# d #1#)) prints: (a b a d a) (print-safely '(#1="ul" #1#)) prints: ("ul" "ul") So what's the difference between ("ul" "ul") and (#1="ul" #1#)? It's that in ("ul" "ul") we have two different string objects that happen to contain the same characters in the same order, while in (#1="ul" #1#) we have the same string object twice: (let ((items '(#1="ul" #1#))) (eq (first items) (second items))) --> t (let ((items '("ul" "ul"))) (eq (first items) (second items))) --> nil -- __Pascal Bourguignon__ http://www.informatimago.com/ ADVISORY: There is an extremely small but nonzero chance that, through a process known as "tunneling," this product may spontaneously disappear from its present location and reappear at any random place in the universe, including your neighbor's domicile. The manufacturer will not be responsible for any damages or inconveniences that may result.