Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

TGA loader in LISP

Name: Anonymous 2010-12-26 3:20

`class` macro automatically generates everything

class Tga
  idLength   = U1  // 00h Size of Image ID field
  cmapType   = U1  // 01h Color map type
  imageType  = U1  // 02h Image type code
  cmapStart  = U2  // 03h Color map origin
  cmapLength = U2  // 05h Color map length
  cmapDepth  = U1  // 07h Depth of color map entries
  xOffset    = U2  // 08h X origin of image
  yOffset    = U2  // 0Ah Y origin of image
  width      = U2  // 0Ch Width of image
  height     = U2  // 0Eh Heigth of image
  bpp        = U1  // 10h Image pixel size
  descriptor = U1  // 11h Image descriptor byte
  idField    = idLength++U1
  cmap       = cmapLength++U1
  bmap       = (width*height*bpp%8)++U1

Name: Anonymous 2010-12-26 17:10

>>22
Fixed that, now (letn (x 2 y 2) b ...) is the same as (let ((x 2) (y 2)) b ...):

(define-syntax (letn stx)
  (syntax-case stx ()
    ((_ ((x y) ...) b ...)
     #'(let ((x y) ...) b ...))
    ((_ (x ...) b ...)
     #`(let #,(let loop ((xs #'(x ...))
                         (r '()))
                (if (stx-null? xs) (reverse r)
                    (let ((x (stx-car xs)))
                      (cond ((and (stx-pair? x)
                                  (stx-null? (stx-cdr x))) (loop (stx-cdr xs)
                                                                 (cons (list (stx-car x) ''()) r)))
                            ((stx-pair? x) (loop (stx-cdr xs)
                                                 (cons x r)))
                            ((not (or (stx-null? (stx-cdr xs))
                                      (identifier? (stx-cadr xs)))) (loop (stx-cddr xs)
                                                                          (cons (list x (stx-cadr xs)) r)))
                            (else (loop (stx-cdr xs)
                                        (cons (list x ''()) r)))))))
         b ...))
    ((_ x b ...)
     #'(let ((x '())) b ...))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List