I finally decided to release the source code of this prototype
implementation of a Lisp Interpreter hoping it may serve as an example
(or counter example maybe) for students and "lifetime students" who
are curious about how a Lisp interpreter could be implemented
> cool thanks. it would be even nicer if you wrote what functions it
> supports.
--------------
John Thingstad
Hello
Here is the list of 54 implemented functions (not fully support eg no
error handling):
DEFMACRO AND FUNCTIONP CAR * + LOAD IMPLEMENTED / POP QUOTE THIRD
FUNCTION LISTP FIRST FIFTH OR TRACE GETF SYMBOL-FUNCTION NOT HELP CONS
ED CDR DEFUN EVAL APPLY NULL INTEGERP EXIT PUSH SYSTEM SLEEP REVERSE -
UNTRACE SECOND QUIT MEMSTAT FORMAT FBOUNDP TEST BYE LIST PROGN CONSP
READ DEFVAR < > FOURTH IF EQL
This list is generated by wishlisp interpreter when you type
(implemented), this is described in (help)
BR
michel Kern
I also recently noticed ClearLisp (http://www.xs4all.nl/~tolenaar/
page3.html) which is another interpreter written C#. It's Common Lisp-y,
including generic functions, but has some incompatible extensions for
"convenience".
Matt
I know very little Lisp, but I'm getting what I think are some strange
results. Here's a copy from the shell:
> (defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1)))))
FACTORIAL
> (factorial 5)
120
> (factorial 120)
0
> (factorial 100)
0
> (factorial 50)
0
> (factorial 25)
2076180480
> (factorial 37)
0
> (factorial 31)
738197504
> (factorial 34)
0
> (factorial 33)
-2147483648
> (factorial 32)
-2147483648
> (factorial 31)
738197504
> (factorial 30)
1409286144
> (factorial 29)
-1241513984
> (factorial 28)
-1375731712
> (factorial 27)
1484783616
> (factorial 26)
-1853882368
> (factorial 25)
2076180480
Here's something similar from Clisp:
[1]> (defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1)))))
FACTORIAL
[2]> (factorial 31)
8222838654177922817725562880000000
Steve
> On Sep 16, 4:27 pm, kernmic...@yahoo.fr wrote:
>> Hello
>>
>> I finally decided to release the source code of this prototype
>> implementation of a Lisp Interpreter hoping it may serve as an example
>> (or counter example maybe) for students and "lifetime students" who
>> are curious about how a Lisp interpreter could be implemented
>
> I know very little Lisp, but I'm getting what I think are some strange
> results. Here's a copy from the shell:
>
>> (defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1)))))
> FACTORIAL
>> (factorial 5)
> 120
>> (factorial 120)
> 0
...
> -1241513984
>> (factorial 28)
> -1375731712
>> (factorial 27)
> 1484783616
>> (factorial 26)
> -1853882368
>> (factorial 25)
> 2076180480
>
>
> Here's something similar from Clisp:
> [1]> (defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1)))))
> FACTORIAL
> [2]> (factorial 31)
> 8222838654177922817725562880000000
>
>
> Steve
CL-USER 40 > (rem (fact 25) (expt 2 32))
2076180480
Which looks suspiciously like the result above.
Clearly the implementation doesn't support bignum. Thus you are stuck with
the 32 bit register size.
For large multiplications C# just wraps around leading to these strange
values.
--------------
John Thingstad
As with wishLisp, I hope this provides a shining example of how to
write a slow implementation of lisp in javascript.
http://code.google.com/p/lispyj/source/browse/trunk/modules/evaluation_module.js
Go to line 228 for the lisp code itself.
Hello
Thanks for the feedback, I confess this "bignum" feature I was not
even aware of it and I guess it is by this kind of feature that Lisp
is beyond the more common languages like C# and Java. As this project
is enough interesting to generate feedback from people more educated
in the Lisp implementation than myself, I would like to ask where I
can find the "core functions" as many sources explain that lisp is
bootstrapped and many functions are in fact written in Lisp so where I
can fond the list of these core functions as well as the lisp source
of lisp functions written on top of the core. There is such a thing at
http://lib.store.yahoo.net/lib/paulgraham/jmc.lisp (and in the book
'ANSI Common Lisp') but I seems more an example rather than a complete
'Lisp in Lisp' source
>
> Hello
>
> Thanks for the feedback, I confess this "bignum" feature I was not
> even aware of it and I guess it is by this kind of feature that Lisp
> is beyond the more common languages like C# and Java.
Not exactly. Big number arithmetric is available as a seperate library.
There just isn't any check than automatically converts the number to a
bignum if it overflows. Or for that matter any check for overflow at all.
> As this project
> is enough interesting to generate feedback from people more educated
> in the Lisp implementation than myself, I would like to ask where I
> can find the "core functions" as many sources explain that lisp is
> bootstrapped and many functions are in fact written in Lisp so where I
> can fond the list of these core functions as well as the lisp source
> of lisp functions written on top of the core. There is such a thing at
> http://lib.store.yahoo.net/lib/paulgraham/jmc.lisp (and in the book
> 'ANSI Common Lisp') but I seems more an example rather than a complete
> 'Lisp in Lisp' source
Implementing a full Common Lisp is complicated. If you don't understand
and have experience with CL you will probaly get it wrong. "Lisp in small
pieces" by Quinnebeck is a 'classic' description of the workings of Lisp.
It mostly describes implementation of Scheme, but Common Lisp features are
also explained. It starts with a interprenter, then goes on to a formal
description and finally decribes how to write a compiler. Not for the
faint of heart though. Read "Structured Introduction to computer
Programming" by Abelson, Sussman, and Sussman first[1]. "Paradigms in AI
programming" by Peter Norvig also has a couple of chapters where he
implements a simple Scheme. (And it's a good book on programming Lisp in
general.)
The full soruce code of Corman CL, SBCL an Clozure CL are availabe. The
final word is "The Common Lisp Hyperspec".
[1] SICP is available online at http://mitpress.mit.edu/sicp/.There are
also some video lectures from a cource using the book at MIT at
http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/.
--------------
John Thingstad
> "Lisp in small pieces" by Quinnebeck is a 'classic' description of the
> workings of Lisp.
Queinnec
<http://www.cambridge.org/catalogue/catalogue.asp?isbn=0521545668>
Do you mean "Structure and Interpretation of Computer Programs"?
http://library.readscheme.org/page1.html
Guy Lewis Steele, Jr. and Gerald Jay Sussman. "The Art of the
Interpreter (excellent just finishing it)
Guy Lewis Steele, Jr.. "RABBIT: A Compiler for SCHEME". (next on my
read list)
bobi