Giter Club home page Giter Club logo

creme's Introduction

Creme

Creme is an implementation of a subset of the Kernel programming language in OCaml.

Requirements

  • OCaml 4.00+

Examples

You can, of course, use Creme in a manner similar to you would with Scheme:

($define! map
  ($lambda (f ls)
    ($if (null? ls)
         ls
         (cons (f (car ls))
               (map f (cdr ls))))))

Which defines an applicative combiner map. An applicative combiner will have its arguments evaluated before being passed to it.

The power of Kernel, however, comes from the $vau operative. An operative does not get its arguments evaluated. Instead, we combine $vau with the eval operative, which allows explicity evaluation of forms. This allows us to define syntax like $cond or $let:

($define! $cond
  ($vau clauses env
    ($define! aux
      ($lambda ((test . body) . clauses)
        ($if (eval test env)
             (apply (wrap $sequence) body env)
             (apply (wrap $cond) clauses env))))
    ($if (null? clauses)
         #inert
         (apply aux clauses))))

This means that unlike in Scheme, where macros aren't first-class, we get something similar to macros as first-class citizens. Neat.

Optimizations

While most of Kernel's features can be bootstrapped from a few primitives, it can lead to performance issues. The biggest performance gain was gotten by rewriting the $sequence operative in OCaml. Further performance gains were gotten by doing the same for $vau and $lambda.

% time ./creme-no-opt tests/tak.crm > /dev/null
./creme-no-opt tests/tak.crm > /dev/null  19.39s user 0.02s system 99% cpu 19.418 total

% time ./creme-opt-seq tests/tak.crm > /dev/null
./creme-opt-seq tests/tak.crm > /dev/null  5.13s user 0.01s system 99% cpu 5.142 total

% time ./creme-opt-seq-vau tests/tak.crm > /dev/null
./creme-opt-seq-vau tests/tak.crm > /dev/null  4.18s user 0.01s system 99% cpu 4.190 total

% time ./creme-opt-seq-vau-lambda tests/tak.crm > /dev/null
./creme-opt-seq-vau-lambda tests/tak.crm > /dev/null  2.39s user 0.01s system 99% cpu 2.394 total

Todo

  • Add #o, #b, #x, #e, #i numerical prefixes
  • Add rational numbers to numerical tower
  • Improve environment support
  • Add to test cases

creme's People

Contributors

sjothen avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.