I'm quite new to scheme and I'm not so sure of something about quote and symbols.
Here is what I understand:
'a
-> a
'()
->(list)
'(1 2 3)
(list 1 2 3)
'(1 . 2)
(cons 1 2)
''a
(quote a)
So:
'(1 . 'a)
(1 quote a) => (list 1 quote a)
What I'd like to achieve is the following.
((let ((x 1) (y 2))
(lambda(f) ,f)) 'x)
-> 1
I send a symbol to the function and the symbol should be evaluated to the current scope which in this case would return 1.
Instead, I have this error:
*** ERROR IN #<procedure #4>, (console)@243.32 -- Unbound variable: unquote
It's as if unquote was only available from within quote
itself.
EDIT
I was just reading some docs and found the function: "eval" which seems to do what I was looking for.
(define a 'foobar)
(define foobar 2)
(eval a)
-> 2
(define a 'x)
(define f (let ((x 1) (y 2))
(lambda (h) (eval h))))
(f a)
*** ERROR -- Unbound variable: y
(f y)
*** ERROR IN (console)@278.4 -- Unbound variable: y
But I'm not sure to really understand.
Here is a stacktrace in chicken
Error: unbound variable: x
Call history:
<syntax> (f (quote x))
<syntax> (quote x)
<syntax> (##core#quote x)
<eval> (f (quote x))
<eval> (eval h) <--
Edit2
Eval is Evil but I guess it's quite important to know how it works.
So after reading the answer of Ankur, I was pretty sure that it was a problem of scope and it is in fact it. So from what I understand, It appears that eval
may be trying to evaluate anything using "globals".
> (define a 11)
> (define b 'a)
> (eval b)
11
> (let ((a 10)) (eval b))
11
> (let* ((a 10) (b 'a)) (eval b))
11
> (let* ((a 10) (b 'a)) b)
a
> (let* ((c 10) (d 'c)) d)
c
> (let* ((c 10) (d 'c)) (eval d))
*** ERROR -- Unbound variable: c
Eval in scheme is clearly evil!