It's possible with quoted arguments:
(define (symtab s)
(cons s (eval s (interaction-environment))))
Now lets test it:
(define xy 12)
(symtab 'xy)
=> (xy . 12)
EDIT: However it's not very reliable (using macro too) - please read closely related Why isn't there an unquote
Lisp primitive?
It's because Scheme like most languages is lexically scoped. It means that variable names are resolved when function is defined, as opposed to dynamic scope when variable names are resolved at run-time. So
(define xy 12)
(define (getXY) xy)
(getXY)
=> 12
This code works, because when we define getXY
, name xy
is known and can be resolved to top-level xy
. However
(define (getXY) xy)
(let ((xy 21))
(getXY))
=> Unbound variable: xy
This doesn't work, because when getXY
was defined, xy
was not known (and my Guile Scheme also gave me warning when defining getXY
"warning: possibly unbound variable `xy'").
It will work in Emacs Lisp - dynamically scoped.