diff --git a/words/command.rkt b/words/command.rkt index fe262e2..d5d4629 100755 --- a/words/command.rkt +++ b/words/command.rkt @@ -16,7 +16,7 @@ (define combo #false) (define min-size #false) (define max-size #false) - (define max-words #false) + (define count #false) (define hide-plurals #true) (define proper-names #false) (command-line @@ -32,9 +32,9 @@ [("-c" "--combo") combo-arg "mandatory combo" (set! combo combo-arg)] - [("-n" "--number") max-words-arg + [("-n" "--number") count-arg "max number of results" - (set! max-words (string->number max-words-arg))] + (set! count (string->number count-arg))] [("--min") min-size-arg "minimum word lengths" (set! min-size (string->number min-size-arg))] @@ -50,7 +50,7 @@ (displayln (string-join (make-words #:letters letters #:mandatory mandatory #:combo combo - #:max-words max-words + #:count count #:min min-size #:max max-size #:hide-plurals hide-plurals diff --git a/words/main.rkt b/words/main.rkt index 1706976..ceb970a 100644 --- a/words/main.rkt +++ b/words/main.rkt @@ -3,16 +3,17 @@ "index.rkt") (provide make-words) -(define (make-words #:letters [letters "etaoinshrdluw"] +(define (make-words #:letters [letters-arg #f] #:mandatory [mandatory #f] #:combo [combo #f] #:min [min-length-arg 5] #:max [max-length-arg 10] #:hide-plurals [hide-plurals? #t] #:proper-names [proper-names? #f] - #:max-words [max-words 10] + #:count [count 10] #:all-caps [all-caps? #f] #:initial-caps [initial-caps? #f]) + (define letters (or letters-arg "abcdefghijklmnopqrstuvwxyz")) (define mandatory-cs (if (or mandatory combo) (remove-duplicates @@ -35,13 +36,13 @@ (define min-length (or min-length-arg 0)) (define max-length (or max-length-arg +inf.0)) (for*/fold ([word-acc null] - [count 0] + [count-acc 0] #:result word-acc) ([idx (in-list (shuffle (range (vector-length wordrecs))))] [rec (in-value (vector-ref wordrecs idx))] [word-charidx (in-value (word-rec-charint rec))] [word (in-value (word-rec-word rec))] - #:break (= count (or max-words +inf.0)) + #:break (= count-acc (or count +inf.0)) #:when (and ;; between min and max length ((if (<= min-length max-length) <= >=) min-length (word-rec-length rec) max-length) @@ -60,10 +61,10 @@ ;; maybe hide plurals (or (not hide-plurals?) (not (word-rec-plural? rec))))) - (values (cons (caser word) word-acc) (add1 count)))) + (values (cons (caser word) word-acc) (add1 count-acc)))) (module+ test (require rackunit) (time (make-words)) - (check-equal? (sort (make-words #:mandatory "xyz" #:combo #false) string