Re: Trade-off, option, choice.
- From: "Carl Taylor" <carltaylor@xxxxxxx>
- Date: Sat, 31 Dec 2005 17:24:42 GMT
verec wrote:
I've got a two dimensional grid of characters.
At one stage, I need to extract strings from the grid, either on a row by row basis, or on a column by column basis.
[...]
Anyone see any other options I missed?
I' m a big fan of (1) the :displaced-to feature of <make-array>, and (2) <loop>.
Carl Taylor
(defun get-char-grid-row (row x-grid) (declare (type fixnum row)) (let ((col-cnt (array-dimension x-grid 1))) (map 'string #'identity (make-array col-cnt :element-type (array-element-type x-grid) :displaced-to x-grid :displaced-index-offset (* row col-cnt)))))
(defun get-char-grid-col (col x-grid) (declare (type fixnum col)) (map 'string #'identity (loop :for i fixnum :repeat (the fixnum (array-dimension x-grid 0)) :collect (aref x-grid i col))))
CL-USER 13 > (get-char-grid-row 2 #2A((#\a #\b #\c) (#\d #\e #\f) (#\g #\h #\i))) "ghi"
CL-USER 14 >
(get-char-grid-col 1 #2A((#\a #\b #\c) (#\d #\e #\f) (#\g #\h #\i))) "beh"
.
- Follow-Ups:
- Re: Trade-off, option, choice.
- From: verec
- Re: Trade-off, option, choice.
- References:
- Trade-off, option, choice.
- From: verec
- Trade-off, option, choice.
- Prev by Date: Re: Python and Lisp Test
- Next by Date: Re: Trade-off, option, choice.
- Previous by thread: Trade-off, option, choice.
- Next by thread: Re: Trade-off, option, choice.
- Index(es):