This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
procedure-name-symbol to procedure
- From: Chuah Teong Leong <teongleong at gmail dot com>
- To: kawa at sourceware dot org
- Date: Sat, 2 Mar 2013 19:18:28 +0800
- Subject: procedure-name-symbol to procedure
Hi, is it possible to construct a symbol and retrieve the procedure
from the interactive environment associated the symbol name?
I have the following code
;; (if (w-key-event? e)
;; (begin
;; (set! last-key 'w)
;; (register-key-down 'w)
;; ))
;; (if (a-key-event? e)
;; (begin
;; (set! last-key 'a)
;; (register-key-down 'a)
;; ))
;; (if (s-key-event? e)
;; (begin
;; (set! last-key 's)
;; (register-key-down 's)
;; ))
;; (if (d-key-event? e)
;; (begin
;; (set! last-key 'd)
;; (register-key-down 'd)
;; ))
and I'm probably going to do the same for every key I care about.
I however would like to do shorten the code to look like this
(vector-map
(lambda (key-sym)
(define proc-sym
(string->symbol
(string-append (symbol->string key-sym) "-key-event?")))
(if (eval (list proc-sym 'e))
(begin
(set! last-key 'key-sym)
(register-key-down 'key-sym)
))
) supported-keys))
(define supported-keys (vector 'w 'a 's 'd ))
This did not work because it couldn't find w-key-down? and the other procedures.