Git Product home page Git Product logo

yascm's Introduction

yascm

Build Status

Yet Another Scheme Interpreter.

Building

The following packages need to install before build:

  • flex
  • bison

Debian/Ubuntu Installation:

sudo apt-get install flex bison

Then run the following:

git clone https://github.com/hmgle/yascm.git
cd yascm
make

If having trouble installing flex/bison, or you don't want to install flex/bison, you can clone the no-flex-bison branch:

git clone -b no-flex-bison https://github.com/hmgle/yascm.git
cd yascm
make

Examples

  • Recursion
$ ./yascm
welcome
> (define (sum x)
    (if (= 0 x) 0 (+ x (sum (- x 1)))))
; ok
> (sum 10000)
50005000
>
  • Closure
$ ./yascm
welcome
> (define (add a)
    (lambda (b) (+ a b)))
; ok
> (define add3 (add 3))
; ok
> (add3 4)
7
> (define my-counter
    ((lambda (count)
       (lambda ()
         (set! count (+ count 1))
         count))
     0)
  )
; ok
> (my-counter)
1
> (my-counter)
2
> (my-counter)
3
>
$ ./yascm
welcome
> (define (A k x1 x2 x3 x4 x5)
    (define (B)
      (set! k (- k 1))
      (A k B x1 x2 x3 x4))
    (if (> 1 k)
        (+ (x4) (x5))
        (B)))
; ok
> (A 10 (lambda () 1) (lambda () -1) (lambda () -1) (lambda () 1) (lambda () 0))
-67
> 
$ ./yascm
; loading stdlib.scm
; done loading stdlib.scm
welcome
> (define Y
    (lambda (h)
      ((lambda (x) (x x))
       (lambda (g)
         (h (lambda args (apply (g g) args)))))))
; ok
> (define fib
    (Y
      (lambda (f)
        (lambda (x)
          (if (> 2 x)
              x
              (+ (f (- x 1)) (f (- x 2))))))))
; ok
> (fib 10)
55
$ ./yascm 
; loading stdlib.scm
; done loading stdlib.scm
welcome
> (load "examples/mceval.scm")
; loading examples/mceval.scm
; done loading examples/mceval.scm
; ok
> (driver-loop)

;;; M-Eval input:
(define fact (lambda (n) (if (= n 0) 1 (* n (fact (- n 1))))))

;;; M-Eval value:
ok

;;; M-Eval input:
(fact 5)

;;; M-Eval value:
120
$ ./yascm 
; loading stdlib.scm
; done loading stdlib.scm
welcome
> ((lambda (x)
      (list x (list (quote quote) x)))
    (quote
      (lambda (x)
        (list x (list (quote quote) x)))))

Testing

$ make test

Authors

LICENSE

GPL Version 3, see the COPYING file included in the source distribution.

yascm's People

Contributors

billjr99 avatar hmgle avatar yuliswe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

yascm's Issues

[Low Priority] Support for infinitely large integer

Should behave in the same way as Scheme.

Example

9999999999999999999999999999999999999
9999999999999999999999999999999999999

-9999999999999999999999999999999999999
-9999999999999999999999999999999999999

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.