Re: Referencing a row in a two dimensional array

Rudi Schlatte <[email protected]>
Newsgroups gmane.lisp.corman
Organization None
Message-ID <[email protected]>
"SmallHairyTroll <[email protected]>" <[email protected]> writes:

> This is a newbie question, but I can't find an answer in my Lisp 
> text:
>
> I have a two dimensional array (MAKE-ARRAY `(,row ,col)). Currently 
> I am writing binary data to this array a single byte at a time using 
> READ-BYTE from within two nested loops (row & column loops).
>
> I now want to use READ-SEQUENCE to read a chunk of bytes into each 
> row, but I'm stumped as to how I can give READ-SEQUENCE a reference 
> to just the row of the array. This is easy to accomplish in C using 
> pointers, and I am sure it is just as easy in Lisp.
>
> (READ-SEQUENCE (row-reference-here) in-stream 0 row)
>

Have a look at the :displaced-to argument to make-array.  See
<URL:http://www.lispworks.com/reference/HyperSpec/Body/f_mk_ar.htm>
for the details.  With this, you can make a second array that "points
to" a subset of your original array (Sorry for the sloppy wording).

Note that you can't do arbitrary slices, only in row-major order.

Regards,

Rudi
-- 
whois DRS1020334-NICAT                    http://constantly.at/pubkey.gpg.asc
     Key fingerprint = C182 F738 6B9A 83AF 9C25  62D9 EFAE 45A6 9A69 0867

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/FpY02D/vN2EAA/xGHJAA/SyjtlB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.