From: Jeff Massung
Subject: Using Lisp to make Lisp
Date: 
Message-ID: <veha9cfo427d10@corp.supernews.com>
Okay, beginner question I'm sure:

I'd like to create my own Lisp environment. Simple enough, I can do this in 
C. My problem is that I'd like to make it in Lisp, but I want it to be very 
specific and limited. I don't want to pass along an entire Lisp system, but 
rather my own little incarnation of Lisp.

So how can I go about doing this? Do I need to write a full app in Lisp 
that would be the same as my C program (ie. create a parser, interpreter, 
etc)? or can I take advantage of what Lisp has to offer me without 
including the whole system?

As an example of what I would like to do: I'd like to make a DEFCOL 
function that would act like a DEFUN, but differently (no need to get into 
details). I would like this function (or macro) available in my Lisp 
implementation, but not DEFUN.

If I'm not being clear enough, let me know and I'll try to explain better. 
Any pointers would be appreciated! Thanks in advance.

-- 
Best regards,
 Jeff                          ··········@mfire.com
                               http://www.simforth.com

From: Erann Gat
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <gat-1206031014450001@k-137-79-50-101.jpl.nasa.gov>
In article <··············@corp.supernews.com>, Jeff Massung
<···@NOSPAM.mfire.com> wrote:

> Okay, beginner question I'm sure:
> 
> I'd like to create my own Lisp environment. Simple enough, I can do this in 
> C. My problem is that I'd like to make it in Lisp, but I want it to be very 
> specific and limited. I don't want to pass along an entire Lisp system, but 
> rather my own little incarnation of Lisp.
> 
> So how can I go about doing this? Do I need to write a full app in Lisp 
> that would be the same as my C program (ie. create a parser, interpreter, 
> etc)? or can I take advantage of what Lisp has to offer me without 
> including the whole system?
> 
> As an example of what I would like to do: I'd like to make a DEFCOL 
> function that would act like a DEFUN, but differently (no need to get into 
> details). I would like this function (or macro) available in my Lisp 
> implementation, but not DEFUN.
> 
> If I'm not being clear enough, let me know and I'll try to explain better. 
> Any pointers would be appreciated! Thanks in advance.

You want to learn about packages.

In particular, you want to make a package that doesn't use any other
packages, and only imports those things that you want to inherit.  (If
that didn't make sense, it will once you've done your background reading.)

E.
From: Nils Goesche
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <ly3ciftcv1.fsf@cartan.de>
Jeff Massung <···@NOSPAM.mfire.com> writes:

> I'd like to create my own Lisp environment. Simple enough, I can do
> this in C. My problem is that I'd like to make it in Lisp, but I
> want it to be very specific and limited. I don't want to pass along
> an entire Lisp system, but rather my own little incarnation of Lisp.
> 
> So how can I go about doing this? Do I need to write a full app in
> Lisp that would be the same as my C program (ie. create a parser,
> interpreter, etc)? or can I take advantage of what Lisp has to offer
> me without including the whole system?
> 
> As an example of what I would like to do: I'd like to make a DEFCOL
> function that would act like a DEFUN, but differently (no need to
> get into details). I would like this function (or macro) available
> in my Lisp implementation, but not DEFUN.

You don't need your own parser: You can customize the builtin reader
and use READ.  You could make packages like MYLISP and MYLISP-USER
containing the primitives of your new language and don't accept any
expressions containing symbols from other packages.  Then, what you do
with the parsed expressions it up to you... in the simplest case, you
can simply translate them to valid CL and compile/run that.  Use
macros for that:

(defpackage "MYLISP"
  (:use "CL")
  (:export "DEFCOL"))

(in-package "MYLISP")

