Re: Trade-off, option, choice.
- From: verec <verec@xxxxxxx>
- Date: Sat, 31 Dec 2005 18:58:15 +0000
On 2005-12-31 17:24:42 +0000, "Carl Taylor" <carltaylor@xxxxxxx> said:
(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"
That's very interesting, but you still end-up with two functions, one for row access and one for column access. That is what I wanted to parameterize on.
Ideally, I'd have either of
(defun get-grid-string (grid position direction) ( ...
with usage:
(get-grid-string #2A((#\a #\b #\c) (#\d #\e #\f) (#\g #\h #\i)) 1 :by-column)
"beh"
if it turns out that providing the direction (rows vs cols) explicitely is required,
or
(defun get-grid-straing (grid position) ( ...
if the direction can be "coded into" the position itself.
with usage:
(get-grid-string #2A((#\a #\b #\c) (#\d #\e #\f) (#\g #\h #\i))
(make-position 2 :by-row)) "ghi"
My point is that I've already got non trivial (working) code to handle the "rows" case, and I'd rather amend it to deal with both directions than copy-paste-patch a second instance of every single row related function into a nearly indentical column related function.
Many Thanks. -- JFB
.
- References:
- Trade-off, option, choice.
- From: verec
- Re: Trade-off, option, choice.
- From: Carl Taylor
- Trade-off, option, choice.
- Prev by Date: Re: Trade-off, option, choice.
- Next by Date: newbie question
- Previous by thread: Re: Trade-off, option, choice.
- Next by thread: newbie question
- Index(es):
Relevant Pages
|