Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.kei.com!newsfeed.internetmci.com!in1.uu.net!news.maz.net!news.ppp.net!news.Hanse.DE!wavehh.hanse.de!cracauer
From: cracauer@wavehh.hanse.de (Martin Cracauer)
Subject: Re: Read/write binary files in Scheme? In Scsh?
Message-ID: <1995Nov20.141202.4705@wavehh.hanse.de>
Organization: BSD User Group Hamburg
References: <48jctp$iil@news.connectnet.com>
Date: Mon, 20 Nov 95 14:12:02 GMT
Lines: 36

dmb@news.connectnet.com (David Brumley) writes:

>How do I portably read and write binary files in Scheme?  For example,
>I want to write run-length-encoded pixmaps for the Utah Raster Toolkit.
>Since the R^4RS didn't give me any clues, I tried writing my own write-byte
>function:

>  (define (write-byte byte)
>     (write-char (integer->char byte)))

[...]

>Using ascii->char instead of integer->char in write-byte seems to work, but 
>there must be a much more portable, much more efficient, way to do binary file
>I/O.

IMHO, reading binary files written out from other langauges is as much
an alien issue as alien code is. As such, handling binary I/O should
be handled in C code via the FFI.

An alternative to FFI usage would be a Unix-Filter in C that outputs
scheme-readable code and is called from a popen()-equivalent from
scheme or if such a call doesn't exist, a named pipe which can be
constructued with every system()-like call.

Note that building multi-byte integer values can be very costly in
scheme, I guess more costly than reading ascii integers (which
should be implemented in C code in most scheme implementations).

Just IMHO, of course.

Martin
-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <cracauer@wavehh.hanse.de>  - BSD User Group Hamburg, Germany 
"As far as I'm concerned,  if something is so complicated that you can't ex-"
"plain it in 10 seconds, then it's probably not worth knowing anyway"- Calvin
