summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2024-06-09 23:20:44 -0600
committerbd <bdunahu@operationnull.com>2024-06-09 23:20:44 -0600
commitefb4865c81bfef747428303d5388fb1889db5769 (patch)
treefd27b383cb6c53f64faee37ec543052f14a21b4c
parente29188413ec6c3243f7965b4408459a7517539b3 (diff)
Cleanup repository
-rw-r--r--basics.scm52
-rw-r--r--binary-search/binary-search-test.scm13
-rw-r--r--binary-search/binary-search.scm7
-rw-r--r--dictionary/dictionary-test.scm57
-rw-r--r--dictionary/dictionary.scm36
l---------[-rw-r--r--]spellcheck/dictionary.scm37
-rw-r--r--spellcheck/spellcheck-test.scm57
7 files changed, 95 insertions, 164 deletions
diff --git a/basics.scm b/basics.scm
deleted file mode 100644
index 4c52883..0000000
--- a/basics.scm
+++ /dev/null
@@ -1,52 +0,0 @@
-;;;; variables
-(define my-var 15)
-my-var
-
-;; set to something else
-(set! my-var 20)
-
-;;;; functions
-(define (find value lst)
- (if (pair? lst)
- (begin
- (display (string-append "Looking at: " (number->string (car lst))
- "\n"))
- (if (equal? (car lst) value)
- (begin (display "Found it!\n")
- (car lst))
- (find value (cdr lst))))
- #f))
-
-(find 5 '(1 2 3 4 5 6))
-
-;; note that variables and functions exist in the same
-;; namespace, and that we can define functions in a
-;; slightly more ugly way, but looks a lot like a var
-;; declaration:
-(define find-x (lambda (value lst)
- (if (pair? lst)
- (begin
- (display (string-append "Looking at: " (number->string (car lst))
- "\n"))
- (if (equal? (car lst) value)
- (begin (display "Found it!\n")
- (car lst))
- (find value (cdr lst))))
- #f)))
-
-(find-x 4 '(1 2 3 4 5 6))
-
-;;;; let
-
-;; let as a looping construct
-(let find-loop ((value 5)
- (lst '(1 2 3 4 5)))
- (if (pair? lst)
- (begin
- (display (string-append "Looking at: " (number->string (car lst))
- "\n"))
- (if (equal? (car lst) value)
- (begin (display "Found it!\n")
- (car lst))
- (find-loop value (cdr lst))))
- #f))
diff --git a/binary-search/binary-search-test.scm b/binary-search/binary-search-test.scm
deleted file mode 100644
index adbeacb..0000000
--- a/binary-search/binary-search-test.scm
+++ /dev/null
@@ -1,13 +0,0 @@
-(use-modules (srfi srfi-64)
- (binary-search))
-
-(test-begin "harness")
-
-
-(define bst (make-empty-bst))
-
-(test-assert "empty-bst-missing-zero"
- (not (bst-member-p bst 0)))
-
-
-(test-end "harness")
diff --git a/binary-search/binary-search.scm b/binary-search/binary-search.scm
deleted file mode 100644
index 95513df..0000000
--- a/binary-search/binary-search.scm
+++ /dev/null
@@ -1,7 +0,0 @@
-(define-module (binary-search))
-
-(define-public (make-empty-bst)
- #t)
-
-(define-public (bst-member-p bst e)
- #f)
diff --git a/dictionary/dictionary-test.scm b/dictionary/dictionary-test.scm
new file mode 100644
index 0000000..89830fe
--- /dev/null
+++ b/dictionary/dictionary-test.scm
@@ -0,0 +1,57 @@
+(use-modules (srfi srfi-64)
+ (dictionary))
+
+(define simple-dict (create-dictionary '("word")))
+(define complex-dict (create-dictionary '("Again" "the" "thirst"
+ "quencher" "of" "wolves"
+ "embarked" "on" "a" "well"
+ "prepared" "expedition"
+ "eastward" "the" "generous"
+ "ruler" "moved" "the" "bitter"
+ "heart" "of" "the" "snake"
+ "across" "the" "fire")))
+
+(test-begin "dictionary")
+
+
+(test-assert "create-dictionary returns hashtable"
+ (hash-table?
+ (create-dictionary '())))
+
+(define dict (create-dictionary '("word")))
+
+(test-equal "list-keys-single"
+ '("word")
+ (dict-keys-ref simple-dict))
+
+(test-equal "count-values-single"
+ 1
+ (dict-values-ref simple-dict))
+
+
+(test-equal "retrieve single"
+ 1
+ (dict-occur-ref complex-dict "wolves"))
+
+(test-equal "retrieve double"
+ 2
+ (dict-occur-ref complex-dict "of"))
+
+(test-equal "retrieve quintuple"
+ 5
+ (dict-occur-ref complex-dict "the"))
+
+(test-equal "retrieve zero"
+ 0
+ (dict-occur-ref complex-dict "king"))
+
+(test-equal "list-keys-sentence"
+ '("Again" "a" "across" "bitter" "eastward" "embarked" "expedition" "fire" "generous" "heart" "moved" "of" "on" "prepared" "quencher" "ruler" "snake" "the" "thirst" "well" "wolves")
+ (sort (dict-keys-ref complex-dict) string<?))
+
+(test-equal "count-values-sentence"
+ 26
+ (dict-values-ref complex-dict))
+
+
+(test-end "dictionary")
diff --git a/dictionary/dictionary.scm b/dictionary/dictionary.scm
new file mode 100644
index 0000000..856fec5
--- /dev/null
+++ b/dictionary/dictionary.scm
@@ -0,0 +1,36 @@
+(define-module (dictionary)
+ #:export (create-dictionary
+ dict-occur-ref
+ dict-keys-ref
+ dict-values-ref))
+
+(define (create-dictionary lst)
+ (dictionary-helper (make-hash-table) lst))
+
+(define (dictionary-helper dict rest)
+ "Recursively adds words to DICT."
+ (if (null? rest)
+ dict
+ (begin
+ (dict-inc-word dict (car rest))
+ (dictionary-helper dict (cdr rest)))))
+
+(define (dict-inc-word dict e)
+ "Inserts word E into the DICT, using E
+as a key and the running total of occurances
+as the value."
+ (hashq-set!
+ dict e (1+ (dict-occur-ref dict e))))
+
+(define (dict-occur-ref dict e)
+ "A wrapper for hashq-ref. Returns '0' if an element
+is not present, rather than '#f'."
+ (or (hashq-ref dict e) 0))
+
+(define (dict-keys-ref dict)
+ "Returns a list of all words in the dictionary."
+ (map car (hash-map->list cons dict)))
+
+(define (dict-values-ref dict)
+ "Sums up the total number of occurances for all words."
+ (apply + (map cdr (hash-map->list cons dict))))
diff --git a/spellcheck/dictionary.scm b/spellcheck/dictionary.scm
index 856fec5..237a3c6 100644..120000
--- a/spellcheck/dictionary.scm
+++ b/spellcheck/dictionary.scm
@@ -1,36 +1 @@
-(define-module (dictionary)
- #:export (create-dictionary
- dict-occur-ref
- dict-keys-ref
- dict-values-ref))
-
-(define (create-dictionary lst)
- (dictionary-helper (make-hash-table) lst))
-
-(define (dictionary-helper dict rest)
- "Recursively adds words to DICT."
- (if (null? rest)
- dict
- (begin
- (dict-inc-word dict (car rest))
- (dictionary-helper dict (cdr rest)))))
-
-(define (dict-inc-word dict e)
- "Inserts word E into the DICT, using E
-as a key and the running total of occurances
-as the value."
- (hashq-set!
- dict e (1+ (dict-occur-ref dict e))))
-
-(define (dict-occur-ref dict e)
- "A wrapper for hashq-ref. Returns '0' if an element
-is not present, rather than '#f'."
- (or (hashq-ref dict e) 0))
-
-(define (dict-keys-ref dict)
- "Returns a list of all words in the dictionary."
- (map car (hash-map->list cons dict)))
-
-(define (dict-values-ref dict)
- "Sums up the total number of occurances for all words."
- (apply + (map cdr (hash-map->list cons dict))))
+../dictionary/dictionary.scm \ No newline at end of file
diff --git a/spellcheck/spellcheck-test.scm b/spellcheck/spellcheck-test.scm
index 438384d..55fce48 100644
--- a/spellcheck/spellcheck-test.scm
+++ b/spellcheck/spellcheck-test.scm
@@ -1,61 +1,6 @@
(use-modules (srfi srfi-64)
- (dictionary)
- (mutate))
+ (mutate))
-(define simple-dict (create-dictionary '("word")))
-(define complex-dict (create-dictionary '("Again" "the" "thirst"
- "quencher" "of" "wolves"
- "embarked" "on" "a" "well"
- "prepared" "expedition"
- "eastward" "the" "generous"
- "ruler" "moved" "the" "bitter"
- "heart" "of" "the" "snake"
- "across" "the" "fire")))
-
-(test-begin "dictionary")
-
-
-(test-assert "create-dictionary returns hashtable"
- (hash-table?
- (create-dictionary '())))
-
-(define dict (create-dictionary '("word")))
-
-(test-equal "list-keys-single"
- '("word")
- (dict-keys-ref simple-dict))
-
-(test-equal "count-values-single"
- 1
- (dict-values-ref simple-dict))
-
-
-(test-equal "retrieve single"
- 1
- (dict-occur-ref complex-dict "wolves"))
-
-(test-equal "retrieve double"
- 2
- (dict-occur-ref complex-dict "of"))
-
-(test-equal "retrieve quintuple"
- 5
- (dict-occur-ref complex-dict "the"))
-
-(test-equal "retrieve zero"
- 0
- (dict-occur-ref complex-dict "king"))
-
-(test-equal "list-keys-sentence"
- '("Again" "a" "across" "bitter" "eastward" "embarked" "expedition" "fire" "generous" "heart" "moved" "of" "on" "prepared" "quencher" "ruler" "snake" "the" "thirst" "well" "wolves")
- (sort (dict-keys-ref complex-dict) string<?))
-
-(test-equal "count-values-sentence"
- 26
- (dict-values-ref complex-dict))
-
-
-(test-end "dictionary")
(test-begin "mutate")