Coder Social home page Coder Social logo

rusche's Introduction

#Rusche

##Introduction

Rusche is a Ruby-to-Scheme transcompiler. It is pronounced "ROO-skee".

The following are supported features:

  • Conditionals, converted from &&, || format to (and a b), (or a b).
  • Constants defined using either functions or the const construct.
  • Conditional branches, converted from if elsif else format to cond.
  • Math expressions, converted from a + b format to (+ a b).
  • n-level deep nesting of conditions, expressions, and function calls.

Rusche doesn't support all features of either language. It can only transcompile a small, restricted subset of Ruby. These restrictions are:

  • No state variables (thus no mutation).
  • All code must be contained within one module.
  • All code must be within instance methods of that one module.
  • Most Ruby standard library functions cannot be transcompiled. Exceptions are: Array.push => cons val List
  • All method definitions must contain only one expression. Any expressions after the first are ignored.

##Requirements

##Examples

###General Test

module ToCC
  SOME_CONST = 5
  MY_CONSTANT = (SOME_CONST * (3 - SOME_CONST)) / 72

  def testme
    sleep
  end

  def othertest(myp)
    ham(MY_CONSTANT, sandwich(SOME_CONST, myp))
  end

  def test
    if a > 3
      1
    elsif b < 2
      2
    else
      3
    end
  end

  def dat_shit_cray
    if ((5 && 2 && 3) || 7) && !9
      8
    else
      5
    end
  end
end
(define (SOME_CONST 5))

(define (MY_CONSTANT (/ (* SOME_CONST (- 3 SOME_CONST)) 72)))

(define (testme)
  (sleep))

(define (othertest myp)
  (ham MY_CONSTANT (sandwich SOME_CONST myp)))

(define (test)
  (cond
    [(> (a) 3) 1]
    [(< (b) 2) 2]
    [else (3)]))

(define (dat_shit_cray)
  (cond
    [(and (or (and 5 (and 2 3)) 7) (not 9)) 8]
    [else (5)]))

Fibonacci (Unoptimized)

module Fibonacci
  def fib(n)
    if n == 0
      0
    elsif n == 1
      1
    else
      fib(n - 1) + fib(n - 2)
    end
  end
end
(define (fib n)
  (cond
    [(= n 0) 0]
    [(= n 1) 1]
    [else (+ (fib (- n 1)) (fib (- n 2)))]))

##How to Use

Some tests are included in this repo. The main code is in rusche.rb. To run: ruby rusche.rb

To select a different file to transcompile (defaults to test.rb), edit the source near the bottom.

rusche's People

Contributors

douglassherk avatar

Stargazers

 avatar

Watchers

 avatar  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.