Skip to content

PopovMP/schemy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minimal Scheme

Use on server

npm install
npm run build
npm run test

Execute code:

const Schemy = require("../bin/schemy.js").Schemy
const schemy = new Schemy()

const code = `(define a 5)
              (+ a a)`

const res = schemy.evaluate(code)
console.log(res) // -> 10

Use in browser

<script src="js/schemy.js"></script>
<script>
	const schemy = new Schemy()

	const code = `(define a 5)
	              (+ a a)`

	const res = schemy.evaluate(code)
	console.log(res) // -> 10
</script>

Forms

Quote

(quote <expression>)
'<expression>

Definition

(define <symbol> <expression>)

Lambda

Accepts zero or more bound parameters. Evaluates and returns the value of the body expression.

(lambda (p0 p1 ... pn)
  <expression>)

Condition

Contains three expressions

(if <expression>  ; test expression
    <expression>  ; then expression
    <expression>) ; else expression

Block of code

Evaluates all expressions in order. Returns the value of the last expression

(begin <expression 1>
       <expression 2>
       ...
       <expression n>)

Primitive data types

###Symbol

'symbol

Number

1 3.14 +42.5 -22.5

Lambda

(lambda () expr)
(lambda (p1 p2 ... pn) expr)

List

'()
(list)

'(1 2 3)
(list 1 2 3)
(cons 1 (cons 2 (cons 3 '())))

String

"Hello world!"

Standard procedures

Confirm data type:

(number?  e)
(symbol?  e)

Comparison:

(eq? e1 e2) ; Returns 1 or '()

Lists:

(cons e1 e2)
(car e)
(cdr e)

Output:

(display e)
(newline)

Math:

(+  e1 e2)
(-  e1 e2)
(*  e1 e2)
(/  e1 e2)

(modulo e)
(round  e)
(floor  e)

(=  e1 e2)
(>  e1 e2)
(>= e1 e2)
(<  e1 e2)
(<= e1 e2)

About

A Scheme language interpreter in JavaScript.

Topics

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Contributors