rename deflocal localVar

This commit is contained in:
2021-07-24 12:53:27 -06:00
parent 12884b4a2d
commit 9c185839ca
10 changed files with 33 additions and 32 deletions

View File

@@ -236,7 +236,7 @@ class Macros {
var uniqueVarSymbol = b.symbol();
b.begin([
b.call(b.symbol("deflocal"), [
b.call(b.symbol("localVar"), [
b.meta("mut", b.typed("Dynamic", uniqueVarSymbol)),
b.symbol("null")
]),
@@ -277,7 +277,7 @@ class Macros {
b.begin([
b.call(
b.symbol("deflocal"), [
b.symbol("localVar"), [
b.meta("mut", b.typed("Dynamic", uniqueVarSymbol)),
b.symbol("null")
]),

View File

@@ -178,9 +178,10 @@ class SpecialForms {
}
map["deflocal"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
wholeExp.checkNumArgs(2, 3, "(deflocal [optional :type] [variable] [optional: &mut] [value])");
wholeExp.checkNumArgs(2, 3, "(localVar [optional :type] [variable] [optional: &mut] [value])");
EVars(toVars(args[0], args[1], k)).withMacroPosOf(wholeExp);
};
renameAndDeprecate("deflocal", "localVar");
map["let"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
wholeExp.checkNumArgs(2, null, "(let [[bindings...]] [body...])");

View File

@@ -174,7 +174,7 @@
(defvar myAnd3 (and 5 false 6))
(defun mySetLocal []
(deflocal &mut loc "one thing")
(localVar &mut loc "one thing")
(set loc "another thing")
loc)
@@ -182,7 +182,7 @@
(defvar myNot2 !5)
(defvar myFilteredList (begin
(deflocal l [-1 -2 5 -3 6])
(localVar l [-1 -2 5 -3 6])
(l.filter (lambda [v] (< 0 v)))))
(defvar myWhen1 (when true 5 6))
@@ -203,7 +203,7 @@
(Assert.equals 10 (last myListOfTen)))
(defun _testListDestructuring []
(deflocal [a b c d &mut e f g h i j] myListOfTen)
(localVar [a b c d &mut e f g h i j] myListOfTen)
(Assert.equals 1 a)
(Assert.equals 2 b)
(Assert.equals 3 c)
@@ -235,7 +235,7 @@
(defvar myMetaList [myListOfTen myListOfTen myListOfTen])
(defun _testDoFor []
(deflocal &mut c 0)
(localVar &mut c 0)
(doFor v myListOfTen
(Assert.equals (+ c 1) v)
(set c v))
@@ -252,7 +252,7 @@
(Assert.equals 10 j)))
(defun _testFor []
(deflocal incrementedList (for v myListOfTen (+ 1 v)))
(localVar incrementedList (for v myListOfTen (+ 1 v)))
(let [[a b c d e f g h i j] incrementedList]
(Assert.equals 2 a)
(Assert.equals 3 b)
@@ -264,7 +264,7 @@
(Assert.equals 9 h)
(Assert.equals 10 i)
(Assert.equals 11 j))
(deflocal smallerMetaList (for [a b c d e f g h i j] myMetaList [a e i]))
(localVar smallerMetaList (for [a b c d e f g h i j] myMetaList [a e i]))
(doFor [a e i] smallerMetaList
(Assert.equals 1 a)
(Assert.equals 5 e)
@@ -276,7 +276,7 @@
(Assert.equals 6 (or c 6))) // (or [optionalVar] [defaultValue]) is the convention for default values
(defun myRestSum [firstOne &rest :List<Int> others]
(deflocal &mut sum firstOne)
(localVar &mut sum firstOne)
(doFor nextOne others (set sum (+ sum nextOne)))
sum)
@@ -285,7 +285,7 @@
(defvar myRest3 (myRestSum 1 2 2))
(defun myCombinedOptRest [firstOne &opt secondOne &rest :List<String> thirdAndMore]
(deflocal &mut concatString (+ firstOne (or secondOne "boop")))
(localVar &mut concatString (+ firstOne (or secondOne "boop")))
(doFor str thirdAndMore (set concatString (+ concatString str)))
concatString)
@@ -376,7 +376,7 @@
(otherwise (Assert.fail))))
(defun _testMaps []
(deflocal :Map<String,String> myMap [=>"hey" "you"
(localVar :Map<String,String> myMap [=>"hey" "you"
=>"found" "me"])
(Assert.equals "you" (dictGet myMap "hey"))
(Assert.equals "me" (dictGet myMap "found"))
@@ -391,7 +391,7 @@
(defun _testRange []
// With just one arg, it's the max:
(deflocal &mut :kiss.List<Int> myList (for i (range 5) i))
(localVar &mut :kiss.List<Int> myList (for i (range 5) i))
(Assert.equals 4 (nth myList -1))
// with two args, they are min and max:
(set myList (for i (range 3 5) i))
@@ -429,9 +429,9 @@
(defvar &mut welcomeCount 0)
(defmacro macroWithLogic [name]
(deflocal message1 (ReaderExp.StrExp "Welcome "))
(deflocal message2 (ReaderExp.StrExp " (Guest #"))
(deflocal message3 (ReaderExp.StrExp ")"))
(localVar message1 (ReaderExp.StrExp "Welcome "))
(localVar message2 (ReaderExp.StrExp " (Guest #"))
(localVar message3 (ReaderExp.StrExp ")"))
`(begin (set welcomeCount (+ welcomeCount 1))
(+ ,message1 ,name ,message2 (Std.string welcomeCount) ,message3)))
@@ -446,7 +446,7 @@
(Assert.equals "you" (dictGet map "hey"))))
(defun _testAssignArith []
(deflocal &mut num 5)
(localVar &mut num 5)
(+= num 5 6)
(Assert.equals 16 num)
(%= num 5)

View File

@@ -1,5 +1,5 @@
(defun myFun []
(deflocal something 5)
(localVar something 5)
)
// This comment used to cause a hard-to-track-down error!

View File

@@ -1,4 +1,4 @@
(defun myFun []
(deflocal something 5)
(localVar something 5)
// This comment used to cause a hard-to-track-down error!
)

View File

@@ -5,7 +5,7 @@
(unless (<= 0 (line.indexOf "contain no other bags"))
(let [[containerStr contents] (line.split "contain ")
contentStrs (contents.split ", ")]
(deflocal :Map<String,Int> innerMap (new Map))
(localVar :Map<String,Int> innerMap (new Map))
(doFor str contentStrs
(let [parts (str.split " ")
quantity (Std.parseInt (parts.shift))
@@ -24,7 +24,7 @@
(defun totalChildBags [bag :ParentMap parentMap]
(if (parentMap.exists bag)
(begin
(deflocal &mut sum 0)
(localVar &mut sum 0)
(doFor =>childColor quantity (dictGet parentMap bag)
(set sum (+ sum quantity (* quantity (totalChildBags childColor parentMap)))))
sum)

View File

@@ -17,7 +17,7 @@
(true fullSeat)))
(defun neighbors [x y :Array<Array<FerrySquare>> grid]
(deflocal &mut n [])
(localVar &mut n [])
(doFor xx (range (- x 1) (+ x 2))
(doFor yy (range (- y 1) (+ y 2))
(unless (and (= x xx) (= y yy))
@@ -28,7 +28,7 @@
(defprop &mut :Array<Array<FerrySquare>> state [])
(defmethod simulate []
(deflocal changed (object changed false))
(localVar changed (object changed false))
(set state
(for rowIdx (range state.length)
(let [:Array<FerrySquare> row (nth state rowIdx)]

View File

@@ -24,7 +24,7 @@
(assert (= 673 (count (map (Util.readLines "src/year2020/inputs/day2-1.txt") (.bind Passwords.validateInputLine _ Passwords.parsePasswordCheck2)) (lambda [v] v)))))
(day 3
(deflocal exampleHillTile [
(localVar exampleHillTile [
"..##......."
"#...#...#.."
".#....#..#."
@@ -55,8 +55,8 @@
(let [:kiss.List<Int> seatIds (map (Util.readLines "src/year2020/inputs/day5-1.txt") Seating.seatId)]
(seatIds.sort (lambda [a b] (- a b)))
(assert (= 947 (nth seatIds -1)))
(deflocal &mut lastId -1)
(deflocal &mut myId -1)
(localVar &mut lastId -1)
(localVar &mut myId -1)
(doFor id seatIds
(when (and (<= 0 lastId) !(= lastId (- id 1)))
(set myId (- id 1))
@@ -71,11 +71,11 @@
(assert (= 3122 (apply + (map (Util.readParagraphLines "src/year2020/inputs/day6-1.txt") Customs.countAllYes)))))
(day 7
(deflocal parentMap (new ParentMap))
(deflocal childMap (new ChildMap))
(localVar parentMap (new ParentMap))
(localVar childMap (new ChildMap))
(doFor line (Util.readLines "src/year2020/inputs/day7.txt")
(Bags.parseRule line parentMap childMap))
(deflocal :Map<String,Bool> shinyGoldParents (new Map))
(localVar :Map<String,Bool> shinyGoldParents (new Map))
(Bags.findIndirectContainers "shiny gold" childMap shinyGoldParents)
(assert (= 172 (count shinyGoldParents)))
(assert (= 39645 (Bags.totalChildBags "shiny gold" parentMap))))

View File

@@ -1,6 +1,6 @@
(defun :kiss.List<Int> pairWithSum [sum :kiss.List<Int> numbers]
// Put the numbers in a map for random access. This gives an O(n) solution
(deflocal :Map<Int,Int> numbersMap (new Map))
(localVar :Map<Int,Int> numbersMap (new Map))
(doFor number numbers
(dictSet numbersMap number (- sum number))
(let [requiredForPair (dictGet numbersMap number)]
@@ -18,7 +18,7 @@
(defun contiguousSumTuple [sum :kiss.List<Int> numbers]
(doFor i (range numbers.length)
(deflocal &mut testSum (nth numbers i))
(localVar &mut testSum (nth numbers i))
(doFor j (range (+ i 1) numbers.length)
(set testSum (+ testSum (nth numbers j)))
(cond

View File

@@ -1,6 +1,6 @@
(defun loadAll [:Array<String> paths :Function callback &opt :Array<PDFDocument> pdfs]
(unless pdfs (set pdfs []))
(deflocal nextPdf (paths.shift))
(localVar nextPdf (paths.shift))
(if (nextPdf.endsWith ".pdf")
(awaitLet [pdf (PDFDocument.load (Fs.readFileSync (print nextPdf)))]
(pdfs.push pdf)