From: Luke J Crook
Subject: Iterate through two lists, performing an operation on each element
Date: 
Message-ID: <BIbJb.38861$Vs3.6280@twister.socal.rr.com>
I'm still very much in the C/Java mindset, so I would appreciate some 
feedback as to the Lispy'ness of the function blit-3. It's function is 
to iterate over two lists and performs an operation on each element.

(setf mask '(
         (255 255 255 255 255 255 255 255)
         (255 0   0   0   0   0   0   255)
         (255 0   255 255 255 255 0   255)
         (255 0   0   0   0   0   0   255)
         (255 0   255 255 255 255 0   255)
         (255 0   0   0   0   0   0   255)
         (255 255 255 0   0   255 255 255)
         (0   0   0   0   0   0   0   0)))

(setf background '(
         (0 5 6 3 5 7 8 0)
         (1 1 9 6 4 5 4 1)
         (3 9 8 6 7 6 6 0)
         (4 0 9 8 7 5 6 7)
         (5 1 5 6 3 5 6 6)
         (7 1 2 3 4 5 6 7)
         (8 8 5 3 4 8 2 7)
         (9 8 7 6 5 4 3 2)))

(defun blit-3 (op x y)
     (mapcar
         (lambda (row-1 row-2)
             (mapcar op row-1 row-2))
         x y))

(blit-3 #'logand background mask)

From: Christopher C. Stacy
Subject: Re: Iterate through two lists, performing an operation on each element
Date: 
Message-ID: <uznd6ab07.fsf@news.dtpq.com>
Have you considered using arrays instead of lists?
From: Christophe Rhodes
Subject: Re: Iterate through two lists, performing an operation on each element
Date: 
Message-ID: <sqisjuy5x0.fsf@lambda.jcn.srcf.net>
Luke J Crook <······@NO-SPAM.hd-plus.com> writes:

> I'm still very much in the C/Java mindset, so I would appreciate some
> feedback as to the Lispy'ness of the function blit-3. It's function is
> to iterate over two lists and performs an operation on each element.

It looks like the Lisp of someone who thinks that the list is the only
datastructure available, I'm afraid...  (and who's learnt from a bad
textbook; your setfs at toplevel invoke undefined behaviour).

(defvar mask 
  #2a((255 255 255 255 255 255 255 255)
      (255 0   0   0   0   0   0   255)
      (255 0   255 255 255 255 0   255)
      (255 0   0   0   0   0   0   255)
      (255 0   255 255 255 255 0   255)
      (255 0   0   0   0   0   0   255)
      (255 255 255 0   0   255 255 255)
      (0   0   0   0   0   0   0   0)))

(defvar background 
  #2a((0 5 6 3 5 7 8 0)
      (1 1 9 6 4 5 4 1)
      (3 9 8 6 7 6 6 0)
      (4 0 9 8 7 5 6 7)
      (5 1 5 6 3 5 6 6)
      (7 1 2 3 4 5 6 7)
      (8 8 5 3 4 8 2 7)
      (9 8 7 6 5 4 3 2)))       

(defun blit-3 (op x y)
  (let ((result (make-array '(8 8))))
    (dotimes (i 64)
      (setf (row-major-aref result i)
            (funcall op (row-major-aref x i) (row-major-aref y i))))
    result))

(blit-3 #'logand background mask)

As it stands, there won't be much difference between your version and
mine (except that I suspect, given the function names, that arrays
will prove a more fruitful datastructure than lists); however, should
you discover the need for better execution time, I think it's likely
that my version can have suitable declarations and alterations
(e.g. to use specialized arrays) made, whereas the list implementation
is a little bit of a dead end.  On the other hand, it's a perfectly
good implementation for a rapid prototype; the advice to give depends
mostly on the expected scope of your code.

Christophe
-- 
http://www-jcsu.jesus.cam.ac.uk/~csr21/       +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%")    (pprint #36rJesusCollegeCambridge)
From: Luke J Crook
Subject: Re: Iterate through two lists, performing an operation on each element
Date: 
Message-ID: <spEJb.39005$Vs3.8192@twister.socal.rr.com>
Christophe Rhodes wrote:
> Luke J Crook <······@NO-SPAM.hd-plus.com> writes:
> 
> It looks like the Lisp of someone who thinks that the list is the only
> datastructure available, I'm afraid...  (and who's learnt from a bad
> textbook; 

Don't blame the textbook :)

> your setfs at toplevel invoke undefined behaviour).

By undefined do you mean: undefined across different implementations of 
Lisp, or undefined within the same implementation ?

> should
> you discover the need for better execution time, I think it's likely
> that my version can have suitable declarations and alterations
> (e.g. to use specialized arrays) made, whereas the list implementation
> is a little bit of a dead end.  

I agree. This is mostly a prototype to get my ducks in a row. In the 
'production' version I will be using arrays in C structs and calling OS 
functions for hardware blitting.

Thanks,
-Luke
From: Christophe Rhodes
Subject: Re: Iterate through two lists, performing an operation on each element
Date: 
Message-ID: <sqy8sox2q0.fsf@lambda.jcn.srcf.net>
Luke J Crook <······@NO-SPAM.hd-plus.com> writes:

> Christophe Rhodes wrote:
>> your setfs at toplevel invoke undefined behaviour).
>
> By undefined do you mean: undefined across different implementations
> of Lisp, or undefined within the same implementation ?

I mean undefined by the standard.  Implementations would be justified
in formatting your hard drive and mailing nasty e-mail to your
addressbook, though most likely they'll just silently create the
variable; there are, however, differences in how that variable can be
created that can cause problems for the poor developer down the line.

Christophe
-- 
http://www-jcsu.jesus.cam.ac.uk/~csr21/       +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%")    (pprint #36rJesusCollegeCambridge)