RG <
rNOS...@flownet.com> writes:
> In article <
a1454336-49ee-49e2...@googlegroups.com>,
> Rickert <
solidi...@gmail.com> wrote:
>
>> Lisp syntax represents AST as far as I know, but in high level format to
>> allow human to easily read and modify, at the same time make it easy for the
>> machine to process the source code as well.
>
> No. Lisp syntax is (merely) a *serialization* format, like JSON. It is
> neither "high level" nor "low level". Those concepts do not really
> apply to serialization formats.
What difference do you make between "X represents Y" and "X is a
serialization format for Y"?
Otherwise, indeed, the terminology for syntax trees is not "high level"
or "low level", but "abstract" and "concrete". Abstract Syntax Tree is
the purified tree, which is what we usually have with lisp forms, while
the Concrete Syntax Tree has leaves to represent spurious characters.
if condexpr then thenexpr else elseexpr fi -- concrete syntax
| | | | | | |
\ expr | expr | expr /
\ | | | | | / -- CST
-----------------------------------
ifexpr
(if condexpr thenexpr elsexpr) -- abstract syntax
which represents the tree:
condexpr thenexpr elseexpr
\ | /
\ | /
--------------- -- AST
if
>> For this reason, in Lisp, it is said that code is data and data is code,
>> since code (s-epxression) is just AST, in essence.
>
> Again no. In Lisp, the semantics of the language are defined directly
> on the underlying data structures themselves, not on the serialization
> as in other programming languages.
>
> All languages have a syntax which is a serialization of an underlying
> data structure. The difference is that in Lisp the underlying data
> structure is directly and intentionally accessible to the user whereas
> in other languages the underlying data structure is hidden and
> accessible only to the compiler.
The important word here is "directly". For S-expression, there's a
simple and direct isomorphism between the textual representation and the
data structure represented. No other language has this direct
isomorphism. (Not even the CL:LOOP language, which is why it's so much
critisized, and of course, this includes the more sophisticated reader
macros that implement other concrete syntaxes).
This is because of this isomorphism that we are entitled to (and can
easily in general) ignore the difference between the textual
representation and the data structure of S-expressions, and just talk
about S-expressions.
If I say that I have a list (a b c), it is obvious to all that I don't
have a sequence of characters "(a b c)", but a chain of cons cells
referencing symbols!
>> I heard that the Lisp machine only has a single address space which holds all
>> data. In operating system like Linux, the programmers only have virtual
>> address space and pretend it to be the real physical address space and can do
>> whatever they want. Data and code in Linux are separated regions, because
>> effectively, data is data and data is code. In normal OS written in C (or C
>> like language), it would be very messy if we only operate a single address
>> space for the whole system(physical memory) and mixing data with code would
>> be very messy.
>
> Again no. Lisp is no different from C in this regard. Data structures
> are just much easier to implement if the underlying representations
> share an address space. It is possible in any language to implement
> data structures that span multiple address spaces, but it's not easy and
> very rarely done.
That wasn't the point.
But indeed, it's not strictly speaking relative to the language.
AFAIK, in lisp machines, there were lisp primitives that allowed to
compute random locations in memory. And on the other hand, AFAIK, there
is nothing in the C standard that allows you to compute random locations
in memory.
That is, at the language standard level, the memory is as protected in
ANSI C as it is in ANSI Common Lisp.
But at the implementation level, there are ways to obtain pointers to
random locations in memory from a random integer.
Now if you use an implementation that is more restrictive in this
respect, (eg. in C an implementation could signal an error everytime you
cast an integer to a pointer that is not an integer that was obtained
from casting a pointer (of the same type) to that integer, which is all
that the ANSI C language allows IIRC), then you can indeed have complex
systems running in the same address space without encountering often the
problem you get when you don't have this control.
Or, said otherwise, the protection that is provided by the hardware
(MMU) and the OS can also be provided by a bug-free compiler, with the
restriction that all programs running be compiled with that compiler,
and that no uncontrolled memory accesses be allowed (at least in user
code).
--
__Pascal Bourguignon__
http://www.informatimago.com/
A bad day in () is better than a good day in {}.