Skip to content

mrsch/CPPScheme

Repository files navigation

CPPScheme

Scheme implementation in C++ that depends on C++17s new std::variant and std::optional. Heavily inspired by Write Yourself a Scheme in 48 Hours.

Uses Haskell-like Maybe and Either types.

Tested with gcc 7.2.0 on Linux

Setup

Required dependencies

Get source

git clone --recursive https://github.com/mrsch/CPPScheme.git

Build

  1. Run cmake -E chdir build cmake .. to setup the project
  2. Compile with cmake --build build
  3. Run main: cd bin && ./main
  4. Run ( non existanst :-( )tests: cd bin && ./unit_test

Anti Features

  • No proper tail recursion
  • No tests
  • Not all standard procedures implemented
  • Only floats as numbers
  • No macros
  • Not optimized
  • Lots of unnessecary copies

Features

  • Haskell like error handling with Either type
  • Scheme values as Sum type with std::variant
  • Should not leak thanks to std::shared_ptr
  • Some standard procedures are implemented directly in Scheme (see resources/stdlib.scm)

Types

  • Booleans - #t and #f
  • Numbers - floats
  • Strings
  • Vector - #()
  • Lambdas
  • Characters - #\t
  • Atoms

Primitive Expressions

  • [X] define
    • [X] shorthand lambda define
  • [X] quote
  • [X] lambda
  • [X] procedure call
  • [X] if
  • [X] set!

Derived Expressions

  • [X] cond
  • [X] case
  • [X] and
  • [X] or
  • [X] let
  • [X] begin
  • [ ] do
  • [ ] named let
  • [ ] delay + force
  • [ ] quasiquote

Standard Procedures

  • [X] apply
  • [X] eval
  • [X] car
  • [X] cdr
  • [X] cons
  • [X] eqv?
  • [ ] eq?
  • [ ] equal=

Output

  • [X] display

Booleans

  • [X] not

Math

  • [X] +
  • [X] -
  • [X] *
  • [X] /
  • [X] modulo
  • [ ] remainder
  • [ ] max
  • [ ] min
  • [ ] abs
  • [ ] gcd
  • [ ] lcm
  • [ ] floor
  • [ ] ceiling
  • [ ] truncate
  • [ ] round
  • [ ] expt

Numerical

  • [X] =
  • [X] <
  • [X] >
  • [X] <=
  • [X] >=
  • [X] zero?
  • [X] positive?
  • [X] negative?
  • [X] odd?
  • [X] even?
  • [ ] min
  • [ ] max

Lists

  • [X] null?
  • [X] length
  • [X] reverse
  • [X] map (only 1 list)

Additional Procedures

  • [X] curry
  • [X] id
  • [X] flip
  • [X] compose
  • [X] folds (foldl foldr)
  • [X] unfold
  • [X] sum
  • [X] product
  • [X] filter

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published