GithubHelp home page GithubHelp logo

orchidrock / myscheme Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 59 KB

An experimental Scheme interpreter implemented using C++.

License: BSD 3-Clause "New" or "Revised" License

CMake 0.27% C++ 84.46% Scheme 15.27%

myscheme's Introduction

MyScheme

An experimental Scheme interpreter implemented using C++.

Build & Run

$ cmake -B build

$ cd build

$ make

$ ./MyScheme

Simple Example

> Welcome to MyScheme. Use Ctrl-C to exit.
> 123
123
> -123
-123
> "sdf"
"sdf"
> #t
#t
> #f
#f
> #\a
#\a
> abc
abc
> (1 . 2)
(1 . 2)
> (1 . (2 . 3))
(1 2 . 3)
> (1 2)
(1 2)
> (1 (2 3))
(1 2 3)

Complex example

> (define count
        ((lambda (total)
            (lambda (increment)
                (set! total (+ total increment))
                total))
        0))
ok
> (count 3)
3
> (count 5)
5
>(define (factorial n)
    (define (iter product counter max-count)
      (if (> counter max-count)
          product
          (iter (* counter product)
                (+ counter 1)
                max-count)))
    (iter 1 1 n))
ok
> (factorial 4)
24
> (define Y
    (lambda (f)
      ((lambda (x) (f (lambda (y) ((x x) y))))
       (lambda (x) (f (lambda (y) ((x x) y)))))))
ok
> (define factorial
    (Y (lambda (fact) 
         (lambda (n) 
           (if (= n 0)
               1
               (* n (fact (- n 1))))))))
ok
> (factorial 5)
120

Script Test

$ cd test

$ ../build/MyScheme

> Welcome to MyScheme. Use Ctrl-C to exit.
> (load "stdlib.scm") ; library 
ok
> (load "conventional_interfaces.scm") ; library
ok
> x
(1 2 3 4 5)
> x2
(1 (2 (3 4)) 5)
> x3
((1 2 3) (2 3 4) (3 4 5))
> T1
(1 4 9 16 25)
> T2
(1 3 5)
> T3
15
> T4
120
> T5
(1 2 3 4 5)
> T6
(2 3 4 5 6 7)
> T7
(1 2 3 4 5)
> (load "eight_queens_puzzle.scm") ; eight queens puzzle problem.
ok
> T7

About Garbage Collector

myscheme's People

Contributors

orchidrock avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.