trackler 2.2.1.69 → 2.2.1.70

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/problem-specifications/exercises/isbn-verifier/description.md +25 -20
  4. data/tracks/c/bin/run-tests +1 -2
  5. data/tracks/c/exercises/acronym/makefile +10 -0
  6. data/tracks/c/exercises/all-your-base/makefile +10 -0
  7. data/tracks/c/exercises/allergies/makefile +10 -0
  8. data/tracks/c/exercises/anagram/makefile +9 -0
  9. data/tracks/c/exercises/atbash-cipher/makefile +9 -0
  10. data/tracks/c/exercises/beer-song/makefile +9 -0
  11. data/tracks/c/exercises/binary/makefile +9 -0
  12. data/tracks/c/exercises/binary-search/makefile +9 -0
  13. data/tracks/c/exercises/bob/makefile +9 -0
  14. data/tracks/c/exercises/clock/makefile +9 -0
  15. data/tracks/c/exercises/collatz-conjecture/makefile +10 -0
  16. data/tracks/c/exercises/difference-of-squares/makefile +9 -0
  17. data/tracks/c/exercises/gigasecond/makefile +9 -0
  18. data/tracks/c/exercises/grains/makefile +9 -0
  19. data/tracks/c/exercises/hamming/makefile +9 -0
  20. data/tracks/c/exercises/isogram/makefile +10 -0
  21. data/tracks/c/exercises/largest-series-product/makefile +9 -0
  22. data/tracks/c/exercises/leap/makefile +9 -0
  23. data/tracks/c/exercises/meetup/makefile +10 -0
  24. data/tracks/c/exercises/nth-prime/makefile +9 -0
  25. data/tracks/c/exercises/nucleotide-count/makefile +10 -0
  26. data/tracks/c/exercises/palindrome-products/makefile +9 -0
  27. data/tracks/c/exercises/pangram/makefile +9 -0
  28. data/tracks/c/exercises/pascals-triangle/makefile +9 -0
  29. data/tracks/c/exercises/perfect-numbers/makefile +8 -0
  30. data/tracks/c/exercises/phone-number/makefile +9 -0
  31. data/tracks/c/exercises/queen-attack/makefile +10 -0
  32. data/tracks/c/exercises/raindrops/makefile +9 -0
  33. data/tracks/c/exercises/react/makefile +9 -0
  34. data/tracks/c/exercises/rna-transcription/makefile +10 -0
  35. data/tracks/c/exercises/robot-simulator/makefile +9 -0
  36. data/tracks/c/exercises/roman-numerals/makefile +9 -0
  37. data/tracks/c/exercises/scrabble-score/makefile +9 -0
  38. data/tracks/c/exercises/series/makefile +9 -0
  39. data/tracks/c/exercises/sieve/makefile +10 -0
  40. data/tracks/c/exercises/space-age/makefile +9 -0
  41. data/tracks/c/exercises/sublist/makefile +10 -0
  42. data/tracks/c/exercises/sum-of-multiples/makefile +10 -0
  43. data/tracks/c/exercises/triangle/makefile +9 -0
  44. data/tracks/c/exercises/word-count/makefile +9 -0
  45. data/tracks/delphi/config.json +10 -0
  46. data/tracks/delphi/exercises/reverse-string/README.md +34 -0
  47. data/tracks/delphi/exercises/reverse-string/ReverseString.dpr +60 -0
  48. data/tracks/delphi/exercises/reverse-string/uReverseStringExample.pas +18 -0
  49. data/tracks/delphi/exercises/reverse-string/uReverseStringTests.pas +69 -0
  50. data/tracks/fsharp/exercises/forth/Example.fs +29 -25
  51. data/tracks/fsharp/exercises/forth/ForthTest.fs +190 -74
  52. data/tracks/fsharp/exercises/markdown/MarkdownTest.fs +6 -3
  53. data/tracks/fsharp/generators/Exercise.fs +4 -4
  54. data/tracks/fsharp/generators/Generators.fs +29 -1
  55. data/tracks/java/exercises/allergies/.meta/src/reference/java/Allergen.java +2 -2
  56. data/tracks/java/exercises/allergies/.meta/src/reference/java/Allergies.java +4 -4
  57. data/tracks/java/exercises/allergies/src/main/java/Allergen.java +2 -2
  58. data/tracks/java/exercises/anagram/.meta/src/reference/java/Anagram.java +5 -5
  59. data/tracks/java/exercises/bob/.meta/src/reference/java/Bob.java +8 -5
  60. data/tracks/java/exercises/kindergarten-garden/src/main/java/KindergartenGarden.java +17 -0
  61. data/tracks/java/exercises/nth-prime/src/main/java/PrimeCalculator.java +7 -0
  62. data/tracks/java/exercises/rotational-cipher/src/main/java/RotationalCipher.java +11 -0
  63. data/tracks/javascript/config.json +15 -0
  64. data/tracks/javascript/exercises/connect/README.md +59 -0
  65. data/tracks/javascript/exercises/connect/connect.spec.js +108 -0
  66. data/tracks/javascript/exercises/connect/example.js +105 -0
  67. data/tracks/kotlin/README.md +1 -1
  68. data/tracks/kotlin/exercises/hello-world/TUTORIAL.md +2 -2
  69. metadata +12 -6
  70. data/tracks/java/exercises/book-store/.meta/src/reference/java/.keep +0 -0
  71. data/tracks/java/exercises/nth-prime/src/main/java/.keep +0 -0
  72. data/tracks/java/exercises/rotational-cipher/src/main/java/.keep +0 -0
  73. data/tracks/javascript/package-lock.json +0 -1895
