diff --git a/args.rkt b/args.rkt index 2ebf8a3..f2289df 100644 --- a/args.rkt +++ b/args.rkt @@ -12,12 +12,12 @@ (let ([args-length (length args)]) (cond [(equal? args-length 0) - (utils:display-hash-ref messages:messages 'show-usage)] + (utils:display-messages '(show-usage))] ;; help-command [(and (equal? args-length 1) (member (list-ref args 0) config:help-commands)) - (utils:display-hash-ref messages:messages 'show-help)] + (utils:display-messages '(show-help))] ;; initialize-command [(and (equal? args-length 1) @@ -42,4 +42,4 @@ (zero? (string->number (list-ref args 1))))) (utils:check-remove-conditions args)] - [else (utils:display-hash-ref messages:messages 'show-usage)]))) + [else (utils:display-messages '(show-usage))]))) diff --git a/init.rkt b/init.rkt index 16b0129..c216e84 100644 --- a/init.rkt +++ b/init.rkt @@ -7,26 +7,26 @@ (provide (all-defined-out)) (define (create-initialization-contents) - (utils:display-hash-ref messages:messages 'creating) + (utils:display-messages '(creating)) (utils:create-directory-700 config:program-directory) (utils:create-file-600 config:list-file) (if (and (directory-exists? config:program-directory) (file-exists? config:list-file)) - (utils:display-hash-ref messages:messages 'successfully-created) + (utils:display-messages '(successfully-created)) ;; Otherwise - (utils:display-hash-ref messages:messages 'creation-error))) + (utils:display-messages '(creation-error)))) (define (initialize) - (utils:display-hash-ref messages:messages 'init-y/n) + (utils:display-messages '(init-y/n)) (display "> ") (let ([user-input (read-line)]) (cond [(member user-input (hash-ref messages:y/n 'yes)) (create-initialization-contents)] [(member user-input (hash-ref messages:y/n 'no)) - (utils:display-hash-ref messages:messages 'terminating)] - [else (utils:display-hash-ref messages:messages 'choose-y/n)]))) + (utils:display-messages '(terminating))] + [else (utils:display-messages '(choose-y/n))]))) (define (check-initialize-conditions) (if (file-exists? config:list-file) - (utils:display-hash-ref messages:messages 'file-already-exists) + (utils:display-messages '(file-already-exists)) (initialize))) diff --git a/utils.rkt b/utils.rkt index deab853..1bcdd05 100644 --- a/utils.rkt +++ b/utils.rkt @@ -17,12 +17,9 @@ (make-directory a-directory) (file-or-directory-permissions a-directory #o700)) -(define (display-hash-ref hash-list key) - (display (hash-ref hash-list key))) - -(define (display-hash-ref-multi hash-list key-list) +(define (display-messages key-list) (for ([key key-list]) - (display (hash-ref hash-list key)))) + (display (hash-ref messages:messages key)))) (define (list->ascending-numbers lst) (list:range (length lst))) @@ -61,13 +58,13 @@ ;; If exists and empty [(and (file-exists? config:list-file) (null? (file:file->lines config:list-file))) - (display-hash-ref messages:messages 'empty-list)] + (display-messages '(empty-list))] ;; If not exist [(and (not (file-exists? config:list-file))) - (display-hash-ref-multi messages:messages '(file-not-found try-init))] + (display-messages '(file-not-found try-init))] - [else (display-hash-ref messages:messages 'show-usage)])) + [else (display-messages '(show-usage))])) (define (append-element-to-end-of-list lst item-to-add) (reverse (cons item-to-add (reverse (file:file->lines lst))))) @@ -85,7 +82,7 @@ (if (and (file-exists? config:list-file)) (add-item-to-list args) ;; Otherwise - (display-hash-ref-multi messages:messages '(file-not-found try-init)))) + (display-messages '(file-not-found try-init)))) (define (remove-item-from-list user-args) (let* ([item-to-remove (list-ref (file:file->lines config:list-file) user-args)] @@ -102,7 +99,7 @@ [(and (directory-exists? config:program-directory) (file-exists? config:list-file) (null? config:list-file)) - (display-hash-ref messages:messages 'empty-list)] + (display-messages '(empty-list))] ;; If directory and file exist, and file is not empty [(and (directory-exists? config:program-directory) @@ -114,9 +111,9 @@ (if (not (> user-args list-length)) (remove-item-from-list user-args) ;; Otherwise - (display-hash-ref messages:messages 'item-not-found)))] + (display-messages '(item-not-found))))] ;; If directory and file don't exist [(and (not (directory-exists? config:program-directory)) (not (file-exists? config:list-file))) - (display-hash-ref-multi messages:messages '(file-not-found try-init))])) + (display-messages '(file-not-found try-init))]))