Muddy Scheme

Author: pmarin
Please add content only in the Comments , Bugs or News section.



Introduction

Muddy Scheme is an implementation of the Scheme language in Tcl.

This interpreter tries to follow the awesome "Scheme from Scratch" articles written by Peter Michaux.

Features

  • A garbage collector!!!
  • Procedures
    • define
    • lambda
    • begin
    • Lexically scoped variables
    • Proper tail calls
  • Binding Constructs
    • let
    • let*
  • Conditionals
    • cond
    • and
    • or
  • Types
    • integers
    • characters
    • pairs
    • strings
    • booleans
  • Primitives
    • Type of Predicates
      • not
      • eq?
      • null?
      • boolean?
      • symbol?
      • atom?
      • number?
      • integer?
      • zero?
      • char?
      • string?
      • pair?
      • procedure?
    • Type conversions
      • char->integer
      • integer->char
      • number->string
      • string->number
      • symbol->string
      • string->symbol
    • Working with integers
      • +
      • -
      • *
      • quotient
      • remainder
      • =
      • <
      • >
    • Working with pair and list
      • cons
      • car
      • cdr
      • set-car!
      • set-cdr!
      • list
    • I/O
      • current-output-port
      • open-output-file
      • close-output-port
      • display
      • write
      • newline
      • write-char
      • current-input-port
      • open-input-file
      • close-input-port
      • read-char
      • peek-char
      • eof-object
      • read
    • Others
      • garbage-collect (you can not use it everywhere)
      • apply
      • load
      • exit
      • quit (return to tclsh if you sourced muddy.tcl)
      • tcl-eval

Install

Muddy Scheme needs Tcl8.6 and tcllib (struct::stack)

The Github page is: http://github.com/pmarin/Muddy-Scheme
You can get the code with:

    $ git clone git://github.com/pmarin/Muddy-Scheme.git

Example of use

    $ muddy.tcl
    Welcome to Muddy Scheme, Copyright (c) 2010 Franciso José Marín Pérez
    Use ctrl-c to exit.

    > #t
    #t
    > -123
    123
    > #\c
    #\c
    > "asdf"
    "asdf"
    > (quote ())
    ()
    > (quote (0 . 1))
    (0 . 1)
    > (quote (0 1 2 3))
    (0 1 2 3)
    > (quote asdf)
    asdf
    > (define a 1)
    ok
    > a
    1
    > (set! a 2)
    ok
    > a
    2
    > (if #t 1 2)
    1
    > (+ 1 2 3)
    6
    > + 
    #<primitive>
    >^c
    $

Bugs

News

(2010-2-21) Now the garbage collector is working properly. Use set-mem-limit! for setting the number of object used before the GC. vector and floats are implemented.
(2010-1-25) Added mark-and-sweep garbage collector. Currently It is called always in the REPL and load loop, I need to determinate the size of the process for using it more properly.
(2010-1-24) Almost all I/O procedures
(2010-1-22) Apply and not
(2010-1-22) (V0.17) Added let*. There is a function in debug.scm that print errorInfo:

Welcome to Muddy Scheme, Copyright (c) 2010 Franciso José Marín Pérez
> (load "debug.scm")
#t
> asdf
unbound variable asdf in the environment Env:0
> (error-info)
unbound variable asdf in the environment Env:0
    while executing
"error "unbound variable [$var val] in the environment $_env""
    (class "::Env" method "lookup_variable_value" line 13)
    invoked from within
"$envi lookup_variable_value $exp $env"
    (procedure "_eval" line 13)
    invoked from within
"_eval $str $the_global_environment "
#t

(2010-1-21) (V0.16) Added let, list and tcl-eval. Now is possible to eval tcl code:

> (tcl-eval "puts {Hello Tclers!}" )
Hello Tclers!
#t

(2010-1-20) Added load. Now the REPL is wrapped with catch so if something goes wrong you will remain in the REPL (is a dirty hack but works). Updated to bootstrap-scheme V0.15.
(2010-1-19) Fixed the bug in the reader. Updated to v0.14 and added and & or. Now the interpreter is compliant with "The Little Schemer".
(2010-1-18) Muddy is compliant with bootstrap-scheme v0.14. I need to fix bugs in the reader.

Accumulator Generator:

    >(define (foo n) 
       (lambda (i) 
          (set! n (+ n i)) n))
    >(define acc (foo 3))
    ok
    > (acc 1)
    4
    > (acc 1)
    5 
    > (acc 10)
    15
    > (acc 0)
    15   

(2010-1-17) Muddy is compliant with bootstrap-scheme v0.12
(2010-1-16) Currently the code is compliant with bootstrap-scheme v0.11

License

MIT License
I give permission to wiki users to copy & paste the code in this wiki.

Comments

pmarin. Enjoy!!!