Created
November 29, 2013 10:42
-
-
Save fand/7704083 to your computer and use it in GitHub Desktop.
((coffeescriptで) 書く (Lisp) インタプリタ) テスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!usr/bin/env coffee | |
# coding: utf-8 | |
scheme = require './scheme.coffee' | |
########################## | |
# Tests | |
########################## | |
repl = scheme.repl | |
assert = (a,b) -> if a == b then console.log("ok") else console.log("ng\t a: " + a + "\t b: " + b) | |
repl('(define area (lambda (r) (* 3.141592653 (* r r))))') | |
assert(repl('(area 3)'), 28.274333877) | |
repl('(define fact (lambda (n) (if (<= n 1) 1 (* n (fact (- n 1))))))') | |
assert(repl('(fact 10)'), 3628800) | |
assert(repl('(area (fact 10))'), 4.1369087198e+13) | |
repl('(define first car)') | |
repl('(define rest cdr)') | |
repl('(define count (lambda (item L) (if L (+ (equal? item (first L)) (count item (rest L))) 0)))') | |
repl('(define count (lambda (item L) (if L (+ (equal? item (car L)) (count item (cdr L))) 0)))') | |
assert(repl('(count 0 (list 0 1 2 3 0 0))'), 3) | |
assert(repl('(count (quote the) (quote (the more the merrier the bigger the better)))'), 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment