brentgordon146
2020-2-3 17:01:19

@brentgordon146 has joined the channel


krismicinski
2020-2-3 19:47:54

sometimes, for sure. I agree define-values is not so different from that.


notjack
2020-2-3 20:14:37

I ask because I usually recommend using define instead of let / let* / etc.


notjack
2020-2-3 20:14:49

so I was curious how you do things


krismicinski
2020-2-3 20:15:28

yeah, good point. I do have a habit of using defines


krismicinski
2020-2-3 20:15:40

that is my style as well


krismicinski
2020-2-3 20:15:54

although if I just have one thing to match on, I might just match


krismicinski
2020-2-3 20:16:00

if I have multiple things, always match-define


brentgordon146
2020-2-3 22:54:45

how can i determine a file’s mime type?


philip.mcgrath
2020-2-3 23:35:16

@brentgordon146 In the general case, you can’t, but that isn’t a very helpful answer. The two usual general approaches (not specific to Racket) are either to use a heuristic based on the file’s content or to rely on metadata. A common type of metadata is the file extension—probably you know that, and probably you also realize there are limitations. You can get it with path-get-extension. The main Racket distribution comes with a mapping of mime types for common file extensions to support the web server: https://docs.racket-lang.org/web-server-internal/mime-types.html Some platforms maintain additional metadata about a file’s type. The GUI library includes file-creator-and-type to access one such mechanism on Mac OS, though you would also need to know what mime type corresponds to each Mac OS content type: https://docs.racket-lang.org/gui/Windowing_Functions.html#(def._((lib._mred%2Fmain..rkt)._file-creator-and-type)) You could use the FFI to access other interfaces from the OS. The way the Unix file command does this (<http://www.darwinsys.com/file/>) is by looking at the file content, usually (maybe always?) just the first few bytes. I thought I remembered there being a Racket package that used this strategy, either in pure Racket or by using libmagic through the FFI, but I can’t find it now. You could run the file command with system*, though, or implement such a package yourself.