From 87eb0204f5534a70eaa82269bf11f72a0802af92 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Tue, 7 Mar 2017 16:41:26 -0500 Subject: [PATCH] Remove SETF function --- fitnesse/FitNesseRoot/RecentChanges.wiki | 1 + .../TranscendentalLisp/LexicalClosures.wiki | 2 +- lisp/random/problem.lisp | 4 +- lisp/random/roman.lisp | 2 +- .../builtin/special/{SETF.java => SETQ.java} | 6 +-- src/table/FunctionTable.java | 2 +- test/function/builtin/predicate/EQTester.java | 4 +- test/function/builtin/special/ANDTester.java | 2 +- test/function/builtin/special/CASETester.java | 8 ++-- .../builtin/special/DEFINE_SPECIALTester.java | 4 +- .../function/builtin/special/DEFUNTester.java | 4 +- test/function/builtin/special/IFTester.java | 4 +- .../builtin/special/LAMBDATester.java | 2 +- test/function/builtin/special/LETTester.java | 14 +++---- .../builtin/special/LET_STARTester.java | 14 +++---- test/function/builtin/special/ORTester.java | 2 +- .../{SETFTester.java => SETQTester.java} | 42 ++++++++----------- test/parser/LispParserTester.java | 2 +- 18 files changed, 57 insertions(+), 62 deletions(-) rename src/function/builtin/special/{SETF.java => SETQ.java} (88%) rename test/function/builtin/special/{SETFTester.java => SETQTester.java} (72%) diff --git a/fitnesse/FitNesseRoot/RecentChanges.wiki b/fitnesse/FitNesseRoot/RecentChanges.wiki index 3e69b01..2e1d183 100644 --- a/fitnesse/FitNesseRoot/RecentChanges.wiki +++ b/fitnesse/FitNesseRoot/RecentChanges.wiki @@ -1,3 +1,4 @@ +|TranscendentalLisp.LexicalClosures||16:39:59 Tue, Mar 07, 2017| |FrontPage||10:19:45 Tue, Mar 07, 2017| |TranscendentalLisp||10:14:02 Tue, Mar 07, 2017| |LispInterpreter.MultipleMethodObject||16:50:19 Mon, Mar 06, 2017| diff --git a/fitnesse/FitNesseRoot/TranscendentalLisp/LexicalClosures.wiki b/fitnesse/FitNesseRoot/TranscendentalLisp/LexicalClosures.wiki index 0dda92f..7ef7de9 100644 --- a/fitnesse/FitNesseRoot/TranscendentalLisp/LexicalClosures.wiki +++ b/fitnesse/FitNesseRoot/TranscendentalLisp/LexicalClosures.wiki @@ -5,5 +5,5 @@ A simple lexical closure. | script | lisp interpreter fixture | | show | evaluate text | (defun adder-x (x) (lambda (y) (+ x y))) | -| show | evaluate text | (setf adder-20 (adder-x 20)) | +| show | evaluate text | (setq adder-20 (adder-x 20)) | | check | evaluate text | (funcall adder-20 2) | 22 | diff --git a/lisp/random/problem.lisp b/lisp/random/problem.lisp index 4073e00..e297504 100644 --- a/lisp/random/problem.lisp +++ b/lisp/random/problem.lisp @@ -2,5 +2,5 @@ (if (< n 1) nil (cons n (problem (- n 1))))) -(setf y (problem 20)) -(setf x (problem 20000)) +(setq y (problem 20)) +(setq x (problem 20000)) diff --git a/lisp/random/roman.lisp b/lisp/random/roman.lisp index 7f82f2b..5ab0691 100644 --- a/lisp/random/roman.lisp +++ b/lisp/random/roman.lisp @@ -1,5 +1,5 @@ ;; A list containing the values of single-letter Roman numerals. -(setf roman-number-list +(setq roman-number-list '((I 1) (V 5) (X 10) (L 50) (C 100) (D 500) (M 1000))) ;; Converts a single Roman numeral letter into its equivalent decimal value. diff --git a/src/function/builtin/special/SETF.java b/src/function/builtin/special/SETQ.java similarity index 88% rename from src/function/builtin/special/SETF.java rename to src/function/builtin/special/SETQ.java index ed16e95..7793a2e 100644 --- a/src/function/builtin/special/SETF.java +++ b/src/function/builtin/special/SETQ.java @@ -7,12 +7,12 @@ import static function.builtin.cons.LIST.makeList; import function.*; import sexpression.*; -@FunctionNames({ "SETF", "SETQ" }) -public class SETF extends LispSpecialFunction { +@FunctionNames({ "SETQ" }) +public class SETQ extends LispSpecialFunction { private ArgumentValidator argumentValidator; - public SETF(String name) { + public SETQ(String name) { this.argumentValidator = new ArgumentValidator(name); this.argumentValidator.setExactNumberOfArguments(2); this.argumentValidator.setFirstArgumentExpectedType(Symbol.class); diff --git a/src/table/FunctionTable.java b/src/table/FunctionTable.java index acd84c0..6768295 100644 --- a/src/table/FunctionTable.java +++ b/src/table/FunctionTable.java @@ -52,7 +52,7 @@ public class FunctionTable { allBuiltIns.add(QUOTE.class); allBuiltIns.add(REST.class); allBuiltIns.add(SET.class); - allBuiltIns.add(SETF.class); + allBuiltIns.add(SETQ.class); allBuiltIns.add(SYMBOL_FUNCTION.class); } diff --git a/test/function/builtin/predicate/EQTester.java b/test/function/builtin/predicate/EQTester.java index f81af2e..f3678fe 100644 --- a/test/function/builtin/predicate/EQTester.java +++ b/test/function/builtin/predicate/EQTester.java @@ -74,8 +74,8 @@ public class EQTester { @Test public void eqWithSameList() { - String initializeL1 = "(setf l1 '(1 2 3))"; - String initializeL2 = "(setf l2 l1)"; + String initializeL1 = "(setq l1 '(1 2 3))"; + String initializeL2 = "(setq l2 l1)"; String input = "(eq l1 l2)"; evaluateString(initializeL1); diff --git a/test/function/builtin/special/ANDTester.java b/test/function/builtin/special/ANDTester.java index 429d29c..11fe4b4 100644 --- a/test/function/builtin/special/ANDTester.java +++ b/test/function/builtin/special/ANDTester.java @@ -71,7 +71,7 @@ public class ANDTester { @Test(expected = UndefinedSymbolException.class) public void andShortCircuits() { - String input = "(and nil (setf x 22))"; + String input = "(and nil (setq x 22))"; assertNil(evaluateString(input)); evaluateString("x"); diff --git a/test/function/builtin/special/CASETester.java b/test/function/builtin/special/CASETester.java index 8ddc54e..7344b70 100644 --- a/test/function/builtin/special/CASETester.java +++ b/test/function/builtin/special/CASETester.java @@ -160,7 +160,7 @@ public class CASETester { @Test public void caseEvaluatesMultipleConsequents() { - String input = "(case 2 (1 1) (2 (setf x 'x) (setf y 'y)) (3 3)))"; + String input = "(case 2 (1 1) (2 (setq x 'x) (setq y 'y)) (3 3)))"; evaluateString(input); @@ -177,10 +177,10 @@ public class CASETester { @Test public void caseOnlyEvaluatesConsequentInFirstMatchingClause() { - String input = "(case 2 ((0) (setf zero 0)) ((1) (setf one 1)) ((2) (setf two '2)) ((2) (setf two 'two)))"; + String input = "(case 2 ((0) (setq zero 0)) ((1) (setq one 1)) ((2) (setq two '2)) ((2) (setq two 'two)))"; - evaluateString("(setf zero nil)"); - evaluateString("(setf one nil)"); + evaluateString("(setq zero nil)"); + evaluateString("(setq one nil)"); evaluateString(input); assertSExpressionsMatch(parseString("nil"), evaluateString("zero")); diff --git a/test/function/builtin/special/DEFINE_SPECIALTester.java b/test/function/builtin/special/DEFINE_SPECIALTester.java index 0ff1dea..ae8d809 100644 --- a/test/function/builtin/special/DEFINE_SPECIALTester.java +++ b/test/function/builtin/special/DEFINE_SPECIALTester.java @@ -80,7 +80,7 @@ public class DEFINE_SPECIALTester { @Test public void defineSpecialVariableCapture() { - evaluateString("(setf x 0)"); + evaluateString("(setq x 0)"); evaluateString("(define-special f (x) (set x 23))"); evaluateString("(f x)"); assertSExpressionsMatch(parseString("0"), evaluateString("x")); @@ -88,7 +88,7 @@ public class DEFINE_SPECIALTester { @Test public void defineSpecialAvoidVariableCaptureConvention() { - evaluateString("(setf x 0)"); + evaluateString("(setq x 0)"); evaluateString("(define-special f (-x-) (set -x- 23))"); evaluateString("(f x)"); assertSExpressionsMatch(parseString("23"), evaluateString("x")); diff --git a/test/function/builtin/special/DEFUNTester.java b/test/function/builtin/special/DEFUNTester.java index 8423b2b..142a87c 100644 --- a/test/function/builtin/special/DEFUNTester.java +++ b/test/function/builtin/special/DEFUNTester.java @@ -79,8 +79,8 @@ public class DEFUNTester { @Test public void defunSimpleClass() { - evaluateString("(defun counter-class () (let ((counter 0)) (lambda () (setf counter (+ 1 counter)))))"); - evaluateString("(setf my-counter (counter-class))"); + evaluateString("(defun counter-class () (let ((counter 0)) (lambda () (setq counter (+ 1 counter)))))"); + evaluateString("(setq my-counter (counter-class))"); assertSExpressionsMatch(parseString("1"), evaluateString("(funcall my-counter)")); assertSExpressionsMatch(parseString("2"), evaluateString("(funcall my-counter)")); diff --git a/test/function/builtin/special/IFTester.java b/test/function/builtin/special/IFTester.java index 03179a4..0dbbf65 100644 --- a/test/function/builtin/special/IFTester.java +++ b/test/function/builtin/special/IFTester.java @@ -64,7 +64,7 @@ public class IFTester { @Test(expected = UndefinedSymbolException.class) public void ifWithNilCondition_DoesNotEvaluateThenForm() { - String input = "(if nil (setf x 22))"; + String input = "(if nil (setq x 22))"; assertNil(evaluateString(input)); evaluateString("x"); @@ -72,7 +72,7 @@ public class IFTester { @Test(expected = UndefinedSymbolException.class) public void ifWithTrueCondition_DoesNotEvaluateElseForm() { - String input = "(if t nil (setf x 22))"; + String input = "(if t nil (setq x 22))"; assertNil(evaluateString(input)); evaluateString("x"); diff --git a/test/function/builtin/special/LAMBDATester.java b/test/function/builtin/special/LAMBDATester.java index 5183048..c3ab9f0 100644 --- a/test/function/builtin/special/LAMBDATester.java +++ b/test/function/builtin/special/LAMBDATester.java @@ -111,7 +111,7 @@ public class LAMBDATester { @Test public void lexicalClosure() { - evaluateString("(setf increment-count (let ((counter 0)) (lambda () (setf counter (+ 1 counter)))))"); + evaluateString("(setq increment-count (let ((counter 0)) (lambda () (setq counter (+ 1 counter)))))"); assertSExpressionsMatch(parseString("1"), evaluateString("(funcall increment-count)")); assertSExpressionsMatch(parseString("2"), evaluateString("(funcall increment-count)")); diff --git a/test/function/builtin/special/LETTester.java b/test/function/builtin/special/LETTester.java index ae8f852..e3269ba 100644 --- a/test/function/builtin/special/LETTester.java +++ b/test/function/builtin/special/LETTester.java @@ -51,7 +51,7 @@ public class LETTester { @Test public void letWithSetf_DoesNotAlterGlobalVariable() { - String before = "(setf x 22)"; + String before = "(setq x 22)"; String input = "(let ((x 1)) x)"; String after = "x"; @@ -62,8 +62,8 @@ public class LETTester { @Test public void letWithNestedSetf_DoesNotAlterGlobalVariable() { - String before = "(setf x 22)"; - String input = "(let ((x 33)) (setf x 44) x)"; + String before = "(setq x 22)"; + String input = "(let ((x 33)) (setq x 44) x)"; String after = "x"; assertSExpressionsMatch(new LispNumber("22"), evaluateString(before)); @@ -80,7 +80,7 @@ public class LETTester { @Test public void nestedLetWithGlobals() { - String before = "(setf x 92)"; + String before = "(setq x 92)"; String input = "(let ((x 1)) (let ((y (+ 1 x))) y))"; String after = "x"; @@ -91,8 +91,8 @@ public class LETTester { @Test public void alterGlobalVariableFromLet() { - String before = "(setf x 1)"; - String input = "(let ((y 1)) (setf x 2))"; + String before = "(setq x 1)"; + String input = "(let ((y 1)) (setq x 2))"; String after = "x"; assertSExpressionsMatch(new LispNumber("1"), evaluateString(before)); @@ -102,7 +102,7 @@ public class LETTester { @Test public void accessGlobalVariableFromLet() { - String before = "(setf x 1)"; + String before = "(setq x 1)"; String input = "(let () x)"; assertSExpressionsMatch(new LispNumber("1"), evaluateString(before)); diff --git a/test/function/builtin/special/LET_STARTester.java b/test/function/builtin/special/LET_STARTester.java index baa4262..7a6911c 100644 --- a/test/function/builtin/special/LET_STARTester.java +++ b/test/function/builtin/special/LET_STARTester.java @@ -51,7 +51,7 @@ public class LET_STARTester { @Test public void letStarWithSetf_DoesNotAlterGlobalVariable() { - String before = "(setf x 22)"; + String before = "(setq x 22)"; String input = "(let* ((x 1)) x)"; String after = "x"; @@ -62,8 +62,8 @@ public class LET_STARTester { @Test public void letStarWithNestedSetf_DoesNotAlterGlobalVariable() { - String before = "(setf x 22)"; - String input = "(let* ((x 33)) (setf x 44) x)"; + String before = "(setq x 22)"; + String input = "(let* ((x 33)) (setq x 44) x)"; String after = "x"; assertSExpressionsMatch(new LispNumber("22"), evaluateString(before)); @@ -80,7 +80,7 @@ public class LET_STARTester { @Test public void nestedLetWithGlobals() { - String before = "(setf x 92)"; + String before = "(setq x 92)"; String input = "(let* ((x 1)) (let* ((y (+ 1 x))) y))"; String after = "x"; @@ -91,8 +91,8 @@ public class LET_STARTester { @Test public void alterGlobalVariableFromLet() { - String before = "(setf x 1)"; - String input = "(let* ((y 1)) (setf x 2))"; + String before = "(setq x 1)"; + String input = "(let* ((y 1)) (setq x 2))"; String after = "x"; assertSExpressionsMatch(new LispNumber("1"), evaluateString(before)); @@ -102,7 +102,7 @@ public class LET_STARTester { @Test public void accessGlobalVariableFromLet() { - String before = "(setf x 1)"; + String before = "(setq x 1)"; String input = "(let* () x)"; assertSExpressionsMatch(new LispNumber("1"), evaluateString(before)); diff --git a/test/function/builtin/special/ORTester.java b/test/function/builtin/special/ORTester.java index c3fc266..44aac42 100644 --- a/test/function/builtin/special/ORTester.java +++ b/test/function/builtin/special/ORTester.java @@ -71,7 +71,7 @@ public class ORTester { @Test(expected = UndefinedSymbolException.class) public void orShortCircuits() { - String input = "(or t (setf x 22))"; + String input = "(or t (setq x 22))"; assertT(evaluateString(input)); evaluateString("x"); diff --git a/test/function/builtin/special/SETFTester.java b/test/function/builtin/special/SETQTester.java similarity index 72% rename from test/function/builtin/special/SETFTester.java rename to test/function/builtin/special/SETQTester.java index ca0231a..30561e3 100644 --- a/test/function/builtin/special/SETFTester.java +++ b/test/function/builtin/special/SETQTester.java @@ -10,11 +10,11 @@ import function.builtin.EVAL.UndefinedSymbolException; import sexpression.LispNumber; import table.*; -public class SETFTester { +public class SETQTester { private ExecutionContext executionContext; - public SETFTester() { + public SETQTester() { this.executionContext = ExecutionContext.getInstance(); } @@ -28,12 +28,6 @@ public class SETFTester { executionContext.clearContext(); } - @Test - public void setf() { - evaluateString("(setf a 23)"); - assertSExpressionsMatch(new LispNumber("23"), evaluateString("a")); - } - @Test public void setq() { evaluateString("(setq a 23)"); @@ -42,7 +36,7 @@ public class SETFTester { @Test public void lookupDefinedSymbol() { - evaluateString("(setf a 23)"); + evaluateString("(setq a 23)"); assertSExpressionsMatch(new LispNumber("23"), executionContext.lookupSymbolValue("A")); } @@ -52,63 +46,63 @@ public class SETFTester { } @Test - public void setfGlobalVariable() { - evaluateString("(setf a 23)"); + public void setqGlobalVariable() { + evaluateString("(setq a 23)"); SymbolTable global = executionContext.getScope(); executionContext.setScope(new SymbolTable(global)); - evaluateString("(setf a 94)"); + evaluateString("(setq a 94)"); executionContext.setScope(global); assertSExpressionsMatch(new LispNumber("94"), evaluateString("a")); } @Test - public void setfLocalVariable() { + public void setqLocalVariable() { SymbolTable global = executionContext.getScope(); SymbolTable local = new SymbolTable(global); local.put("A", new LispNumber("99")); executionContext.setScope(local); - evaluateString("(setf a 94)"); + evaluateString("(setq a 94)"); assertSExpressionsMatch(new LispNumber("94"), evaluateString("a")); } @Test(expected = UndefinedSymbolException.class) - public void setfLocalVariableDefined_DoesNotSetGlobal() { + public void setqLocalVariableDefined_DoesNotSetGlobal() { SymbolTable global = executionContext.getScope(); SymbolTable local = new SymbolTable(global); local.put("A", new LispNumber("99")); executionContext.setScope(local); - evaluateString("(setf a 94)"); + evaluateString("(setq a 94)"); executionContext.setScope(global); evaluateString("a"); } @Test - public void setfLocalVariableUndefined_SetsGlobal() { + public void setqLocalVariableUndefined_SetsGlobal() { SymbolTable global = executionContext.getScope(); SymbolTable local = new SymbolTable(global); executionContext.setScope(local); - evaluateString("(setf a 94)"); + evaluateString("(setq a 94)"); executionContext.setScope(global); assertSExpressionsMatch(new LispNumber("94"), evaluateString("a")); } @Test(expected = BadArgumentTypeException.class) - public void setfWithNonSymbol() { - evaluateString("(setf 1 2)"); + public void setqWithNonSymbol() { + evaluateString("(setq 1 2)"); } @Test(expected = TooFewArgumentsException.class) - public void setfWithTooFewArguments() { - evaluateString("(setf x)"); + public void setqWithTooFewArguments() { + evaluateString("(setq x)"); } @Test(expected = TooManyArgumentsException.class) - public void setfWithTooManyArguments() { - evaluateString("(setf a b c)"); + public void setqWithTooManyArguments() { + evaluateString("(setq a b c)"); } } diff --git a/test/parser/LispParserTester.java b/test/parser/LispParserTester.java index ebe27ce..92e76f6 100644 --- a/test/parser/LispParserTester.java +++ b/test/parser/LispParserTester.java @@ -150,7 +150,7 @@ public class LispParserTester { @Test public void givenMultipleExpressions_CreatesCorrectSExpressions() { - String input = "(setf x 2) x \"hi\" () 29"; + String input = "(setq x 2) x \"hi\" () 29"; LispParser parser = createLispParser(input); assertList(parser.getNextSExpression());