[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

making patterns the hard way



I tried to make a pattern using make-record, but it didn't work. Although
make-record macro-expanded into something reasonable, the resulting pattern
was not correct. Why?

(defvar *grid-x-pattern* (make-record :pattern
                                      (:array 0) 255
                                      (:array 1) 0
                                      (:array 2) 0
                                      (:array 3) 0
                                      (:array 4) 255
                                      (:array 5) 0
                                      (:array 6) 0
                                      (:array 7) 0
                                      ))

I ended up doing it this way:

;;; modified from examples:View-Example.lisp
(defun make-pattern (bytes)
  (let ((result (#_NewPtr 8))
        (i 0))
    (dolist (b bytes)
      (%put-byte result b i)
      (incf i))
    result))

(defvar *grid-x-pattern* (make-pattern '(255 0 0 0 255 0 0 0)))

This worked, but it required some digging around in the examples folder
to find the make-pattern function. Make-pattern calls some low-level functions,
so it's not very elegant. Is there a correct, documented, high-level way
to make patterns?