diff --git a/fitnesse/FitNesseRoot/LispInterpreter/LexicalClosures.wiki b/fitnesse/FitNesseRoot/LispInterpreter/LexicalClosures.wiki index db70e13..00a89f5 100644 --- a/fitnesse/FitNesseRoot/LispInterpreter/LexicalClosures.wiki +++ b/fitnesse/FitNesseRoot/LispInterpreter/LexicalClosures.wiki @@ -1,39 +1,9 @@ --- Test --- +A simple lexical closure. + | script | lisp interpreter fixture | | show | evaluate | (defun adderx (x) (lambda (y) (+ x y))) | | show | evaluate | (setf adder20 (adderx 20)) | | check | evaluate | (funcall adder20 2) | 22 | - - -| script | lisp interpreter fixture | -| # | Let Over Lambda Over Let Over Lambda | -| show | evaluate |!- - -(let ((direction 'up)) - (defun toggle-counter-direction () - (setq direction - (if (eq direction 'up) - 'down - 'up))) - - (defun counter-class () - (let ((counter 0)) - (lambda () - (if (eq direction 'up) - (setq counter (+ counter 1)) - (setq counter (- counter 1))))))) - -!| -| show | evaluate | (setq my-counter (counter-class)) | -| check | evaluate | (funcall my-counter) | 1 | -| check | evaluate | (funcall my-counter) | 2 | -| check | evaluate | (funcall my-counter) | 3 | -| show | evaluate | (toggle-counter-direction) | -| check | evaluate | (funcall my-counter) | 2 | -| check | evaluate | (funcall my-counter) | 1 | -| check | evaluate | (funcall my-counter) | 0 | -| show | evaluate | (toggle-counter-direction) | -| check | evaluate | (funcall my-counter) | 1 | -| check | evaluate | (funcall my-counter) | 2 | -| check | evaluate | (funcall my-counter) | 3 | \ No newline at end of file diff --git a/fitnesse/FitNesseRoot/LispInterpreter/MultipleMethodClosure.wiki b/fitnesse/FitNesseRoot/LispInterpreter/MultipleMethodClosure.wiki deleted file mode 100644 index 3ec719a..0000000 --- a/fitnesse/FitNesseRoot/LispInterpreter/MultipleMethodClosure.wiki +++ /dev/null @@ -1,95 +0,0 @@ ---- -Test ---- -| script | lisp interpreter fixture | -| # | Object with multiple methods | -| show | evaluate |!- - -(defun counter-class () - (let ((counter 0)) - (lambda (msg) - (case msg - ((:inc) - (setq counter (+ counter 1))) - ((:dec) - (setq counter (- counter 1))))))) - - -!| -| show | evaluate | (setq my-counter (counter-class)) | -| check | evaluate | (funcall my-counter :inc) | 1 | -| check | evaluate | (funcall my-counter :inc) | 2 | -| check | evaluate | (funcall my-counter :inc) | 3 | -| check | evaluate | (funcall my-counter :dec) | 2 | -| check | evaluate | (funcall my-counter :dec) | 1 | -| check | evaluate | (funcall my-counter :dec) | 0 | - - -| script | lisp interpreter fixture | -| # | dlambda | -| show | evaluate |!- - -(defun map (fn ls) - (if (null ls) - () - (cons (funcall fn (first ls)) - (map fn (rest ls)) - ) - ) -) - -(define-macro dlambda (&rest methods) - (cons - (quote lambda) - (cons - (quote (&rest arguments)) - (list - (cons - (quote case) - (cons - (quote (first arguments)) - (map - (lambda (method) - (cons - (first method) - (list - (cons - (quote apply) - (cons - (cons - (quote lambda) - (rest method) - ) - (list (quote (rest arguments))) - ) - ) - ) - ) - ) - methods - ) - ) - ) - ) - ) - ) -) - -(defun apple-counter () - (let ((apple-count 0)) - (eval - (dlambda - (:inc () (setf apple-count (+ apple-count 1))) - (:dec () (setf apple-count (- apple-count 1))) - ) - ) - ) -) - -!| -| show | evaluate | (setf a (apple-counter)) | -| check | evaluate | (funcall a :inc) | 1 | -| check | evaluate | (funcall a :inc) | 2 | -| check | evaluate | (funcall a :inc) | 3 | -| check | evaluate | (funcall a :dec) | 2 | -| check | evaluate | (funcall a :dec) | 1 | -| check | evaluate | (funcall a :dec) | 0 | -| show | evaluate | (funcall a :inc 1) | diff --git a/fitnesse/FitNesseRoot/LispInterpreter/MultipleMethodObject.wiki b/fitnesse/FitNesseRoot/LispInterpreter/MultipleMethodObject.wiki new file mode 100644 index 0000000..38a1828 --- /dev/null +++ b/fitnesse/FitNesseRoot/LispInterpreter/MultipleMethodObject.wiki @@ -0,0 +1,25 @@ +--- +Test +--- +An object with multiple methods. + +| script | lisp interpreter fixture | +| show | evaluate |!- + +(defun counter-class () + (let ((counter 0)) + (lambda (msg) + (case msg + ((:inc) + (setq counter (+ counter 1))) + ((:dec) + (setq counter (- counter 1))))))) + + -!| +| show | evaluate | (setq my-counter (counter-class)) | +| check | evaluate | (funcall my-counter :inc) | 1 | +| check | evaluate | (funcall my-counter :inc) | 2 | +| check | evaluate | (funcall my-counter :inc) | 3 | +| check | evaluate | (funcall my-counter :dec) | 2 | +| check | evaluate | (funcall my-counter :dec) | 1 | +| check | evaluate | (funcall my-counter :dec) | 0 | diff --git a/fitnesse/FitNesseRoot/LispInterpreter/ObjectComposition.wiki b/fitnesse/FitNesseRoot/LispInterpreter/ObjectComposition.wiki new file mode 100644 index 0000000..0ca7492 --- /dev/null +++ b/fitnesse/FitNesseRoot/LispInterpreter/ObjectComposition.wiki @@ -0,0 +1,14 @@ +--- +Test +--- +Shows object composition, a default method, and two different ways of referencing objects. + +| script | lisp interpreter fixture | +| show | evaluate | (load "../lisp/dlambda.lisp") | +| show | evaluate | (load "../lisp/fruit-counter.lisp") | +| check | evaluate | (my-counter :inc-apples) | 1 | +| check | evaluate | (my-counter :inc-apples) | 2 | +| check | evaluate | (funcall my-counter2 :dec-bananas) | 9999 | +| check | evaluate | (my-counter :set-coconuts 12) | 12 | +| check | evaluate | (my-counter) |(APPLES 2 BANANAS 0 COCONUTS 12) | +| check | evaluate | (funcall my-counter2) |(APPLES 10000 BANANAS 9999 COCONUTS 10000) | \ No newline at end of file diff --git a/fitnesse/FitNesseRoot/LispInterpreter/StaticVariable.wiki b/fitnesse/FitNesseRoot/LispInterpreter/StaticVariable.wiki new file mode 100644 index 0000000..84c4804 --- /dev/null +++ b/fitnesse/FitNesseRoot/LispInterpreter/StaticVariable.wiki @@ -0,0 +1,35 @@ +--- +Test +--- +Shows the usage of a static variable. +''"Let Over Lambda Over Let Over Lambda"'' + +| script | lisp interpreter fixture | +| show | evaluate | !- + +(let ((direction 'up)) + (defun toggle-counter-direction () + (setq direction + (if (eq direction 'up) + 'down + 'up))) + +(defun counter-class () + (let ((counter 0)) + (lambda () + (if (eq direction 'up) + (setq counter (+ counter 1)) + (setq counter (- counter 1))))))) + -!| +| show | evaluate | (setq my-counter (counter-class)) | +| check | evaluate | (funcall my-counter) | 1 | +| check | evaluate | (funcall my-counter) | 2 | +| check | evaluate | (funcall my-counter) | 3 | +| show | evaluate | (toggle-counter-direction) | +| check | evaluate | (funcall my-counter) | 2 | +| check | evaluate | (funcall my-counter) | 1 | +| check | evaluate | (funcall my-counter) | 0 | +| show | evaluate | (toggle-counter-direction) | +| check | evaluate | (funcall my-counter) | 1 | +| check | evaluate | (funcall my-counter) | 2 | +| check | evaluate | (funcall my-counter) | 3 | diff --git a/fitnesse/FitNesseRoot/RecentChanges.wiki b/fitnesse/FitNesseRoot/RecentChanges.wiki index ede3c2c..9310805 100644 --- a/fitnesse/FitNesseRoot/RecentChanges.wiki +++ b/fitnesse/FitNesseRoot/RecentChanges.wiki @@ -1,6 +1,9 @@ +|LispInterpreter.LexicalClosures||16:31:40 Thu, Mar 02, 2017| +|LispInterpreter.LexicalClosure||16:26:49 Thu, Mar 02, 2017| +|LispInterpreter.FruitCounter||16:13:51 Thu, Mar 02, 2017| +|LispInterpreter.SimpleClosure||16:12:31 Thu, Mar 02, 2017| +|LispInterpreter.MultipleMethodClosure||16:11:28 Thu, Mar 02, 2017| |LispInterpreter.SetUp||15:09:12 Thu, Mar 02, 2017| -|LispInterpreter.MultipleMethodClosure||16:02:22 Wed, Mar 01, 2017| -|LispInterpreter.LexicalClosures||12:10:13 Mon, Feb 27, 2017| |LispInterpreter.TestClosure||11:24:27 Mon, Feb 27, 2017| |LispInterpreter.TestOne||09:26:08 Fri, Feb 24, 2017| |LispInterpreter.SuiteSetUp||14:27:52 Wed, Feb 22, 2017| diff --git a/test/acceptance/FitNesseRunnerTester.java b/test/acceptance/AcceptanceTester.java similarity index 87% rename from test/acceptance/FitNesseRunnerTester.java rename to test/acceptance/AcceptanceTester.java index 49c3426..2d1f622 100644 --- a/test/acceptance/FitNesseRunnerTester.java +++ b/test/acceptance/AcceptanceTester.java @@ -8,4 +8,4 @@ import fitnesse.junit.FitNesseRunner; @FitNesseRunner.Suite("LispInterpreter") @FitNesseRunner.FitnesseDir("fitnesse") @FitNesseRunner.OutputDir("fitnesse/fitnesse-results") -public class FitNesseRunnerTester {} +public class AcceptanceTester {}