Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Scheme > Quote and unquo...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 4547 of 4716
Post > Topic >>

Quote and unquote question.

by ejhewy@[EMAIL PROTECTED] Jun 11, 2008 at 09:17 AM

My reason for using Scheme is to understand how it sup****ts meta level
code=97Code generating code.  I=92m investigating both how one writes meta
code, as well as how it is evaluated once written.

This, of course, leads to these Scheme topics:

  Quoting/Quasiquoting and Unquoting
  Eval

My question relates to the need for both Unquote and Eval.  Why are
both necessary?

I imagine a system that allows any code to be quoted to any meta
level.  In the middle of this code, one could unquote back down (all
the way to concrete, if desired).  When unquote is run on code, it
would strip off one of the meta levels (effectively moving all of the
code down one meta level).  Anything that is then at level 0 gets
evaluated.  Anything higher remains unevaluated.

Basically, this is a combination of unquote and eval.  For example, in
the following I define d to be a triply quasiquoted expression.  After
evaluation, the first quasiquote is removed, leaving 2, along with the
singly unquoted a and doubly unquoted b references.  I then define a
and b, and eval d, dropping it one meta level.  This evaluates the b
reference, but not the a reference.  One more time evaluates both.

(define d ```(,a ,,b))
	; d is now : (quasiquote (quasiquote ((unquote a) (unquote (unquote
b)))))
(define a 0)
(define b 0)
(define d (eval d))   ; Why not (unquote d) here, instead of (eval d)?
	; d is now (quasiquote ((unquote a) (unquote 0)))
(define a 1)
(define b 1)
(define d (eval d))   ; And here?
   ; d is now (1 0)

Why can=92t unquote be used in place of the (eval d) expressions above?
If I attempt this, it complains about an unbound variable: unquote.

My specific questions:
1. I understand that unquote, the way it is defined, only makes sense
within quasiquote.  However, I don=92t understand why it was defined
this way.  I don=92t see any problems with the concept of =91unquoting=92
a
chunk of Scheme code.  It seems like the logical opposite of quoting.
2. So, why isn=92t unquote the opposite of quote.  If quoting a scheme
expression causes it to not be evaluated, shouldn=92t unquoting a quote
cause it to be evaluated?  I would expect the following code, for
example, to evaluate to 5.  It does not, and instead gives the unbound
variable: unquote error.
  (define (a) 5)
  (define b '(a))
  (unquote b)
If I replace the unquote with eval, it returns 5.

Thanks in advance for your help!

Eric
 




 3 Posts in Topic:
Quote and unquote question.
ejhewy@[EMAIL PROTECTED]   2008-06-11 09:17:18 
Re: Quote and unquote question.
Jens Axel Soegaard <fi  2008-06-11 20:23:49 
Re: Quote and unquote question.
ejhewy@[EMAIL PROTECTED]   2008-06-12 17:43:50 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 15:36:30 CDT 2008.