From: Paul Rubin on
bolega <gnuist006(a)gmail.com> writes:
> I am trying to compare LISP/Scheme/Python for their expressiveness...
> Are there already answers anywhere ?
> How would a gury approach such a project ?

These two articles

http://page.mi.fu-berlin.de/~prechelt/Biblio/jccpprt_computer2000.pdf
http://www.haskell.org/papers/NSWC/jfp.ps

about language comparisons (Python is in the first but not the second)
might be of interest.

If you want to know how to implement C, there is a pretty good book by
Hanson and Fraser about LCC, called "A Retargetable C Compiler".
Basically a code walkthrough of a small C compiler written in C.
From: bolega on
On Jul 13, 11:18 pm, geremy condra <debat...(a)gmail.com> wrote:
> On Tue, Jul 13, 2010 at 11:01 PM, bolega <gnuist...(a)gmail.com> wrote:
> > On Jun 20, 9:31 pm, Richard Fateman <fate...(a)cs.berkeley.edu> wrote:
> >> Define Macro wrote:
> >> > On Jun 13, 7:07 pm, bolega <gnuist...(a)gmail.com> wrote:
> >> >> I am trying to compare LISP/Scheme/Python for their expressiveness.
>
> >> >> For this, I propose a vanilla C interpreter. I have seen a book which
> >> >> writes C interpreter in C.
>
> >> >> The criteria would be the small size and high readability of the code.
>
> >> >> Are there already answers anywhere ?
>
> >> Sure. Lots of texts on compilers provide exercises which, in one way or
> >> another suggest how to write an interpreter and perhaps a compiler too
> >> for some language. Anyone taking a course on compilers is likely to
> >> have followed such exercises in order to pass the course. Some
> >> instructors are enlightened enough to allow students to pick the
> >> implementation language.
>
> >> Ask any such instructor.
>
> > Beware, he does not tell the readers the financial details. This is
> > what he wrote to me by email.
>
> > <quote>
> > I would be willing to meet with you here in Berkeley to educate you on
> > these matters at a consulting rate of $850 per hour, with a minimum
> > of 8 hours.
>
> > RJF
> > </quote>
>
> He's Berkeley's former CS chair and was implementing lisp before
> common lisp was a twinkle in anybody's eye. His time is valuable.
>
> Geremy Condra

This makes some sense. He replied on the newsgroup in a lengthy post
that there are sufficient resources out there giving hint that no one
need help me out. Then I was called "lazy" in one email and tersely
given JUST the last name of an author who has many books each many
100s pages, when I asked for a relevant book, as if i am a scholar in
the field, although he did spend lots of words on irrelevant and
unbeneficial things which diminished my enthusiasm. Now, I find out
from you that he has/had a business concern or interest in a company
that is writing/wrote lisp interpreter in C. Correct me if I am making
an error. I dont want to think deprecatingly of any good soul but this
is what i experienced.

From: bolega on
On Jul 13, 11:35 pm, Paul Rubin <no.em...(a)nospam.invalid> wrote:
> bolega <gnuist...(a)gmail.com> writes:
> > I am trying to compare LISP/Scheme/Python for their expressiveness...
> > Are there already answers anywhere ?
> > How would a gury approach such a project ?
>
> These two articles
>
>    http://page.mi.fu-berlin.de/~prechelt/Biblio/jccpprt_computer2000.pdf
>    http://www.haskell.org/papers/NSWC/jfp.ps
>
> about language comparisons (Python is in the first but not the second)
> might be of interest.
>
> If you want to know how to implement C, there is a pretty good book by
> Hanson and Fraser about LCC, called "A Retargetable C Compiler".
> Basically a code walkthrough of a small C compiler written in C.

I have decided to limit my goal to tyni LISP interpreter in C because
its a smaller and simpler language.

From: Thomas A. Russ on

[Newsgroups trimmed]

bolega <gnuist006(a)gmail.com> writes:

> I have decided to limit my goal to tyni LISP interpreter in C because
> its a smaller and simpler language.

Even easier would be to write a tiny Lisp interpreter in Lisp. It will
still be instructive and will let you get going much faster. Or, if you
prefer, you could try your hand at writing a Scheme interpreter in Lisp
or Scheme. A great book for that is Abelson & Sussman's _Structure and
Interpretation of Computer Programs_.



--
Thomas A. Russ, USC/Information Sciences Institute
From: Pascal J. Bourguignon on
tar(a)sevak.isi.edu (Thomas A. Russ) writes:

> [Newsgroups trimmed]
>
> bolega <gnuist006(a)gmail.com> writes:
>
>> I have decided to limit my goal to tyni LISP interpreter in C because
>> its a smaller and simpler language.
>
> Even easier would be to write a tiny Lisp interpreter in Lisp. It will
> still be instructive and will let you get going much faster. Or, if you
> prefer, you could try your hand at writing a Scheme interpreter in Lisp
> or Scheme. A great book for that is Abelson & Sussman's _Structure and
> Interpretation of Computer Programs_.

And if you really want to have a C source, you can also write a tiny
Lisp to C translator.


;; do the proper package definitions and shadowing.

(defvar *c* *standard-output*)


(defun generate-c-variable (name initform)
`(progn
,(generate-expression initform)
(format *c* "object* ~A= result;~%" name)))

(defun generate-bindings (bindings parallelp)
(if parallelp
(cl:let ((temps (loop repeat (length bindings) collect (gensym))))
`(progn
,@(mapcar (lambda (var binding)
(generate-c-variable var
(if (atom binding) 'nil (second binding))))
temps bindings)
,@(mapcar (lambda (var binding)
(generate-c-variable
(if (atom binding) binding (first binding))
var))
temps bindings))
`(progn
,@(mapcar (lambda (binding)
(generate-c-variable
(if (atom binding) binding (first binding))
(if (atom binding) 'nil (second binding))))
bindings)))))

(defmacro let (bindings &body body)
`(progn
(format *c* "{~%")
(generate-bindings bindings t)
,@body
(format *c* "}~%")
(values)))

etc...

To begin with, you only need to be able to generate enough C from sexps,
so that you can write your C code as sexp. And right away, you can
write a couple of lisp macros to write C code at a higher level. Step
by step, macro by macro you get closer to CL, while still generating C
code.

Soon you will have enough Lisp generable into C to translate your tiny
lisp interpreter written in tiny lisp into C.

--
__Pascal Bourguignon__
http://www.informatimago.com