;;; Goal: Use a C switch statement to perform a fast lookup of an ;;; integer constant and return a symbol. (In the real code there are ;;; about 300 integer constants to lookup.) ;;; ;;; Are there any problems (e.g. memory leaks) with this approach? ;;; Is there a better way to do this? (import (chicken base) (chicken foreign) (chicken format)) #> enum { FOO, BUZZ, THIS_IS_AN_EXTREMELY_LONG_INTEGER_CONSTANT_NAME }; <# (define FOO (foreign-value FOO int)) (define BUZZ (foreign-value BUZZ int)) (define THIS_IS_AN_EXTREMELY_LONG_INTEGER_CONSTANT_NAME (foreign-value THIS_IS_AN_EXTREMELY_LONG_INTEGER_CONSTANT_NAME int)) (define ->symbol (foreign-primitive ((int x)) #< ~A [~A]~N" FOO (->symbol FOO) (eq? 'foo (->symbol FOO))) (printf "~A -> ~A [~A]~N" BUZZ (->symbol BUZZ) (eq? 'buzz (->symbol BUZZ))) (printf "~A -> ~A [~A]~N" THIS_IS_AN_EXTREMELY_LONG_INTEGER_CONSTANT_NAME (->symbol THIS_IS_AN_EXTREMELY_LONG_INTEGER_CONSTANT_NAME) (eq? 'this-is-an-extremely-long-symbol-name (->symbol THIS_IS_AN_EXTREMELY_LONG_INTEGER_CONSTANT_NAME)))