[cffi-devel] defenum proposal

Frank Buss fb at frank-buss.de
Sun Jan 22 14:47:47 UTC 2006


When translating anonymous enums to Lisp, it might be easier to use
something like the defcenum:

(defmacro defenum (&body enums)
  `(progn ,@(loop for value in enums
                  for index = 0 then (1+ index)
                  when (listp value) do (setf index (second value)
                                              value (first value))
                  collect `(defconstant ,value ,index))))

This will be expanded to a block of defconstants:

(defenum
  a
  (b 10)
  c)

->

(PROGN
  (DEFCONSTANT A 0)
  (DEFCONSTANT B 10)
  (DEFCONSTANT C 11))

It is not necessary to use keywords like for the named enums, because
unnamed enums in C are just syntatic sugar for a list of "#define"s, which
is mapped to a list of defconstants. I don't know, if this macro fits in the
philosophy of CFFI, perhaps in some utility class, and maybe with another
name "defanonenum".

-- 
Frank Buss, fb at frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de




More information about the cffi-devel mailing list