@@ -1,13 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
7
12
 
8
13
  test: tests.out
9
14
  @./tests.out
10
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
11
20
  clean:
12
21
  rm -f *.o *.out
13
22
 
@@ -1,12 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
12
+
7
13
  test: tests.out
8
14
  @./tests.out
9
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
10
20
  clean:
11
21
  rm -f *.o *.out
12
22
 
@@ -1,13 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
7
12
 
8
13
  test: tests.out
9
14
  @./tests.out
10
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
11
20
  clean:
12
21
  rm -f *.o *.out
13
22
 
@@ -1,13 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
7
12
 
8
13
  test: tests.out
9
14
  @./tests.out
10
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
11
20
  clean:
12
21
  rm -f *.o *.out
13
22
 
@@ -1,12 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
12
+
7
13
  test: tests.out
8
14
  @./tests.out
9
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
10
20
  clean:
11
21
  rm -f *.o *.out
12
22
 
@@ -1,13 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
7
12
 
8
13
  test: tests.out
9
14
  @./tests.out
10
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
11
20
  clean:
12
21
  rm -f *.o *.out
13
22
 
@@ -1,13 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
7
12
 
8
13
  test: tests.out
9
14
  @./tests.out
10
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
11
20
  clean:
12
21
  rm -f *.o *.out
13
22
 
@@ -1,13 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
7
12
 
8
13
  test: tests.out
9
14
  @./tests.out
10
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
11
20
  clean:
12
21
  rm -f *.o *.out
13
22
 
@@ -1,13 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
7
12
 
8
13
  test: tests.out
9
14
  @./tests.out
10
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
11
20
  clean:
12
21
  rm -f *.o *.out
13
22
 
@@ -1,12 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
12
+
7
13
  test: tests.out
8
14
  @./tests.out
9
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
10
20
  clean:
11
21
  rm -f *.o *.out
12
22
 
@@ -1,13 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
7
12
 
8
13
  test: tests.out
9
14
  @./tests.out
10
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
11
20
  clean:
12
21
  rm -f *.o *.out
13
22
 
@@ -1,12 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
12
+
7
13
  test: tests.out
8
14
  @./tests.out
9
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
10
20
  clean:
11
21
  rm -f *.o *.out
12
22
 
@@ -1,12 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
12
+
7
13
  test: tests.out
8
14
  @./tests.out
9
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
10
20
  clean:
11
21
  rm -f *.o *.out
12
22
 
@@ -1,13 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
7
12
 
8
13
  test: tests.out
9
14
  @./tests.out
10
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
11
20
  clean:
12
21
  rm -f *.o *.out
