From: Matthew Swank
Subject: FORMAT/scanf style input parsing
Date: 
Message-ID: <pan.2007.08.17.23.57.57.577556@c.net>
Lisp has read. Read is nice enough. However, since at least the time of
fortran many computer languages have supported simple input parsing
based on the same kinds of specifications used to generated formatted
output.  Witness C's scanf/printf, fortran's FORMAT, and C#'s
IFormatProvider interface.

Has lisp ever had support for parsing based on some subset of format
control-string language?  The reason I ask is that after porting some old
fortran in the recent past, I realize that i kind of miss having a
way to conveniently parse moderately structured input.  I know for
extremely simple things there are libs like SPLIT-SEQUENCE, and cl-ppcre
and parser generators for more complicated parsing.  However, there is a
sweet spot for parsers like FORMAT (not to mention the symmetry of
notation).

Just curious,

Matt 

-- 
"You do not really understand something unless you
 can explain it to your grandmother." - Albert Einstein.

From: Andrew Philpot
Subject: Re: FORMAT/scanf style input parsing
Date: 
Message-ID: <slrnfccfds.kv.philpot@ubirr.isi.edu>
On 2007-08-17, Matthew Swank <································@c.net> wrote:
> Has lisp ever had support for parsing based on some subset of format
> control-string language?  
>
> Just curious,
>
> Matt 
>

http://www.dirk-zoller.de/lisp/scan.lisp

-- 
Andrew Philpot
USC Information Sciences Institute
·······@isi.edu
From: Juho Snellman
Subject: Re: FORMAT/scanf style input parsing
Date: 
Message-ID: <slrnfccqf9.i31.jsnell@sbz-30.cs.Helsinki.FI>
Matthew Swank <································@c.net> wrote:
> Lisp has read. Read is nice enough. However, since at least the time of
> fortran many computer languages have supported simple input parsing
> based on the same kinds of specifications used to generated formatted
> output.  Witness C's scanf/printf, fortran's FORMAT, and C#'s
> IFormatProvider interface.
>
> Has lisp ever had support for parsing based on some subset of format
> control-string language?  The reason I ask is that after porting some old
> fortran in the recent past, I realize that i kind of miss having a
> way to conveniently parse moderately structured input.  I know for
> extremely simple things there are libs like SPLIT-SEQUENCE, and cl-ppcre
> and parser generators for more complicated parsing.  However, there is a
> sweet spot for parsers like FORMAT (not to mention the symmetry of
> notation).

There's an implementation of (SETF FORMAT):

http://www-jcsu.jesus.cam.ac.uk/~csr21/format-setf.lisp

-- 
Juho Snellman
From: Matthew Swank
Subject: Re: FORMAT/scanf style input parsing
Date: 
Message-ID: <pan.2007.08.18.16.35.27.543789@c.net>
On Sat, 18 Aug 2007 03:39:21 +0000, Juho Snellman wrote:

> There's an implementation of (SETF FORMAT):
> 
> http://www-jcsu.jesus.cam.ac.uk/~csr21/format-setf.lisp


Immediately I thought of:

(defmacro format-bind ((control-string &rest vars) string &body body)
  `(let ,vars
     (setf (format nil ,control-string ,@vars) ,string)
     ,@body))

Of course it needs a little more macro foo to deal with declarations.

Matt
-- 
"You do not really understand something unless you
 can explain it to your grandmother." - Albert Einstein.