Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rewinfrey/lisp-ruby


https://github.com/rewinfrey/lisp-ruby

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# Let's Make a Lisp!
### A Ruby programming challenge originally created by [Mark Grant](http://github.com/mg50)

### Instructions

#### Checkout the code

```
git clone [email protected]:rewinfrey/lisp_in_ruby.git
cd lisp_in_ruby
```

#### Start the auto test runner

```
./runtest
```

#### Add your solution

Your code should be added to `lisp.rb`.

After you have completed the 10 challenges, compare your solution against a provided solution example in `lisp_solution.rb`.

-----

### Challenge 1

Evaluate numbers and Booleans:

```
lisp_eval("1").should == 1
lisp_eval("#t").should == true
```

### Challenge 2

Evaluate simple addition and multiplication function calls:

```
lisp_eval("(+ 1 2)").should == 3
lisp_eval("(* 2 2 3)").should == 12
```

### Challenge 3

Evaluate nested addition and multiplication calls

```
lisp_eval("(+ 1 (* 2 3))").should == 7
```

### Challenge 4

Evaluate conditionals:

```
lisp_eval("(if #t 1 2)").should == 1
lisp_eval("(if #f #t #f)").should == false
```

### Challenge 5

Evaluate top-level definitions:

```
lisp_eval("(def x 3)
(+ x 1)").should == 4
```

### Challenge 6

Evaluate simple `let` bindings:

```
lisp_eval("(let (x 3)
x)").should == 3
```

### Challenge 7

Evaluate more sophisticated `let` bindings:

```
lisp_eval("(let (x 3)
(+ x 1))").should == 4
```

### Challenge 8

Evaluate `let` bindings with multiple variables:

```
lisp_eval("(let (x 3
y 4)
(+ x y))").should == 7
```

### Challenge 9

Evaluate function definitions:

```
code = "(defn add2 (x)
(+ x 2))

(add2 9)"

lisp_eval(code).should == 1
```

### CHALLENGE 10

Evaluates function definitions with multiple variables:

```
code = "(defn maybeAdd2 (bool x)
(if bool
(+ x 2)
x))

(+ (maybeAdd2 1 #t) (maybeAdd2 1 #f))"

lisp_eval(code).should == 4
```