(defmacro defcol (&rest args)
  `(defun ,@args))

or something like that.

Or you could write your own interpreter or compiler.  But then you
should read a book first:

  ``Lisp in Small Pieces�� by Christian Queinnec

is probably best.

Regards,
-- 
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0
From: Jeff Massung
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <vehf3u3bhlvi99@corp.supernews.com>
Nils Goesche <······@cartan.de> wrote in ···················@cartan.de:

Thanks for the ideas. Didn't know about packages yet. I assume in-package 
limits the scope of macros, functions, etc that can be evaluated?

> 
> Or you could write your own interpreter or compiler.  But then you
> should read a book first:
> 
>   ``Lisp in Small Pieces�� by Christian Queinnec
> 

Currently reading it... best money spent on a book yet (IMHO). This is 
where my question arose from. In the book, a Lisp interpreter is written 
using Scheme...

-- 
Best regards,
 Jeff                          ··········@mfire.com
                               http://www.simforth.com
From: Erann Gat
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <gat-1206031105540001@k-137-79-50-101.jpl.nasa.gov>
In article <··············@corp.supernews.com>, Jeff Massung
<···@NOSPAM.mfire.com> wrote:

> Thanks for the ideas. Didn't know about packages yet. I assume in-package 
> limits the scope of macros, functions, etc that can be evaluated?

Not quite.  It limits the symbols you can access without having to use a
special syntax.

I've been contemplating writing a "Complete idiot's guide to packages". 
It would be useful to know if, after reading what is already available,
you think such a thing would have been useful to you.

E.
From: Björn Lindberg
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <hcsbrwz4e14.fsf@tjatte.nada.kth.se>
···@jpl.nasa.gov (Erann Gat) writes:

> In article <··············@corp.supernews.com>, Jeff Massung
> <···@NOSPAM.mfire.com> wrote:
> 
> > Thanks for the ideas. Didn't know about packages yet. I assume in-package 
> > limits the scope of macros, functions, etc that can be evaluated?
> 
> Not quite.  It limits the symbols you can access without having to use a
> special syntax.
> 
> I've been contemplating writing a "Complete idiot's guide to packages". 
> It would be useful to know if, after reading what is already available,
> you think such a thing would have been useful to you.

I certainly would read such a guide. I still haven't completely
grasped packages.


Bj�rn
From: Yarden Katz
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <86he6ksj3d.fsf@underlevel.net>
···@jpl.nasa.gov (Erann Gat) writes:

> <···@NOSPAM.mfire.com> wrote:
>
>> Thanks for the ideas. Didn't know about packages yet. I assume in-package 
>> limits the scope of macros, functions, etc that can be evaluated?
>
> I've been contemplating writing a "Complete idiot's guide to packages". 
> It would be useful to know if, after reading what is already available,
> you think such a thing would have been useful to you.

Yes.  Write it.
-- 
Yarden Katz <····@underlevel.net>  |  Mind the gap
From: Drew McDermott
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <85abc9ba.0306211207.70a3b85f@posting.google.com>
···@jpl.nasa.gov (Erann Gat) wrote in message news:<····················@k-137-79-50-101.jpl.nasa.gov>...

> I've been contemplating writing a "Complete idiot's guide to packages". 
> It would be useful to know if, after reading what is already available,
> you think such a thing would have been useful to you.
> 
> E.

If you do, consider adding it to the Common Lisp Cookbook
(http://cl-cookbook.sourceforge.net/)

It looks like they need a chapter on packages.
From: Erann Gat
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <gat-2106031431490001@192.168.1.51>
In article <····························@posting.google.com>,
··············@yale.edu (Drew McDermott) wrote:

> ···@jpl.nasa.gov (Erann Gat) wrote in message
news:<····················@k-137-79-50-101.jpl.nasa.gov>...
> 
> > I've been contemplating writing a "Complete idiot's guide to packages". 
> > It would be useful to know if, after reading what is already available,
> > you think such a thing would have been useful to you.
> > 
> > E.
> 
> If you do, consider adding it to the Common Lisp Cookbook
> (http://cl-cookbook.sourceforge.net/)
> 
> It looks like they need a chapter on packages.

OK, this now officially on my todo list.

E.
From: Erann Gat
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <gat-2106031433170001@192.168.1.51>
In article <····················@192.168.1.51>, ···@jpl.nasa.gov (Erann
Gat) wrote:

> In article <····························@posting.google.com>,
> ··············@yale.edu (Drew McDermott) wrote:
> 
> > ···@jpl.nasa.gov (Erann Gat) wrote in message
> news:<····················@k-137-79-50-101.jpl.nasa.gov>...
> > 
> > > I've been contemplating writing a "Complete idiot's guide to packages". 
> > > It would be useful to know if, after reading what is already available,
> > > you think such a thing would have been useful to you.
> > > 
> > > E.
> > 
> > If you do, consider adding it to the Common Lisp Cookbook
> > (http://cl-cookbook.sourceforge.net/)
> > 
> > It looks like they need a chapter on packages.
> 
> OK, this now officially on my todo list.
> 
> E.

Hm, it says that Tim Bradshaw is working on this.

http://cl-cookbook.sourceforge.net/packages.html

E.
From: Kenny Tilton
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <3EE8D403.8040706@nyc.rr.com>
Jeff Massung wrote:
> Nils Goesche <······@cartan.de> wrote in ···················@cartan.de:
> 
> Thanks for the ideas. Didn't know about packages yet. I assume in-package 
> limits the scope of macros, functions, etc that can be evaluated?
> 
> 
>>Or you could write your own interpreter or compiler.  But then you
>>should read a book first:
>>
>>  ``Lisp in Small Pieces�� by Christian Queinnec
>>
> 
> 
> Currently reading it... best money spent on a book yet (IMHO).

Wow, maybe I should read my copy, I imagine you've spent money on more 
than a few other books given your background.

Are you hoping with your mini-lisp project to come up with a small, 
standalone exe lisp environment? If so, I doubt you'll shake the rest of 
CL via package-based exclusion. But I'm no expert.


-- 

  kenny tilton
  clinisys, inc
  http://www.tilton-technology.com/
  ---------------------------------------------------------------
"Everything is a cell." -- Alan Kay
From: Jeff Massung
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <vehn729mn15e7e@corp.supernews.com>
Kenny Tilton <·······@nyc.rr.com> wrote in
·····················@nyc.rr.com: 

> 
> Wow, maybe I should read my copy, I imagine you've spent money on more
> than a few other books given your background.

I'm no expert on lambda-calculus, so some parts of the book are a little 
diffucult to follow. But overall it has been a wealth of information. 
Finding information on creating a Lisp compiler/interpreter is more than 
difficult.

> 
> Are you hoping with your mini-lisp project to come up with a small, 
> standalone exe lisp environment? If so, I doubt you'll shake the rest
> of CL via package-based exclusion. But I'm no expert.
> 
> 

I got a crazy language-notion in my head that I just have to attempt. I 
believe firmly that two languages are the best out there: Lisp (desktop) 
and Forth (embedded). Neither seems to be very practical in the other's 
"natural" environment, but combined, I think they could make quite the 
team.

My idea is to use Lisp syntax to create an interactive assembler and 
Forth compiler. Most likely this idea would not amount to much and may be 
a total flop, but something tells me the idea is sound (even if my first 
implementation is far from it).

Here would be a small sample of what I envision this language being like:


; define an ADD instruction for THUMB mode (ARM7TDMI)
(defun add (rd imm)
	(cond
		((eq rd 'sp)
			(byte-compile (bit-shift-right imm 2) 0xB0))
		(t (byte-compile imm (bit-or 0x30 rd)))))

; BX rm
(defun bx (rm)
	(cond
		((member rm '(r0 r1 r2 r3 r4 r5 r6 r7))
			(byte-compile (bit-shift-left rm 3)))
		(t (byte-compile (bit-or (bit-shift-left rm 3) 0x40))))
	(byte-compile 0x47))

; compiles a Forth CODE word that will add n to the top of stack
(defun add-n (name n)
    	(defcode name (add r0 n) (bx lr)))

; create an increment function
(add-n increment 1)

; create a Forth COLON definition to increment 3 times
(defcol inc-3-times increment increment increment)


I'd be curious as to what others think about this idea. Perhaps it is 
completely silly. Perhaps it is something that Lisp can do already with a 
lot of macro work?

What are the advantages of such a language? In my mind, it is the ability 
at compile time (what Lisp excels at) to create embedded lookup tables, 
import binary information without external programs: my platform of 
choice at the momeny is the GameBoy Advance. Being able to import a JPEG 
from HD and convert it to GBA format and compile it into the binary at 
compile time is a big plus. 

Lastly, it is very retargetable - easily. Instead of having a compiler 
designed from the ground up to be for X processor, you actually create 
the functions that will compile assembly. Rewrite a couple low-level CODE 
definitions and away you go with highly portable COLON definitions (what 
Forth excels at).

Comments? 2 cents? dollars even? :)

-- 
Best regards,
 Jeff                          ··········@mfire.com
                               http://www.simforth.com
From: Erann Gat
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <gat-1206031316150001@k-137-79-50-101.jpl.nasa.gov>
In article <··············@corp.supernews.com>, Jeff Massung
<···@NOSPAM.mfire.com> wrote:

> My idea is to use Lisp syntax to create an interactive assembler and 
> Forth compiler. Most likely this idea would not amount to much and may be 
> a total flop, but something tells me the idea is sound (even if my first 
> implementation is far from it).

There is a long history of this sort of thing being done in Lisp with much
success, mainly in the area of programming microcontrollers for auonomous
mobile robots, but also in other areas.  (I once did exactly what you
describe -- write a Forth compiler in Lisp -- to generate a code patch for
the magnetometer instrument on the Galileo spacecraft.  The whole project
took three months from start to finish, and was considered a great
success.)

But the right way to do this is not to build a minimalist Lisp that
doesn't have defun.  The right way to do this is to simply write a
compiler for a small embedded language in Lisp.  That's much easier than
implementing a Lisp system from scratch.

E.
From: Jeff Massung
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <vehs43pgdc8199@corp.supernews.com>
···@jpl.nasa.gov (Erann Gat) wrote in
·························@k-137-79-50-101.jpl.nasa.gov: 

> In article <··············@corp.supernews.com>, Jeff Massung
> <···@NOSPAM.mfire.com> wrote:
> 
>> My idea is to use Lisp syntax to create an interactive assembler and 
>> Forth compiler. Most likely this idea would not amount to much and
>> may be a total flop, but something tells me the idea is sound (even
>> if my first implementation is far from it).
> 
> There is a long history of this sort of thing being done in Lisp with
> much success, mainly in the area of programming microcontrollers for
> auonomous mobile robots, but also in other areas.  (I once did exactly
> what you describe -- write a Forth compiler in Lisp -- to generate a
> code patch for the magnetometer instrument on the Galileo spacecraft. 
> The whole project took three months from start to finish, and was
> considered a great success.)

Thank you for letting me know this. It encourages me to continue.

> 
> But the right way to do this is not to build a minimalist Lisp that
> doesn't have defun.  The right way to do this is to simply write a
> compiler for a small embedded language in Lisp.  That's much easier
> than implementing a Lisp system from scratch.
> 

I'm looking at all my options before picking a direction initially. I 
wasn't going to remove defun per se, instead I was trying to convey the 
notion that I didn't want to just code a few functions and rewrite read-
eval-print. Perhaps that is what I should do, but it isn't what I want to 
do :)

-- 
Best regards,
 Jeff                          ··········@mfire.com
                               http://www.simforth.com
From: Nils Goesche
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <lyu1avrwp6.fsf@cartan.de>
Jeff Massung <···@NOSPAM.mfire.com> writes:

> Nils Goesche <······@cartan.de> wrote in ···················@cartan.de:
> 
> Thanks for the ideas. Didn't know about packages yet. I assume
> in-package limits the scope of macros, functions, etc that can be
> evaluated?

Not really.  But if you check that expressions you read in contain
only symbols from certain packages you have defined yourself (and
reject them otherwise), the user will not have access to the rest of
CL.

Regards,
-- 
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0
From: Nils Goesche
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <lyy907rxw4.fsf@cartan.de>
I <······@cartan.de> wrote:

> (defpackage "MYLISP"
>   (:use "CL")
>   (:export "DEFCOL"))
> 
> (in-package "MYLISP")
> 
> (defmacro defcol (&rest args)
>   `(defun ,@args))
> 
> or something like that.

