Last active
December 12, 2015 08:58
-
-
Save danking/4747479 to your computer and use it in GitHub Desktop.
You'll notice there's also a problem with it not realizing that the unless terms will stop execution before I try to return non-string values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #lang typed/racket | |
| (require racket/cmdline) | |
| ;; The command line syntax is currently: | |
| ;; spims -p <file> -s <file> | |
| ;; where the first file is a pattern image and the second file is a source image | |
| (define-type MaybeString [U False String]) | |
| (: parse-arguments ([Vector String] -> [Values String String])) | |
| (define (parse-arguments arguments) | |
| (let: ((pattern-image-filename : MaybeString #f) | |
| (source-image-filename : MaybeString #f)) | |
| ;; This expression returns (void) because there is no #:args clause. A #:args | |
| ;; clause could be used to parse arguments which succeed the regular, flagged | |
| ;; arguments. | |
| (command-line #:program "spims" | |
| #:argv arguments | |
| #:once-each | |
| ["-p" filename "the pattern image" | |
| (set! pattern-image-filename filename)] | |
| ["-s" filename "the source image" | |
| (set! source-image-filename filename)]) | |
| ;; verify that the necessary arguments were passed | |
| (unless source-image-filename | |
| (error 'parse-arguments | |
| "You must specify a source image -- see 'spims -h' for help.")) | |
| (unless pattern-image-filename | |
| (error 'parse-arguments | |
| "You must specify a pattern image -- see 'spims -h' for help.")) | |
| ;; this returns two values, you can use a (let-values (((a b) ...) ...) ...) | |
| ;; form to capture these values | |
| (values pattern-image-filename source-image-filename))) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| I get these errors: | |
| racket parse-command-line-typed.rkt | |
| parse-command-line-typed.rkt:22:18: Type Checker: Mutation only allowed with compatible types: | |
| Any is not a subtype of MaybeString | |
| in: (set! pattern-image-filename filename) | |
| context...: | |
| /usr/local/lib/racket/collects/typed-racket/utils/tc-utils.rkt:95:12: for-loop | |
| f16 | |
| /usr/local/lib/racket/collects/typed-racket/typecheck/tc-toplevel.rkt:295:0: type-check | |
| success | |
| /usr/local/lib/racket/collects/typed-racket/typed-racket.rkt:40:4 | |
| standard-module-name-resolver | |
| parse-command-line-typed.rkt:24:18: Type Checker: Mutation only allowed with compatible types: | |
| Any is not a subtype of MaybeString | |
| in: (set! source-image-filename filename) | |
| context...: | |
| /usr/local/lib/racket/collects/typed-racket/utils/tc-utils.rkt:95:12: for-loop | |
| f16 | |
| /usr/local/lib/racket/collects/typed-racket/typecheck/tc-toplevel.rkt:295:0: type-check | |
| success | |
| /usr/local/lib/racket/collects/typed-racket/typed-racket.rkt:40:4 | |
| standard-module-name-resolver | |
| parse-command-line-typed.rkt:34:11: Type Checker: Expected String, but got MaybeString | |
| in: pattern-image-filename | |
| context...: | |
| /usr/local/lib/racket/collects/typed-racket/utils/tc-utils.rkt:95:12: for-loop | |
| f16 | |
| /usr/local/lib/racket/collects/typed-racket/typecheck/tc-toplevel.rkt:295:0: type-check | |
| success | |
| /usr/local/lib/racket/collects/typed-racket/typed-racket.rkt:40:4 | |
| standard-module-name-resolver | |
| parse-command-line-typed.rkt:34:34: Type Checker: Expected String, but got MaybeString | |
| in: source-image-filename | |
| context...: | |
| /usr/local/lib/racket/collects/typed-racket/utils/tc-utils.rkt:95:12: for-loop | |
| f16 | |
| /usr/local/lib/racket/collects/typed-racket/typecheck/tc-toplevel.rkt:295:0: type-check | |
| success | |
| /usr/local/lib/racket/collects/typed-racket/typed-racket.rkt:40:4 | |
| standard-module-name-resolver | |
| Type Checker: Summary: 4 errors encountered | |
| context...: | |
| /usr/local/lib/racket/collects/typed-racket/typecheck/tc-toplevel.rkt:295:0: type-check | |
| success | |
| /usr/local/lib/racket/collects/typed-racket/typed-racket.rkt:40:4 | |
| standard-module-name-resolver | |
| Compilation exited abnormally with code 1 at Sat Feb 9 17:54:31 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment