From: Harald Kucharek
Subject: Reading hexfile in CL
Date: 
Message-ID: <2445@idtuva.kfk.de>
My problem: I want to read hexnumbers from a textfile which has the following format:

0xFFFF,0xFFFF,0xFFFF,0xFFFF,
0x8000,0x0000,0x0000,0x0001,
	    :
0x800C,0x0661,0x8C30,0x0001
	
If there would be no comma following the number without an whitespace char, 
it would be no problem. Just scan the file until an 'x' appears and then do an 

(let* ((*read-base* 16))(read stream))
	
This fails because of the comma:

Error: A comma appears outside the scope of a backquote 

I read something that it is possible to change the behaviour of the lisp-reader. 
Is there perhaps an easy way to declare an comma locally as an whitespace character?

Any help or suggestions would be appreciated.

Harald

P.S.: I know, the most 'systematic' approach would be to write a parser for this file format.
      My problem is: I feel, there is a nice & easy way to do the job in CL.

--------- Harald Kucharek
    |     Kernforschungszentrum Karlsruhe 
    |	  (Nuclear Research Center Karlsruhe)
    |     IDT
--------- 7514 Eggenstein-Leopoldshafen
    ^     Germany
   / \
  /   \   Internet: ·····@issun1.kfk.de
 /     \  Phone   : +49 7247 825706
/       \ Fax     : +49 7247 825786
From: Barry Margolin
Subject: Re: Reading hexfile in CL
Date: 
Message-ID: <kqtai4INNl8g@early-bird.think.com>
In article <····@idtuva.kfk.de> ·····@issun1.kfk.de writes:
>My problem: I want to read hexnumbers from a textfile which has the following format:
>
>0xFFFF,0xFFFF,0xFFFF,0xFFFF,
>0x8000,0x0000,0x0000,0x0001,
...
>I read something that it is possible to change the behaviour of the lisp-reader. 
>Is there perhaps an easy way to declare an comma locally as an whitespace character?

(defvar *comma-readtable* (copy-readtable))
(set-syntax-from-char #\, #\space *comma-readtable*)

(let ((*read-base* 16)
      (*readtable* *comma-readtable*))
  (read stream))

>P.S.: I know, the most 'systematic' approach would be to write a parser for this file format.
>      My problem is: I feel, there is a nice & easy way to do the job in CL.

That's actually my preference.  READ is an extremely general mechanism, and
usually overkill when you're not inputting stuff that uses the full Lisp
syntax.  In this case, I'd use READ-LINE, search for the 0x and comma, and
then call PARSE-INTEGER on the substring, e.g.:

(loop for start = (search "0x" line) then (search "0x" line :start2 (1+ start))
      for end = (when start (position #\, line :start start))
      while start
      collect (parse-integer line :radix 16 :start (+ start 2) :end end))
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar