2001-03-10 22:47:00 -05:00
|
|
|
;;; Copyright (c) 1994 by Olin Shivers. See file COPYING.
|
1995-10-13 23:34:21 -04:00
|
|
|
|
|
|
|
;;; Handy for defining random flags and constants.
|
|
|
|
;;; (define-enum-constant "errno" intr 9) => (define errno/intr 9)
|
2001-03-10 22:47:00 -05:00
|
|
|
|
|
|
|
;;; This is deeply bogus code. It merely serves to demonstrate what a loser
|
|
|
|
;;; I am when it comes to serious modern-tech macrology.
|
1995-10-13 23:34:21 -04:00
|
|
|
|
|
|
|
;;; The question: is / the best separator? Alternates: $ . |
|
|
|
|
|
|
|
|
|
2001-03-10 22:47:00 -05: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)
|
2001-03-10 22:47:00 -05:00
|
|
|
(let* ((%define (rename 'define))
|
|
|
|
(base (let ((b (cadr form)))
|
|
|
|
(cond ((string? b) b)
|
|
|
|
((symbol? b) (symbol->string b))
|
|
|
|
(else (error "Enum constant base must be symbol or string"
|
|
|
|
b )))))
|
|
|
|
(var (string->symbol (string-append base "/"
|
1995-10-13 23:34:21 -04:00
|
|
|
(symbol->string (caddr form)))))
|
|
|
|
(value (cadddr form)))
|
|
|
|
`(,%define ,var ,value))))
|
2001-03-10 22:47:00 -05: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) ...))))
|