Giter VIP home page Giter VIP logo

jcscheme's Introduction

JCScheme

After programming so many years, I finally write my own language !

JCScheme = Jiacai's Scheme ๐Ÿ˜Š

Concepts

JCScheme use S-expression internally to represent AST like any other Scheme. SExpression.java is the implementation of S-expression, which is the core part of JCScheme.

FYI, diagram below is the S-expression of (+ 1 2 (* 3 4)) expressed inside SExpression.java. AST_demo

More explanations can be found in my Chinese blog ใ€Šๆˆ‘็š„็ฌฌไธ€ไธช็Žฉๅ…ท่ฏญ่จ€ JCScheme ้—ฎไธ–ไบ†ใ€‹ใ€‚

Install

git clone [email protected]:jiacai2050/JCScheme.git
cd JCScheme; mvn clean package
java -jar target/JCScheme-*.jar

You can install rlwrap to support line editing, persistent history and completion.

# ubuntu
sudo apt-get install rlwrap
# centos 
sudo yum install rlwrap
# Mac
brew install rlwrap  # for Homebrew
port install rlwrap  # for MacPorts

Then, run JCScheme like this

rlwrap java -jar target/JCScheme-*.jar

Syntax

The very first version of JCScheme support:

  1. datatype: Number, Bool, Function
  2. keyword: if, def, lambda
  3. literal: true, false

More new features can be found at Change Logใ€‚

rlwrap java -jar target/JCScheme-*.jar
>> (* 2 3 4 5)
120
>> (def a 4)
null
>> (def b 5)
null
>> (if (> a b) a b)
5
>> (def max (lambda (a b) (if (> a b) a b)))
null
>> (def c (max a b))
null
>> c
5

ChangeLog

>> ((lambda (a b) (if (> a b) a b)) 3 4)
4
>> (lambda (a b) (if (> a b) a b))
Function :
	Args : [a, b]
	Body : ( if ( > a b )  a b )
  • 0.0.3-SNAPSHAT, 2015/10/05
    1. new datatype: pair and list
    2. new keyword: consใ€list
    3. new builtin function: carใ€cdrใ€empty?
    4. a new literal: nil, which stands for empty list
>> (cons 1 2)
[1, 2]
>> (car (cons 1 2))
1
>> (cdr (cons 1 2))
2
>> (list) # identical to nil
nil   
>> (list 1 2)
(1, 2)
>> (car (list 1 2))
1
>> (cdr (list 1 2)) #  aware of the difference between this and (cdr (cons 1 2))
(2)
>> (empty? (cdr (list 1 2)))
false
>> (empty? (cdr (cdr (list 1 2))))
true
>> (empty? nil)
true
>> (cons 1 nil)
(1)
>> (list 1)  # identical to (cons 1 nil)
(1)
  • 0.0.4-SNAPSHAT, 2015/10/06
    1. support closure
    2. support currying
    3. support function scope
# closure demo
>> (def adder (lambda (x) (lambda (y) (+ x y))))
null
>> (def add2 (adder 2))
null
>> (add2 3)
5
# currying demo
>> (def myadd (lambda (x y) (+ x y)))
null
>> (myadd 3)
Function :
        Args : [y]
        Body : [( + x y ) ]
>> ( (myadd 3) 4)
7
# function scope demo
>> (lambda () (def a 1) a)
Function :
        Args : []
        Body : [( def a 1 ) , a]
>> ((lambda () (def a 1) a))
1
>> a    # variable a isn't in global scope
Error token: a

License

MIT License ยฉ Jiacai Liu

jcscheme's People

Watchers

James Cloos avatar sunbiaobiao avatar  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.