Skip to content

FlyCloudC/scheme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FlyCloudC/scheme

A Scheme interpreter implemented in Moonbit. It will be used for teaching purposes and not too many optimizations will be added. The understandability of the code is given top priority.

Reference:

example

test "example in README" {
  let env = Environment::base()..add_number_primitive()
  let code =
    #|(define (fact x)
    #|   (if (= x 0)
    #|       1                      ; base case
    #|       (* x (fact (- x 1))))) ; rec case
    #|(fact 5)
  let sexp = parse!(code)
  let program = [ //
    sexp[0].to_core_form!(),
    sexp[1].to_core_form!(),
  ]
  let inst = program.map(compile)
  // make VM, load "(define (fact x) ...)" and env
  let vm = VM::new(inst=inst[0], env~)
  // run, add "fact" to env
  vm.run_to_halt!()
  inspect!( //
    vm.env.lookup!(Symbol::of("fact")),
    content="#<procedure fact>",
  )
  // load and run "(fact 5)"
  vm.next = inst[1]
  vm.run_to_halt!()
  inspect!(vm.acc, content="120")
}

About

A Scheme interpreter implemented in Moonbit for teaching purposes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published