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: string to list or string to array Date: Sun, 21 Oct 2012 22:22:40 +0200 Organization: Informatimago Message-ID: <87zk3f7ey7.fsf@kuiper.lan.informatimago.com> References: <62642868-f757-4115-a047-34c319a1c30f@o5g2000yqi.googlegroups.com> <87pq4c848a.fsf@kuiper.lan.informatimago.com> <4e87f58c-72fc-457b-8596-c792c39472e5@m4g2000yqb.googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1350851114 11187 80.91.229.3 (21 Oct 2012 20:25:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 21 Oct 2012 20:25:14 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Oct 21 22:25:21 2012 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 1TQ25I-0005HK-Fa for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Oct 2012 22:25:20 +0200 Original-Received: from localhost ([::1]:44385 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQ25B-0004F9-1S for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Oct 2012 16:25:13 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs Original-Lines: 65 Original-X-Trace: individual.net 74MYJlpykvST8r/dTNSrRwQoFCd4r7ifa9MMAk3Hyn8M5LPBYFiQ+NXOC1pWKAIeMK Cancel-Lock: sha1:MmRhM2Y5NTM3MDk4YjJhZGNkNGQxMDViYmRjOWU5NDRkOTQ2MjcyOQ== sha1:0KOpmYeXcw/npg1UewEB4/nCYWE= 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/23.4 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:195021 comp.emacs:102642 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:87350 Archived-At: Swami Tota Ram Shankar writes: > On Oct 21, 4:16 am, "Pascal J. Bourguignon" > wrote: >> Since the syntax of this text is exactly the printed representation of >> an emacs lisp vector, you can read it directly with read. >> >> (defun get-vectors-from-buffer () >>    (let ((vectors '())) >>      (goto-char (point-min)) >>      (while (re-search-forward "\\[[0-9.+-\\ ]+\\]" nil t) >>         (goto-char (match-beginning 0)) >>         (push (read (current-buffer)) vectors)) >>      (nreverse vectors))) >> >> ;; [1 2 3.0] [4 5 6] >> ;; [7 +8 -9] >> >> (get-vectors-from-buffer) >> --> ([[0-9\.+-\\] +] >>      [[0-9\.+-\\] +\\] >>      [17.16 -17.16 17.16 17.16 17.16 17.16 17.16 17.16] >>      [[0-9\.+-\\] +\\] >>      [1 2 3.0] >>      [4 5 6] >>      [7 8 -9]) >> > > Hi Pascal, Thanks for the reply but there are some problems. I > understood your change to regexp. > > However, you are doing too much in your and I need only read one > string at a specific location at a time, not the whole buffer. > > Thus, I am having difficulty and need help. Let me write the modified > story again. > > (when (looking-at "\\[[0-9.+-\\ ]+\\]") > (forward-char (+ (string-width (match-string 0)) 1)) > (setq V (match-string 0)) > (setq V (read-from-string (intern (match-string 0)))) 0- What's the purpose of moving the point? 1- Don't use setq, use let. 2- Don't bind two different things to the same variable! 3- read-from-string reads from a string, not a symbol, so why are you interning a symbol? Let me advise you to read: An Introduction to Programming in Emacs Lisp http://www.gnu.org/software/emacs/emacs-lisp-intro/ or M-: (info "(eintr)Top") RET (defun get-vector-at-point () (when (looking-at "\\[[0-9.+-\\ ]+\\]") (goto-char (match-beginning 0)) (read (current-buffer)))) -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}.