Re: Trade-off, option, choice.



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

.



Relevant Pages

  • Re: Trade-off, option, choice.
    ... either on a row by row basis, or on a column by column ... (declare (type fixnum row)) ... :element-type (array-element-type x-grid) ...
    (comp.lang.lisp)
  • Re: From the Beautiful Code Book, Chapter 1, A Regular Expression Matcher
    ... One thing that could be further optimized, I guess, is to avoid any closures around the code (the closure is over the regexp, text arguments, and regexp-length, text-length variables). ... (declare (type fixnum text-length regexp-length)) ... (labels ((match-star (ro to) ...
    (comp.lang.lisp)
  • fast io of numbers in ascii
    ... format. ... (declare (type fixnum m)) ... ; Compiling LAMBDA ...
    (comp.lang.lisp)
  • Re: Trade-off, option, choice.
    ... Hi Verec, ... >> (declare (type fixnum row)) ... | orientation ORIENTATION, ...
    (comp.lang.lisp)
  • Optimizing sort-algorithm
    ... i'm trying to optimize execution time of bubblesort. ... slower than the c-version. ... (declare (type fixnum tmp)) ...
    (comp.lang.lisp)