Re: Symbols, metacircular evaluation, external representation.



Rudy wrote:
Hi,

I'm new to Scheme (please, forgive my shortcomings ;-)) and I don't grasp
some issues connected with it.

Firstable, what's the point in symbols? Are they only to make Lisp
homoiconic? I think that without them any expression (e.g. (lambda (x) (* x
2))) wouldn't be a proper Lisp's list structure because nobody would know
what do these lambda, x, and * mean. Am I right? I also wonder why aren't
they treated as strings instead of a separate data type? Strings and
symbols are quite similar, aren't they?

There are several important differences. Yes, as you
note, symbols allow homoiconicity in that they provide
a way to read code containing variable references as
data. It wasn't the only way to do that, so it wasn't
*strictly* necessary for homoiconicity, but it does
make the isomorphism between code-as-code and code-as-data
very simple conceptually.

In code, Strings evaluate to themselves and Symbols
evaluate as variable references.

An equality comparison between identical symbols
is guaranteed to take O(1) time, while an equality
comparison between identical strings (under most
implementations) takes O(n) time in length of the
smaller string.

Strings and symbols are superficially similar. Some
early LISPs lacked a string datatype and used symbols
to do string operations. Separating them did produce
clearer code.


Let's go further. What is so great about homoiconic languages? They are
amenable to metacircular evaluation but what is so super about this thing?
I would like to hear some practical arguments.

Homoiconic languages allow macro systems that operate
on code as data. That means you don't have to learn
a separate or more limited language to do your macros,
and your macros can work on program structure rather
than surface syntax or machine-code. This allows you
to extend the language easily, and avoids a lot of the
"gotchas" that operate when macrology is used on a
complicated surface syntax.

The last issue I'm grappling with is external representation of objects.
What's the point in it? It is very often used in this way:

'(1 2 3) instead of (list 1 2 3) or
'#(1 2 3 4 5 "foo" foo) instead of (vector 1 2 3 4 5 "foo" 'foo)

I doubt that's all the application of external representations.

External representation of objects firstly operates
as as a "free" serialization mechanism. This means
that you can store data structures and later read
them back easily, in a regular and reasonably human-
readable way, as S-expressions. It's better and
simpler, anyway, than XML and equivalents. This also
means that mobile code and separate processes have a
simple way to communicate complex datastructures to
one another.

External representations operate secondly as a means
of storing code so that it can be read and operated
on by humans or other programs (as in debugging
libraries). It makes it very easy to write or extend
a debugger.

I've been also thinking what's the purpouse of quoting (except for the
above-mentioned trivial usage and "obtaining symbols"). Examples like
symbolic differentiation from SICP don't appeal to me, beacuse such tasks
could be done by strings as well. Could you enlighten me?

Quoting is a support mechanism. In a homoiconic
language your reader can be reading code or reading
external representations of data at any time.
Quoting (and Unquoting) allows you to switch its
mode when you want to. This is simply a utility
that supports controlling and exploiting the
distinction between external representations of
data and external representations of code.

It seems to me that all these problems are somehow related but I cannot put
them together. S.O.S!

All of these things are related. When you put them
together you get the difference between the lisp family
of languages and other programming languages. Each of
these things works together with the others and makes
each of the others more powerful and flexible. As such,
they are not "problems." They are the main reasons why
anybody would put up with and learn to love the lispy-
language surface syntax, because they are what make it
so very expressive.

Perhaps if enlightenment is chasing you, you should slow
down long enough to read http://www.paulgraham.com/diff.html
and see if that lets it catch up.

Bear




.



Relevant Pages

  • Re: add support for other languages
    ... language DLLs or a single DLL with multiple language support, ... Just compile in Unicode ... You can create a hand-edited resource that contains Unicode strings, but you have to do it ... I don't know where is the language support comes into ...
    (microsoft.public.vc.mfc)
  • Re: Two Questions about "strlen", "strcat" and "strcpy"
    ... >>Important is that we have in the standard language a way of using ... > No. zero terminated strings is the whole problem in the first place. ... > programmer to think in terms of implementation and constantly respin ... The standards comitee refuses any change, ...
    (comp.lang.c)
  • Re: GNU gettext
    ... The gettext documentation explains how the keys work. ... translation files, or that you'd need to write a small utility to help ... gettext was desined for plain C, the keys are C strings ... as a developer you have no clue what every language ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How come Ada isnt more popular?
    ... A language with a Hinldey-Milner type system ... fixed size strings, unbounded strings, suffix tree. ... container varies, the element does not. ...
    (comp.lang.ada)
  • Re: Substituting the main menu bar(s)
    ... I have tab-separated-value table of strings maintained with Excel, with a column for each language. ... All it does is replace the strings according to the translation table. ... I also have a batch file which calls the translation app, and then invokes the compiler on each resource-only DLL project. ...
    (microsoft.public.vc.mfc)