Coder Social home page Coder Social logo

cppscheme's Introduction

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

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.