From 35f28df5d3c5089aa2cd765019a718e8d176d4fb Mon Sep 17 00:00:00 2001 From: m455 Date: Mon, 19 Mar 2018 16:56:52 -0400 Subject: [PATCH] i finally figured out how to close files in racket --- rodo.rkt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/rodo.rkt b/rodo.rkt index 1b4e35a..3bcb5d3 100755 --- a/rodo.rkt +++ b/rodo.rkt @@ -1,7 +1,7 @@ #! /usr/bin/env racket #lang racket/base -(define (display-hash hash-list key) +(define (displayln-hash-ref hash-list key) (displayln (hash-ref hash-list key))) (define messages (hash @@ -21,26 +21,27 @@ (define (open/create-file path) (let ([path (expand-user-path path)]) - (open-output-file path + (let ([opened-file (open-output-file path #:mode 'text - #:exists 'can-update))) + #:exists 'can-update)]) + (close-output-port opened-file)))) (define (prompt-user prompt-message) - (display-hash messages prompt-message) + (displayln-hash-ref messages prompt-message) (let ([user-input (read-line)]) (cond [(member user-input (hash-ref y/n 'yes)) - (display-hash messages 'creating-file) + (displayln-hash-ref messages 'creating-file) (open/create-file "~/.rodo")] [(member user-input (hash-ref y/n 'no)) - (display-hash messages 'terminating)] + (displayln-hash-ref messages 'terminating)] [else - (display-hash messages 'choose-y/n) + (displayln-hash-ref messages 'choose-y/n) (prompt-user 'file-not-found)]))) (define (todo-list-exist?) (if (file-exists? (expand-user-path "~/.rodo")) - (display-hash messages 'file-exists) + (displayln-hash-ref messages 'file-exists) (prompt-user 'file-not-found))) (todo-list-exist?)