1995-10-13 23:34:21 -04:00
|
|
|
;;; Copyright (c) 1994 by Olin Shivers.
|
|
|
|
|
|
|
|
;;; Handy for defining random flags and constants.
|
|
|
|
;;; (define-enum-constant "errno" intr 9) => (define errno/intr 9)
|
|
|
|
;;; Ugly, but it works.
|
|
|
|
|
|
|
|
;;; The question: is / the best separator? Alternates: $ . |
|
|
|
|
|
|
|
|
|
1996-09-11 23:33:32 -04:00
|
|
|
;;; (define-enum-constant fruit apple 1) =>
|
|
|
|
;;; (define fruit/apple 1)
|
|
|
|
|
1995-10-13 23:34:21 -04:00
|
|
|
(define-syntax define-enum-constant
|
|
|
|
(lambda (form rename compare)
|
|
|
|
(let ((%define (rename 'define))
|
1996-09-11 23:33:32 -04:00
|
|
|
(var (string->symbol (string-append (symbol->string (cadr form)) "/"
|
1995-10-13 23:34:21 -04:00
|
|
|
(symbol->string (caddr form)))))
|
|
|
|
(value (cadddr form)))
|
|
|
|
`(,%define ,var ,value))))
|
1996-09-11 23:33:32 -04:00
|
|
|
|
|
|
|
;;; (define-enum-constants fruit (apple 1) (orange 2))
|
|
|
|
;;; => (begin (define-enum-constant fruit apple 1)
|
|
|
|
;;; (define-enum-constant fruit orange 2))
|
|
|
|
|
|
|
|
(define-syntax define-enum-constants
|
|
|
|
(syntax-rules ()
|
|
|
|
((define-enum-constants set (elt val) ...)
|
|
|
|
(begin (define-enum-constant set elt val) ...))))
|