http://synthcode.com/scheme/chibi-scheme-0.1.tgz
Smaller than TinyScheme, faster than a speeding Guile, able to leap
tall vectors in a single bounds check, with native hygiene to boot!
WARNING: Do not use Chibi-Scheme!
Seriously, there are real Scheme compilers out there. The author
of Chibi-Scheme was working on one himself before starting this
silly project, and will likely continue to work on it for years to
come. But sometimes we all just want to release something.
There seems to be a disturbing trend, however, of people taking
toy Scheme interpreters seriously. It can't be for ease of use,
because the serious compilers all have the most friendly FFI's.
It can't be for the small memory footprint, because the difference
between a 100k and 2MB program text will be dwarfed by the runtime
memory, and all of the real implementations have much more
efficient memory usage. But time and again you'll find TinyScheme
crop in in bizarre places, which leads one to wonder how much of a
bad name is Scheme getting by being so often represented by one of
the slowest language implementations on the planet?
So Chibi-Scheme exists as a better toy implementation. It's a
very small but mostly complete R5RS Scheme implementation using a
reasonably fast custom VM. Chibi-Scheme tries as much as possible
not to trade its small size by cutting corners, and provides full
continuations, both low and high-level hygienic macros based on
syntactic-closures, string ports and exceptions. It also has
optional immediate symbols, just to be quirky.
But don't use Chibi-Scheme. Don't use toy Scheme implementations
at all. But if you really want a toy... well, then perhaps
Chibi-Scheme 0.3 or so may be right for you.
[On a more serious note, I do want to hold this up as an example
of how extremely simple and natural it is to implement
syntactic-closures compared to alternatives such as syntax-case.
The whole macro implementation is about 25 lines of low-level C
code (modulo the extra lines I'll have to add later for bug
fixes), as opposed to say the 4000 or so lines of Scheme for
psyntax.]
--
Alex
http://www.ccil.org/~cowan/chibi-scheme-0.1.tgz
until I get a more stable server.
--
Alex
oh the fun! :)
> WARNING: Do not use Chibi-Scheme!
>
> Seriously, there are real Scheme compilers out there.
[snip]
> There seems to be a disturbing trend, however, of people taking
> toy Scheme interpreters seriously.
[snip]
> efficient memory usage. But time and again you'll find TinyScheme
> crop in in bizarre places, which leads one to wonder how much of a
> bad name is Scheme getting by being so often represented by one of
> the slowest language implementations on the planet?
Well, I'm guilty myself of once recommending it as a very small (and
incomplete) Scheme, before first realizing how slow it is.
OTOH, "It is meant to be used as an embedded scripting interpreter for
other programs." Scripting GUI elements should not exactly demand
performance.
> So Chibi-Scheme exists as a better toy implementation. It's a
> very small but mostly complete R5RS Scheme implementation using a
> reasonably fast custom VM. Chibi-Scheme tries as much as possible
> not to trade its small size by cutting corners, and provides full
> continuations, both low and high-level hygienic macros based on
> syntactic-closures, string ports and exceptions. It also has
> optional immediate symbols, just to be quirky.
Impressive! As much of your Scheme code anyway.
Is it easy to embed it into an app?
> [On a more serious note, I do want to hold this up as an example
> of how extremely simple and natural it is to implement
> syntactic-closures compared to alternatives such as syntax-case.
> The whole macro implementation is about 25 lines of low-level C
> code (modulo the extra lines I'll have to add later for bug
> fixes), as opposed to say the 4000 or so lines of Scheme for
> psyntax.]
C code is much more compact and economic than Scheme code. Besides,
isn't psyntax a host of libs for various implementations?
Interesting nonetheless.
> C code is much more compact and economic than Scheme code.
This is not what I get as experimental results. When I translated my C
libraries into lisp, only 1/10 of them needed translations (the others
were already included in CL, (or Scheme libraries), or were plain useless,
given lisp power), and of those translated, the lisp code was 1/10 of C.
--
__Pascal Bourguignon__
http://www.informatimago.com
> [On a more serious note, I do want to hold this up as an example
> of how extremely simple and natural it is to implement
> syntactic-closures compared to alternatives such as syntax-case.
> The whole macro implementation is about 25 lines of low-level C
> code (modulo the extra lines I'll have to add later for bug
> fixes), as opposed to say the 4000 or so lines of Scheme for
> psyntax.]
Seriously? If it took you one line to implement each basic
form (lambda, cond, or, and, etc), you'd probably end up
with more than 25 lines of code. R6RS's guard macros, by
itself, takes more than 25 lines of code. All these do add
up in a complete macro system like psyntax or Andre's
syntax-case implementation and they do make the majority of
the 4000 lines that you're comparing against.
Aziz,,,
Yes, read the source - it's tiny! :)
The whole idea is _not_ to include any logic about Scheme
in the macro expander at all. Instead, you interleave
macro expansion with syntactic analysis. So you have a fixed
cost for implementing the core forms (define, set!, lambda, if,
begin and quote). Then another cost for implementing any macros
at all - define-syntax, let-syntax and letrec-syntax core forms,
plus one extra case in the analysis loop to see a macro as a head
form and expand it (about 50 lines in chibi-scheme). Then a few
extra special cases for recognizing syntactic closure forms in
analysis and swapping the environments, which really is just a
few more lines of code. identifier=? is 17 lines, though; all
told the hygienic macros are maybe 50 more lines than a defmacro
version.
I'm not counting the R5RS derived forms, which are about 150 lines
of explicit renaming macros (in the already complete and functioning
macro system) or syntax-rules which is itself another 150 line
explicit renaming macro. These are optional - you could decide on
your own Scheme dialect with different derived forms, or use an
alternate pattern matching style to syntax-rules, without any need
to modify the core macro system.
Of course, in the process of defining these macros the first ones
have to be defined only in terms of core forms, and you need to
bootstrap yourself up into a more expressive language. It's an
interesting exercise to find which should be defined first to
find the shortest overall definitions. You'd think you'd want to
implement let and letrec first, but I found it was easier to
implement cond first, then quasiquote. syntax-rules is of course
last, but just to be safe it was initially written without
quasiquote, which makes it especially ugly :)
--
Alex
Yes, very. You can also have multiple VMs running
simultaneously.
--
Alex
> [...] or syntax-rules which is itself another 150 line
> explicit renaming macro.
And is broken. All my tests were for ER macros.
I'll fix that in the next release.
--
Alex
Is this next release coming soon? Or, do you make the development
version (in cvs, svn, git, bzr, tgz, etc.) accessible to the public?
I really would like to see this implementation of syntax-rules as an
explicit renaming macro. (preferably one that actually works)
Aziz,,,