From: ····@compuserve.com
Subject: ( picoVerse-:( How to implement quasiquote ) )
Date: 
Message-ID: <1170664229.288660.216050@v45g2000cwv.googlegroups.com>
Hi

I am implementing Lisp on top of Smalltalk.  Dolphin Smalltalk for
Windows.
I am following the implementation in the ( book "Lisp In Small
Pieces" ).
I am trying to make the implementation itself easy to understand.
There is a test suite that is like a guided tour which can be stepped
through.
All the Smalltalk Classes and methods are available in this Lisp via
the perform:withArguments: bottle neck.  The style is ( at:put:
anArray 1 anObject ).
It does continuations and should be able to do macros at some point.
It compiles into a tree of Objects.  Which can be inpected and
evaluated.
It should be able to do source level debugging via a stepper if there
are no Macros.  What happens when there are Macros I don't know.
Macros seem to be why the Lisp debuggers do not do source level
debugging or seem reluctant to do so.  At least not in the Smalltalk
way.  This Lisp will be highly informed by Smalltalk with Browsers and
Packages instead of source code files.  Smalltalk will be its
primative language.

It should be able to generate byte codes at some point which will be
speed limited by the BlockClosure>>value message bottle neck.

The design could also generate machine code.  At some point.  I hope I
can get Smalltalk MT to make a DLL that can take a machine code
ByteArray generated by Dolphin and evaluate it.  Perhaps a CPU
simulator could be made in Smalltalk and machine instructions for that
could be generated.  At some point those machine codes might run on
the CPU and RAM itself.

I hope to publish the Packages for this at some point and try to get
some help with it.  I'm thinking about sourceforge.  The basic stuff
works.  The idea is to make a Lisp that totally reflects all its inner
workings by having all of the source code in Smalltalk be available.
So that it can totally have a test suite that totally shows you all
the inner workings about how it works and its implementation.
Starting from simple expressions and going on to more complex things.

The idea is to have a small elegant design.  And the design in the
book combined with Smalltalk seems to be doing that.  The basic stuff
works.

So I seem to be ready to start to move on to Macros now.

So my question is about quasiquotes.  Implementing quasiquotes.

The book does not tell about how to implement quasiquotes.
I have been having some ideas but I want a good design.
The design that I have seems to be good( from the book ).
I implemented the tail recursion optimization in a day.
So I think the design is good.  So far.

I have a Lisp Lexer that breaks source code up into subStrings.
And then a simple Parser that collects those into List Objects.
Then each Lisp expression type has a Compiler Class for it which
compiles members of that expression into trees of Eval Objects which
can be evaluated and run via the
>>evalWithActivation:returningToContinuation: message.

So it all runs fine.  It does tail optimization, continuations,
function creation, function calling.  The slow version is built to
reveal itself.  Not go fast.  The byte code and machine code versions
will be the ones that go fast.  I'm hoping I can stick the code
generation right into the Evals so you can either evaluate them
directly or tell them to generate byte codes or machine codes.

So my question is about quasiquotes.  Implementing quasiquotes.

Is there a book that tells how to do this?  Or a paper?

Is there anyone here who has done it who is willing to say how it
should be done?

Should it be done at the Parse into Lists phase?

So you quote a list but then you traverse the list looking for , and .
operators and when you find them you have to do special things.  You
have to compile expressions and run them to make further lists and
stitch them into the quote.  And those expressions might have
quasiquotes inside of them too.  So that sounds like what the
compilers and evaluators are doing.  It's a little confusing.  So a
little advice about how to do it would be appreciated.

-Kjell

From: Rob Thorpe
Subject: Re: ( picoVerse-:( How to implement quasiquote ) )
Date: 
Message-ID: <1170674186.455597.239860@k78g2000cwa.googlegroups.com>
> Is there a book that tells how to do this?  Or a paper?
>
> Is there anyone here who has done it who is willing to say how it
> should be done?
>
> Should it be done at the Parse into Lists phase?
>
> So you quote a list but then you traverse the list looking for , and .
> operators and when you find them you have to do special things.  You
> have to compile expressions and run them to make further lists and
> stitch them into the quote.  And those expressions might have
> quasiquotes inside of them too.  So that sounds like what the
> compilers and evaluators are doing.  It's a little confusing.  So a
> little advice about how to do it would be appreciated.

To add to Pascal's answer...

Backquote is quite simple, it's normally a reader macro.  It simply
performs substitutions, it does not concern itself with compiling etc,
it produces only lists.  It does not concern itself with nested
backquotes, their behaviour comes about naturally from the behaviour
of backquote.  It operates by making the ` @ and , characters special
to the reader, forming a tree and processing it.

The spec allows it to be written in other ways, e.g. to be treated
directly by the reader.
From: Pascal Costanza
Subject: Re: ( picoVerse-:( How to implement quasiquote ) )
Date: 
Message-ID: <52oas9F1of4e2U1@mid.individual.net>
····@compuserve.com wrote:

> So my question is about quasiquotes.  Implementing quasiquotes.
> 
> Is there a book that tells how to do this?  Or a paper?
> 
> Is there anyone here who has done it who is willing to say how it
> should be done?

CLtL2 contains an appendix with a backquote implementation. There are 
also implementations of backquote / quasiquote in all Common Lisp and 
Scheme implementations, including of course the open source ones.


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Marco Monteiro
Subject: Re: ( picoVerse-:( How to implement quasiquote ) )
Date: 
Message-ID: <1170838573.505441.320750@q2g2000cwa.googlegroups.com>
On Feb 5, 8:30 am, ····@compuserve.com wrote:
> So my question is about quasiquotes.  Implementing quasiquotes.
>
> Is there a book that tells how to do this?  Or a paper?

Have you tried Google? There is a fine paper by Alan Bawden. Search
for (the obvious) "quasiquotation in lisp".

Marco