Figuring out enums and structs with foreigners
Diogo via Chicken-users <[email protected]>
| Newsgroups | gmane.lisp.scheme.chicken |
|---|---|
| Message-ID | <[email protected]> |
Dear mailing list,
I have a beginners question. Using `foreigners` one can easily define
structs and enums. But how does one figure out whether a symbol is an
enum or a struct?
Here is a small example of what I am trying to do:
```
(import (chicken base)
(chicken foreign)
foreigners)
;; define "enum event" and "struct plan"
#>
#define EV_X 111
#define EV_Y 222
<#
(define-foreign-enum-type
(event unsigned-integer32)
(event->int int->event)
((evx event/x) EV_X)
((evy event/y) EV_Y))
(define-foreign-record-type
plan
(integer nxt plan-nxt)
(c-string msg plan-msg))
;; assume this function comes from a library, it doesn't know about event
;; or plan:
(define (print-type-info type)
(cond ((??) (printf "~a is enum~n" type))
((??) (printf "~a is struct~n" type))
(else (printf "~a is something else~n" type))))
;; And I'd hope to use it like this
(print-type-info 'plan)
(print-type-info 'event)
;; Or like this if print-type-info would need to be defined with syntax-rules.
(print-type-info plan)
(print-type-info event)
```
Any suggestions?
Thanks in advance.
Best,
-Diogo