From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Greg Hill Newsgroups: gmane.emacs.help Subject: Re: How to parse a string? Date: Thu, 1 May 2003 16:41:39 -0700 Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <87ade7d023.fsf@noos.fr> <87fznygypu.fsf@thalassa.informatimago.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Trace: main.gmane.org 1051832558 24176 80.91.224.249 (1 May 2003 23:42:38 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 1 May 2003 23:42:38 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Fri May 02 01:42:36 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19BNhE-0006Hd-00 for ; Fri, 02 May 2003 01:42:36 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19BNi4-0005Sb-02 for gnu-help-gnu-emacs@m.gmane.org; Thu, 01 May 2003 19:43:28 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 19BNhd-0005Kr-00 for help-gnu-emacs@gnu.org; Thu, 01 May 2003 19:43:01 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 19BNhI-0004qQ-00 for help-gnu-emacs@gnu.org; Thu, 01 May 2003 19:42:40 -0400 Original-Received: from renfield.synergymicro.com ([153.105.4.30] helo=synergymicro.com) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19BNgv-0004eH-00 for help-gnu-emacs@gnu.org; Thu, 01 May 2003 19:42:18 -0400 Original-Received: from synergy.synergy.encinitas.ca.us ([153.105.4.29]) by synergymicro.com (8.9.3/8.9.3) with ESMTP id QAA02062 for ; Thu, 1 May 2003 16:43:42 -0700 Original-Received: from [198.17.100.22] (G_Hill_Mac [198.17.100.22]) h41NnfoJ018003 for ; Thu, 1 May 2003 16:49:41 -0700 In-Reply-To: <87fznygypu.fsf@thalassa.informatimago.com> Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:9139 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:9139 At 11:10 PM +0200 5/1/03, Pascal Bourguignon wrote: >Francois Fleuret writes: > > But is there a generic way to do such a thing ? No scanf equivalent > > around ? >Just encapsulate the line with '( ... ): > > (defun scanf (string) ;; no need to specify the format and the variable, > "We return a list of item scanned from the string." > (read (concat "( " string " )"))) > >(dolist (item (scanf "10 20 3.33 wordA wordB wordC")) > (show item (type-of item))) > >==> (10 integer) >==> (20 integer) >==> (3.33 float) >==> (wordA symbol) >==> (wordB symbol) >==> (wordC symbol) Nice trick, if you want the strings read as symbols. If you're looking for strings, how about: (defun scanf (string) "We return a list of items scanned from the string." (mapcar (lambda (x) (if (symbolp x) (symbol-name x) x)) (read (concat "( " string " )")))) By the way, where is that "show" function defined? I presume it is effectively: (defun show (&rest args) (princ "==> ") (princ args) (terpri)) --Greg