Subject: Re: Question : QUOTE/external representation semantic ?
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 13 Jun 2001 10:11:50 GMT
Newsgroups: comp.lang.scheme
Message-ID: <9g7e96$g8v9p$1@fido.engr.sgi.com>
Olivier Duval <olivier.duval@selftrade.com> wrote:
+---------------
| I'm writing a kind of Scheme interpreter in C++ and I got a problem on
| quote semantic : are quoted terms always eval'd as quoted or just once ?
+---------------

If I understand what you're asking, "just once". Unless you explicitly
call "eval", *everything* in a Scheme expression is evaluated "just once",
if it is evaluated at all [and some parts of special forms aren't evaluated
at all, per se].

+---------------
| More clearly, if I write
|    ((if #t (quote set!)) (quote u) 1)
| what will happen ?
+---------------

Typically, something like this:

	> ((if #t (quote set!)) (quote u) 1)
	Error in procedure application: expected a
	procedure, but was given: set! [a symbol];
	other arguments were: u [a symbol] and 1 [a number]
	>

+---------------
| 1) First, the terms of the funcall are eval'd and I obtain (set! u 1),
+---------------

That's correct, BUT... what you end up with is not a valid procedure call,
since the first form did not evaluate to a procedure object. [It evaluated
to a symbol object.]

+---------------
| I apply "set!" and I got u=1 in the environment
+---------------

No. You may *try* to apply a symbol ("set!"), but symbols are not procedures,
and so the application fails.

Besides, the "set!" form is not a procedure call -- it's a special
[primitive syntax] form. You can't "compute" a special form (without
explicitly using "eval").

+---------------
| 2) It's the same process except that I obtain "set!" and "u" as data (and
| not as identifier), so I got an error because datas are not related to
| identifier.
+---------------

Almost:  Where you said "data" read "symbol" [or "identifier used as a
symbol"], and where you said "identifier" read "evaluated identifier"
[or "evaluated variable" or "identifier used as a variable, and then
evaluated"].

+---------------
| I guess that 1) is the correct answer but in that case, I should have the
| same result with ((quote set!) (quote u) 1)
+---------------

No, because this is once again asking the evaluator to use a symbol
("set"!) as a procedure, which doesn't work. It's just as bad as writing
this:

	> (1 2 3)
	Error in procedure application: expected a
	procedure, but was given: 1 [a number];
	other arguments were: 2 [number] and 2 [number]
	>

You probably want simply:  (set! u 1)

+---------------
| Another problem arise with assignment.
| In the following code, what is the value of "my-second-set" ?
| 
| (define my-set (quote set!))
| (define my-second-set my-set)
+---------------

The symbol "set!".

+---------------
| In both, I got my-set=set!, but in the first case, the eval of my-set is an
| identifier...
+---------------

No. In the first "define" form, the "my-set" identifier is *NOT* evaluated,
only assigned to. In the second "define", "my-second-set" isn't evaluated,
but "my-set" (in the value position) is (yielding the value previously stored
into it, namely, the symbol "set!").

+---------------
| so the evaluation of my-set results in the evaluation of set!
+---------------

No, the symbol "set!" is never evaluated in any of the above.

+---------------
| ... and an error (I guess)
+---------------

No, both forms are legal, and the result is that afterwards both
"my-set" and "my-second-set" contain the symbol "set!".

	> (define my-set (quote set!))
	> (define my-second-set my-set)
	> (list my-set my-second-set)
	(set! set!)
	> 

+---------------
| and in the second case, it's only data, so my-second-set has the same
| value as my-set.
+---------------

In *both* cases it's "only data" (the symbol "set!").

+---------------
| And, just to finish, R5RS talks quickly about "external representation".
| Is it another type (like numbers, strings and so) or something else...
+---------------

I think you trying to make it more complicated than it is. An "external
representation" just *how* your represent numbers, strings and so on
externally, that is, outside the Scheme system's internal memory. It's
what you type to an active "read" to get stuff *into* the machine, and
it's what the machine outputs as a result of a "display" or "write".
For example, one possible external representation of the number 123 is
the sequence of three characters "1", "2", and "3" -- that is, "123".
Another external representation of the same number is the seven-character
sequence "#e123.0".


-Rob

-----
Rob Warnock, 31-2-510		<rpw3@sgi.com>
SGI Network Engineering		<http://reality.sgi.com/rpw3/> [until 8/15]
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA

[Note: aaanalyst@sgi.com and zedwatch@sgi.com aren't for humans ]