13
22
 
@@ -1,13 +1,22 @@
1
1
  CFLAGS = -std=c99
2
+ CFLAGS += -g
2
3
  CFLAGS += -Wall
3
4
  CFLAGS += -Wextra
4
5
  CFLAGS += -pedantic
5
6
  CFLAGS += -Werror
6
7
 
8
+ VFLAGS = --quiet
9
+ VFLAGS += --tool=memcheck
10
+ VFLAGS += --leak-check=full
11
+ VFLAGS += --error-exitcode=1
7
12
 
8
13
  test: tests.out
9
14
  @./tests.out
10
15
 
16
+ memcheck: tests.out
17
+ @valgrind $(VFLAGS) ./tests.out
18
+ @echo "Memory check passed"
19
+
11
20
  clean:
12
21
  rm -f *.o *.out
13
22
 
@@ -22,6 +22,16 @@
22
22
  ],
23
23
  "uuid": "60eb0882-495d-45f4-8d38-5b10d8851cf6"
24
24
  },
25
+ {
26
+ "core": false,
27
+ "difficulty": 1,
28
+ "slug": "reverse-string",
29
+ "topics": [
30
+ "strings"
31
+ ],
32
+ "unlocked_by": null,
33
+ "uuid": "8bdf3796-592c-48f1-b2ef-8e4deb40cc37"
34
+ },
25
35
  {
26
36
  "core": false,
27
37
  "difficulty": 1,
@@ -0,0 +1,34 @@
1
+ # reverse-string
2
+
3
+ Reverse a string
4
+
5
+ For example:
6
+ input: "cool"
7
+ output: "looc"
8
+
9
+ ## Testing
10
+
11
+ In order to run the tests for this track, you will need to install
12
+ DUnitX. Please see the [installation](http://www.exercism.io/languages/delphi/installing) instructions for more information.
13
+
14
+ ### Loading Exercises into Delphi
15
+
16
+ If Delphi is properly installed, and `*.dpr` file types have been associated with Delphi, then double clicking the supplied `*.dpr` file will start Delphi and load the exercise/project. `control + F9` is the keyboard shortcut to compile the project or pressing `F9` will compile and run the project.
17
+
18
+ Alternatively you may opt to start Delphi and load your project via. the `File` drop down menu.
19
+
20
+ ### When Questions Come Up
21
+ We monitor the [Pascal-Delphi](https://gitter.im/exercism/Pascal-Delphi) support room on [gitter.im](https://gitter.im) to help you with any questions that might arise.
22
+
23
+ ### Submitting Exercises
24
+
25
+ Note that, when trying to submit an exercise, make sure the exercise file you're submitting is in the `exercism/delphi/<exerciseName>` directory.
26
+
27
+ For example, if you're submitting `ubob.pas` for the Bob exercise, the submit command would be something like `exercism submit <path_to_exercism_dir>/delphi/bob/ubob.pas`.
28
+
29
+ ## Source
30
+
31
+ Introductory challenge to reverse an input string [https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb](https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb)
32
+
33
+ ## Submitting Incomplete Solutions
34
+ It's possible to submit an incomplete solution so you can see how others have completed the exercise.
@@ -0,0 +1,60 @@
1
+ program ReverseString;
2
+
3
+ {$IFNDEF TESTINSIGHT}
4
+ {$APPTYPE CONSOLE}
5
+ {$ENDIF}{$STRONGLINKTYPES ON}
6
+ uses
7
+ System.SysUtils,
8
+ {$IFDEF TESTINSIGHT}
9
+ TestInsight.DUnitX,
10
+ {$ENDIF }
11
+ DUnitX.Loggers.Console,
12
+ DUnitX.Loggers.Xml.NUnit,
13
+ DUnitX.TestFramework,
14
+ uReverseStringTests in 'uReverseStringTests.pas',
15
+ uReverseString in 'uReverseString.pas';
16
+
17
+ var
18
+ runner : ITestRunner;
19
+ results : IRunResults;
20
+ logger : ITestLogger;
21
+ nunitLogger : ITestLogger;
22
+ begin
23
+ {$IFDEF TESTINSIGHT}
24
+ TestInsight.DUnitX.RunRegisteredTests;
25
+ exit;
26
+ {$ENDIF}
27
+ try
28
+ //Check command line options, will exit if invalid
29
+ TDUnitX.CheckCommandLine;
30
+ //Create the test runner
31
+ runner := TDUnitX.CreateRunner;
32
+ //Tell the runner to use RTTI to find Fixtures
33
+ runner.UseRTTI := True;
34
+ //tell the runner how we will log things
35
+ //Log to the console window
36
+ logger := TDUnitXConsoleLogger.Create(true);
37
+ runner.AddLogger(logger);
38
+ //Generate an NUnit compatible XML File
39
+ nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile);
40
+ runner.AddLogger(nunitLogger);
41
+ runner.FailsOnNoAsserts := True; //When true, Assertions must be made during tests;
42
+
43
+ //Run tests
44
+ results := runner.Execute;
45
+ if not results.AllPassed then
46
+ System.ExitCode := EXIT_ERRORS;
47
+
48
+ {$IFNDEF CI}
49
+ //We don't want this happening when running under CI.
50
+ if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then
51
+ begin
52
+ System.Write('Done.. press <Enter> key to quit.');
53
+ System.Readln;
54
+ end;
55
+ {$ENDIF}
56
+ except
57
+ on E: Exception do
58
+ System.Writeln(E.ClassName, ': ', E.Message);
59
+ end;
60
+ end.
@@ -0,0 +1,18 @@
1
+ unit uReverseString;
2
+
3
+ interface
4
+
5
+ function reverse(aInString: string): string;
6
+
7
+ implementation
8
+
9
+ function reverse(aInString: string): string;
10
+ var
11
+ i: integer;
12
+ begin
13
+ result := '';
14
+ for i := Low(aInString) to High(aInString) do
15
+ result := aInString[i] + result;
16
+ end;
17
+
18
+ end.
@@ -0,0 +1,69 @@
1
+ unit uReverseStringTests;
2
+
3
+ interface
4
+ uses
5
+ DUnitX.TestFramework;
6
+
7
+ const
8
+ CanonicalVersion = '1.0.1';
9
+
10
+ type
11
+
12
+ [TestFixture]
13
+ ReverseStringTest = class(TObject)
14
+ public
15
+ [Test]
16
+ // [Ignore('Comment the "[Ignore]" statement to run the test')]
17
+ procedure an_empty_string;
18
+
19
+ [Test]
20
+ [Ignore]
21
+ procedure a_word;
22
+
23
+ [Test]
24
+ [Ignore]
25
+ procedure a_capitalized_word;
26
+
27
+ [Test]
28
+ [Ignore]
29
+ procedure a_sentence_with_punctuation;
30
+
31
+ [Test]
32
+ [Ignore]
33
+ procedure a_palindrome;
34
+ end;
35
+
36
+ implementation
37
+ uses uReverseString;
38
+
39
+
40
+ { ReverseStringTest }
41
+
42
+ procedure ReverseStringTest.an_empty_string;
43
+ begin
44
+ Assert.AreEqual('', reverse(''));
45
+ end;
46
+
47
+ procedure ReverseStringTest.a_capitalized_word;
48
+ begin
49
+ Assert.AreEqual('nemaR',reverse('Ramen'));
50
+ end;
51
+
52
+ procedure ReverseStringTest.a_palindrome;
53
+ begin
54
+ Assert.AreEqual('racecar',reverse('racecar'));
55
+ end;
56
+
57
+ procedure ReverseStringTest.a_sentence_with_punctuation;
58
+ begin
59
+ Assert.AreEqual('!yrgnuh m''I', reverse('I''m hungry!'));
60
+ end;
61
+
62
+ procedure ReverseStringTest.a_word;
63
+ begin
64
+ Assert.AreEqual('tobor', reverse('robot'));
65
+ end;
66
+
67
+ initialization
68
+ TDUnitX.RegisterTestFixture(ReverseStringTest);
69
+ end.
@@ -23,12 +23,6 @@ type Operation =
23
23
 
24
24
  type ForthState = { sStack: Value list; sInput: Item list; sMapping: Map<Word, Operation> }
25
25
 
26
- type ForthError =
27
- | DivisionByZero
28
- | StackUnderflow
29
- | InvalidWord
30
- | UnknownWord of Word
31
-
32
26
  let defaultMapping =
33
27
  [("+", Plus);
34
28
  ("-", Minus);
@@ -72,21 +66,21 @@ let parse text state = parseText text |> addItems state
72
66
 
73
67
  let unaryStackOp op state =
74
68
  match state.sStack with
75
- | [] -> Choice2Of2 StackUnderflow
76
- | x::xs -> Choice1Of2 { state with sStack = op x @ xs}
69
+ | [] -> None
70
+ | x::xs -> Some { state with sStack = op x @ xs}
77
71
 
78
72
  let binaryStackOp op state =
79
73
  match state.sStack with
80
- | x::y::xs -> Choice1Of2 { state with sStack = op x y @ xs}
81
- | _ -> Choice2Of2 StackUnderflow
74
+ | x::y::xs -> Some { state with sStack = op x y @ xs}
75
+ | _ -> None
82
76
 
83
77
  let toBinaryStackOp op x y = [op y x]
84
78
 
85
79
  let divOp state =
86
80
  match state.sStack with
87
- | 0::_ -> Choice2Of2 DivisionByZero
88
- | x::y::xs -> Choice1Of2 { state with sStack = (y / x) :: xs }
89
- | _ -> Choice2Of2 StackUnderflow
81
+ | 0::_ -> None
82
+ | x::y::xs -> Some { state with sStack = (y / x) :: xs }
83
+ | _ -> None
90
84
 
91
85
  let applyOp op state =
92
86
  match op with
@@ -98,33 +92,43 @@ let applyOp op state =
98
92
  | Drop -> unaryStackOp (fun _ -> []) state
99
93
  | Swap -> binaryStackOp (fun x y -> [y; x]) state
100
94
  | Over -> binaryStackOp (fun x y -> [y; x; y]) state
101
- | User terms -> addItems state terms |> Choice1Of2
95
+ | User terms -> addItems state terms |> Some
102
96
 
103
97
  let evalWord word state =
104
98
  match Map.tryFind word state.sMapping with
105
- | None -> UnknownWord word |> Choice2Of2
99
+ | None -> None
106
100
  | Some op -> applyOp op state
107
101
 
108
102
  let rec evalState state =
109
103
  match state with
110
- | Choice2Of2 _ -> state
111
- | Choice1Of2 s ->
104
+ | None -> state
105
+ | Some s ->
112
106
  match s.sInput with
113
107
  | [] -> state
114
- | (Value v)::xs -> { s with sStack = v::s.sStack; sInput = xs } |> Choice1Of2 |> evalState
108
+ | (Value v)::xs -> { s with sStack = v::s.sStack; sInput = xs } |> Some |> evalState
115
109
  | (Word w)::xs ->
116
110
  match w with
117
111
  | ":" ->
118
112
  match breakBy (fun c -> c = Word ";") xs with
119
113
  | ((Word userWord::operations), remainder) ->
120
114
  { s with sInput = List.tail remainder; sMapping = Map.add (userWord.ToLower()) (User operations) s.sMapping }
121
- |> Choice1Of2
115
+ |> Some
122
116
  |> evalState
123
- | _ -> Choice2Of2 InvalidWord
124
- | ";" -> Choice2Of2 InvalidWord
117
+ | _ -> None
118
+ | ";" -> None
125
119
  | _ -> evalWord w { s with sInput = xs } |> evalState
126
120
 
127
- let eval text state =
128
- parse text state
129
- |> Choice1Of2
130
- |> evalState
121
+ let rec eval commands (state: ForthState option) =
122
+ match commands, state with
123
+ | [], _
124
+ -> state |> Option.map (fun x -> List.rev x.sStack)
125
+ | x::xs, Some y ->
126
+ let updatedState =
127
+ parse x y
128
+ |> Some
129
+ |> evalState
130
+
131
+ eval xs updatedState
132
+ | _ -> None
133
+
134
+ let evaluate commands = eval commands (Some empty)