I should also mention that you don't have to rename everything.  You
could also do

(defpackage "MYLISP"
  (:use "CL")
  (:shadow "DEFUN")
  (:export "DEFUN"))

(in-package "MYLISP")

(defmacro defun (&rest args)
  `(cl:defun ,@args)) ; or something modified

and later

(defpackage "MYLISP-USER"
  (:use "MYLISP"))

of course.

Regards,
-- 
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0
From: Luke J Crook
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <RT4Ga.51896$49.1565145@twister.socal.rr.com>
Looking at your webpage, is your target platform the GBA ? That would be
cool.

-Luke


"Jeff Massung" <···@NOSPAM.mfire.com> wrote in message
···················@corp.supernews.com...
> Okay, beginner question I'm sure:
>
> I'd like to create my own Lisp environment. Simple enough, I can do this
in
> C. My problem is that I'd like to make it in Lisp, but I want it to be
very
> specific and limited. I don't want to pass along an entire Lisp system,
but
> rather my own little incarnation of Lisp.
>
> So how can I go about doing this? Do I need to write a full app in Lisp
> that would be the same as my C program (ie. create a parser, interpreter,
> etc)? or can I take advantage of what Lisp has to offer me without
> including the whole system?
>
> As an example of what I would like to do: I'd like to make a DEFCOL
> function that would act like a DEFUN, but differently (no need to get into
> details). I would like this function (or macro) available in my Lisp
> implementation, but not DEFUN.
>
> If I'm not being clear enough, let me know and I'll try to explain better.
> Any pointers would be appreciated! Thanks in advance.
>
> -- 
> Best regards,
>  Jeff                          ··········@mfire.com
>                                http://www.simforth.com
From: Jeff Massung
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <vehns63c3jbcd2@corp.supernews.com>
"Luke J Crook" <····@NO-SPAM.balooga.com> wrote in
···························@twister.socal.rr.com: 

> Looking at your webpage, is your target platform the GBA ? That would
> be cool.
> 
> -Luke

Yep. Currently Dragon BASIC (what you see) actually compiles to Forth, 
then is compiled to native code.... extremely compact and fast =)

The best part about this is:

I initially wrote Dragon BASIC for kids. Giving them the opportunity to 
learn [good] programming in a way they could see results quickly. The 
registered used actually have full access to all the assembly.

The more they learned about Dragon BASIC, they more they were interested 
in Forth (a lot of ``what is it?'' questions). The more I talk about this 
language on my forums (I call the language "tin") the more excited these 
kids get.

I'm hoping this will be an exciting way to bring Forth and Lisp to those 
that only know about C, and teach them to code well.

-- 
Best regards,
 Jeff                          ··········@mfire.com
                               http://www.simforth.com
From: William Barnett-Lewis
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <MovGa.7044$vx3.2306053@kent.svc.tds.net>
"Jeff Massung" <···@NOSPAM.mfire.com> wrote in message
···················@corp.supernews.com...
> "Luke J Crook" <····@NO-SPAM.balooga.com> wrote in
> ···························@twister.socal.rr.com:
>
> > Looking at your webpage, is your target platform the GBA ? That would
> > be cool.
> >
> > -Luke
>
> Yep. Currently Dragon BASIC (what you see) actually compiles to Forth,
> then is compiled to native code.... extremely compact and fast =)

Oh. my. "I must have this..." to quote Dork Tower.  I am unable to help you
get there, but I'd do more than I care to think about for a copy of the
final environment.

> The best part about this is:
>
> I initially wrote Dragon BASIC for kids. Giving them the opportunity to
> learn [good] programming in a way they could see results quickly. The
> registered used actually have full access to all the assembly.
>
> The more they learned about Dragon BASIC, they more they were interested
> in Forth (a lot of ``what is it?'' questions). The more I talk about this
> language on my forums (I call the language "tin") the more excited these
> kids get.

Hrm. This seems too obvious, but you have read about Logo?

> I'm hoping this will be an exciting way to bring Forth and Lisp to those
> that only know about C, and teach them to code well.

Schweet.. Good luck in your attempt.

> -- 
> Best regards,
>  Jeff                          ··········@mfire.com
>                                http://www.simforth.com

William
From: Barry Margolin
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <sQ6Ga.22$9D3.204@paloalto-snr1.gtei.net>
In article <··············@corp.supernews.com>,
Jeff Massung  <···@NOSPAM.mfire.com> wrote:
>Okay, beginner question I'm sure:
>
>I'd like to create my own Lisp environment. Simple enough, I can do this in 
>C. My problem is that I'd like to make it in Lisp, but I want it to be very 
>specific and limited. I don't want to pass along an entire Lisp system, but 
>rather my own little incarnation of Lisp.
>
>So how can I go about doing this? Do I need to write a full app in Lisp 
>that would be the same as my C program (ie. create a parser, interpreter, 
>etc)? or can I take advantage of what Lisp has to offer me without 
>including the whole system?
>
>As an example of what I would like to do: I'd like to make a DEFCOL 
>function that would act like a DEFUN, but differently (no need to get into 
>details). I would like this function (or macro) available in my Lisp 
>implementation, but not DEFUN.
>
>If I'm not being clear enough, let me know and I'll try to explain better. 
>Any pointers would be appreciated! Thanks in advance.

Read the chapter on "Meta-Circular Evaluators" in "Structure and
Interpretation of Computer Programs".

-- 
Barry Margolin, ··············@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Moop
Subject: Re: Using Lisp to make Lisp
Date: 
Message-ID: <87isr2fmfr.fsf@foo.foo>
Barry Margolin <··············@level3.com> writes:

> Read the chapter on "Meta-Circular Evaluators" in "Structure and
> Interpretation of Computer Programs".

Hi,

Just thought I'd add that SICP is available on-line:

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-1.html

Shawn