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 15:43

>>20
There's a cheap trick I sometimes use in CL for that when x is a toplevel variable binding: arguments passed to the function can be treated the same as a let form around the function body (at the same time, let can be seen as a lambda form to which you pass some arguments), however there's this difference between Scheme and CL in that argument lists to functions and lambda's, or ordinary lambda lists, to be more precise, allow you to pass other kinds of arguments such as optional arguments, rest arguments (variable number), keyword arguments and "auxiliary" arguments. All, but auxiliary arguments could technically be seen as passing any number of arguments and having a special way of parsing them (this part of CL is quite comfy when you write large programs as it allows for a lot of customization without the programmer needing to change code around, however it comes with added complexity which sometimes means you might have to involve lambda-list parsers in more advanced macros)... Anyway, I got a bit off-topic here, but the other kind of argument, "auxiliary ones" (marked by &aux) are nothing more than a way of introducing a local variable as if it were an argument, or basically adding extra variables without needing to add an extra let form. It also has some uses when it comes to places where you can't quite pass values, but can pass on argument lists (they are rare, but do exist, if you want an example, you could think of structure definition forms). Or to cut things short, if you had something like:
(defun f ()
  (let ((x '())) ...))

you could just write
(defun f (&aux x) ...) instead.
Or (defun f () (let (x) ...)) if you want to take advantage of the extra sugar that comes with CL's let and the fact that in CL NIL and [m]'()[/] are the same

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