Skip to content

Instantly share code, notes, and snippets.

@fand
Created November 29, 2013 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fand/7704083 to your computer and use it in GitHub Desktop.
Save fand/7704083 to your computer and use it in GitHub Desktop.
((coffeescriptで) 書く (Lisp) インタプリタ) テスト
#!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