Friday, May 15, 2009

Back quotes embeded: The basic

Q: Explain the results:

A: 
1. `(,'foo)  -> (FOO)
when evaluate a symbol 'foo, since there's no need to bind a variable, ,'foo will be FOO.

2. `(`(,'foo)) -> ('(FOO))
though embedded in the double backup quotes, it doesn't metter: 'foo is a symbol not a variable - it doesn't bothered to the binding thing.  

3. (let ((x 'foo)) `(`(,x))) -> (`(,x)) with a warning saying that x is never used
when the ,x is met in the 2nd level of data mode, that x doesn't need to be evaluated: it's a literal value, well formed, ready for the 2nd expanding.

4. (let ((x 'foo)) `(`(,',x))) -> ('(FOO))
when ,',x is met in the 2nd level of data mode, the ',x need to be resolved as a symbol (for that '). ,x will be evaluated at the 1st level where there's a binding (x 'foo).

So ,',x will be ,'FOO, then FOO. (see A 1.)

5. (let ((x 'foo)) `(`(,,x))) -> (`(,FOO))
when ,,x is met in the 2nd level embedding of data mode, the ,x after , will be evaluated - on the 1st level. ,x -> FOO, thus ,,x -> ,FOO.



Q: So the embedding affects the expanding?

A: Sure.

`(`(,',x))) => `(         ) ; 1st level, (x 'foo);        ,x evaluated here                
                 `(,',x))   ; 2nd level, () no binding; ,',x evaluated here


Q: one more level?

A: yeah:




The explanation is quite the same with previous one. But we can try a different approach:

It's the same with the above one. But with the lexical vairable factored out to show the levels.



Q: Why do we need that extra quote ' in the nested let?

A: Because we can't assign FOO directly to a variable. It need to be a symbol.

No comments: